Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extraUrlParams and extraUrlParamsReplaceMap to amp-analytics #1932

Merged
merged 1 commit into from
Feb 12, 2016

Conversation

jmadler
Copy link
Contributor

@jmadler jmadler commented Feb 11, 2016

Implements #1881

@jmadler
Copy link
Contributor Author

jmadler commented Feb 11, 2016

@jmadler jmadler changed the title Add customVars and customVarsKeyReplace to amp-analytics Add customVars and customVarsMap to amp-analytics Feb 11, 2016
var i = 0;
for (const keyrule in this.config_['customVarsMap']) {
var replacerule = this.config_['customVarsMap'][keyrule];
alert ("keyrule = " + keyrule + ";replacerule = " + replacerule);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend using console.log :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will remove - that was for debugging

@cramforce
Copy link
Member

Looks great. Just some simple questions and nits.

Run gulp lint and gulp presubmit to fix the lint issues.

@avimehta
Copy link
Contributor

who are we building this for? can you point to some examples on who would use/need these?

@jmadler
Copy link
Contributor Author

jmadler commented Feb 11, 2016

This is for Adobe Analytics

@avimehta
Copy link
Contributor

I see. a few general concerns:

  1. Having variables defined like this and then the vendor renaming them in the config looks like a weird contract between two parties. I think @cramforce already asked this and you gave an answer but why wouldn't a publisher simply specify the parameter name in their config? Isn't specifying just the parameter name and value easier, more flexible?

    Taking a cursory look at adobe's site, it looks like the variables they use in the request are literally of the format:

    prop31:en-us
    prop32:en-us:adobe.com:marketing-cloud:web-analytics
    prop34:9
    eVar37:D=oid
    eVar38:D=pid
    

    Given that, I am not sure if the customVarsMap part of this PR is needed. Won't just the vendor config part of your PR suffice?

  2. Custom Variables is actually used by multiple products and it means slightly different thing in each different product. So GA users might try to use this but will not see the results they would like. Same for piwik and some other products out there.

  3. I will prefer a solution where the hit building/parameter config is more descriptive. For example, if we decide to do Support POSTing JSON with amp-analytics #1798 and Provide ability to conditionally append key-value pair in amp-analytics #1701, will this work with that? To some extent, I feel that solving Provide ability to conditionally append key-value pair in amp-analytics #1701 is a superset of this feature.

@cramforce
Copy link
Member

Maybe customParams is a better name, as in: It literally (with the exception of the replace) goes into the URL.

I second Avi's concern about the replace being really weird, since people could just use the output instead. But I'm happy to make things easy for Adobe customers.

@jmadler
Copy link
Contributor Author

jmadler commented Feb 11, 2016

  1. In the case of Adobe, the key names in these key/val pairs are different in different contexts. For example, s.evar0 is sometimes called v0. Adobe (and other analytics providers) should be able to have that sort of flexibility in AMP Analytics. I understand that this additional ease of use comes at a cost of reduced performance, but note that the performance impact for analytics configs not using it is a one-time check of two vars, and the entire routine is skipped if the config doesn't exist. In terms of performance impact for those using analytics vendors that enable this routine, this O(n * m) routine runs once per page load and has a maximum "m" of 8, and an unlimited "n". I'm happy to add a limit to "n" (customVars) to minimize the potential upper bound of performance impact in these cases. I'd suggest 128.
  2. We can rename to customParams or extraParams or whatever you like best. I have no opinion. Just let me know which is best for AMP Analytics.
  3. Provide ability to conditionally append key-value pair in amp-analytics #1701 and Support POSTing JSON with amp-analytics #1798 seems to me to be orthogonal to this PR. Based on this PR, Provide ability to conditionally append key-value pair in amp-analytics #1701 could be a config variable to omit vars and/or extraParams if the value is null; Support POSTing JSON with amp-analytics #1798 would be a config variable to specify the verb to use (POST, GET, HEAD, et al). I'm happy to implement Provide ability to conditionally append key-value pair in amp-analytics #1701, btw.

@cramforce
Copy link
Member

I'm not worried about runtime performance. Code size and complexity is the only worry.

Lets call them extraUrlParams

@jmadler jmadler force-pushed the analytics-customvars branch from c337838 to 66337b9 Compare February 11, 2016 18:13
@jmadler
Copy link
Contributor Author

jmadler commented Feb 11, 2016

I did:

  • renamed to extraUrlParams / extraUrlParamsReplaceMap
  • removed debugging shims
  • moved regex outside of the inner loop to the outer loop to reduce duplication of effort
  • rename variables and set scope appropriately throughout (var => let/const)
  • Ran gulp lint and gulp presubmit and corrected issues

I did not:

  • Remove regex sanitation

PTAL

@jmadler jmadler changed the title Add customVars and customVarsMap to amp-analytics Add extraUrlParams and extraUrlParamsReplaceMap to amp-analytics Feb 11, 2016
}

