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 CONTAINER and CONTAINER_TOKEN variable support to amp-analytics. #13499

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions extensions/amp-analytics/0.1/vendors.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export const ANALYTICS_CONFIG = /** @type {!JsonObject} */ ({
'documentReferrer': 'DOCUMENT_REFERRER',
'domainLookupTime': 'DOMAIN_LOOKUP_TIME',
'domInteractiveTime': 'DOM_INTERACTIVE_TIME',
'container': 'CONTAINER',
'containerToken': 'CONTAINER_TOKEN',
'externalReferrer': 'EXTERNAL_REFERRER',
'navRedirectCount': 'NAV_REDIRECT_COUNT',
'navTiming': 'NAV_TIMING',
Expand Down
19 changes: 18 additions & 1 deletion src/service/url-replacements-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from '../service';
import {
parseUrl,
getFragment,
removeFragment,
parseQueryString,
addParamsToUrl,
Expand Down Expand Up @@ -513,6 +514,21 @@ export class GlobalVariableSource extends VariableSource {
return this.getStoryValue_(storyVariables => storyVariables.pageId,
'STORY_PAGE_ID');
});

this.set('CONTAINER_TOKEN', () => {
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 the use case of this?
we can probably make this a macro function that takes an argument, like we have for QUERY_PARAM('ct'), we can have FRAGMENT_PARAM('ct')

let fragment = getFragment(this.ampdoc.win.location.href);
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to check location.originalHash, we wipe the viewer params from the location.href (and therefore location.hash) on load.

Better yet, you can use viewer's #getParam to get these without doing a query parse.

if (!fragment) {
return '';
Copy link
Contributor

Choose a reason for hiding this comment

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

Whitespace...

}
let args = parseQueryString(fragment.substring(1, fragment.length));
Copy link
Contributor

Choose a reason for hiding this comment

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

It'll parse with the # symbol.

if (!args.ct) {
return '';
}
return args.ct;
});
this.set('CONTAINER', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Likely we'll need better naming.

return document.location.ancestorOrigins[0];
});
}

/**
Expand Down Expand Up @@ -973,7 +989,8 @@ export class UrlReplacements {
if (opt_collectVars) {
opt_collectVars[match] = val;
}
return encodeValue(val);
// Should this be implemented as a whitelist or something?
return match == 'CONTAINER' ? val : encodeValue(val);
});

if (replacementPromise) {
Expand Down