// only allow word chars
replaceMapKey = extraUrlParamsReplaceMapKey.replace(/(\W)/g, '\$1');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what extraUrlParamsReplaceMapKey is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch. corrected and tested.

@avimehta
Copy link
Contributor

agreed with @cramforce on code complexity. Plus I still feel that this is too specific a solution and that #1701 is a more generic replacement of this.

Having said that, I am still not completely sure about how this is going to be used. I am not sure there will be multiple vendor contexts. Is adobe going to create multiple types in vendors.js?

Since I don't understand the usecase, I think I am okay with committing this and keeping an eye on how this will be used.

@jmadler
Copy link
Contributor Author

jmadler commented Feb 11, 2016

I've given this some thought and I think, more broadly, the need for the extraUrlParams is introduced because the request URLs have the variables built into the string.

Rather than push this one through, and adding that as technical debt for later, let's grab some time to brainstorm the right approach and move forward appropriately.

@cramforce
Copy link
Member

I have the same questions as @avimehta, but I also want to get this resolved quickly. Main question is whether the replace list itself needs to be configured by clients or is there a single one.

I think the extraUrlParams feature is super useful and should definitely land.

@avimehta
Copy link
Contributor

talked offline. Iets continue with this PR. I don't think we are painting ourselves is a bad corner with this. Overall, this is a positive this for analytics and should be done.

Jordan has some great ideas about how to make requests more flexible. Lets talk about those outside of this PR.

@jmadler jmadler force-pushed the analytics-customvars branch from 66337b9 to d572fe2 Compare February 11, 2016 23:28
@jmadler
Copy link
Contributor Author

jmadler commented Feb 11, 2016

Final revisions made. PTAL @cramforce before merge

// of params to String.replace to allow aliasing of the keys in
// extraUrlParams.
let count = 0;
const MAX_REPLACES = 16;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be defined near the top of the file and come with an explanation.

@cramforce
Copy link
Member

One comment. Please rebase.

@jmadler jmadler force-pushed the analytics-customvars branch from d572fe2 to 27339f7 Compare February 11, 2016 23:42
@jmadler
Copy link
Contributor Author

jmadler commented Feb 11, 2016

fixed & rebased

@cramforce
Copy link
Member

Rebasing appears to not have been successful. Maybe you forgot to pull down master?

}

// only allow word chars
replaceMapKey = replaceMapKey.replace(/(\W)/g, '\$1');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this preventing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

early iterations treated the key as a regex. It's now just a string, though. I'll remove the line as it's irrelevant now.

@jmadler jmadler force-pushed the analytics-customvars branch 2 times, most recently from 8864386 to 409bb62 Compare February 12, 2016 00:47
@jmadler jmadler force-pushed the analytics-customvars branch from 409bb62 to 42726fc Compare February 12, 2016 01:01
@cramforce
Copy link
Member

LGTM

cramforce added a commit that referenced this pull request Feb 12, 2016
Add extraUrlParams and extraUrlParamsReplaceMap to amp-analytics
@cramforce cramforce merged commit 7353601 into ampproject:master Feb 12, 2016
@jmadler jmadler deleted the analytics-customvars branch February 12, 2016 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants