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

Conversation

RJSumi
Copy link
Contributor

@RJSumi RJSumi commented Feb 15, 2018

  • Implements a CONTAINER variable, allowing access to ancestorOrigins[0] without %-encoding
  • Implements a CONTAINER_TOKEN variable, allowing access to the value of the ct in the hash fragment the document was initialized with

Please advise on how to better not %-encode CONTAINER, and what kind of unit testing would be good for this, etc.

Fixes #13498

	modified:   extensions/amp-analytics/0.1/vendors.js
	modified:   src/service/url-replacements-impl.js
@dreamofabear
Copy link

/to @lannka /cc @calebcordry Who's been working with this recently IIRC.

  • If these new variables will only be used in amp-analytics, can we implement this in amp-analytics/0.1/variables.js instead to avoid bloating the main binary?
  • Nit: Why CONTAINER and CONTAINER_TOKEN vs. ANCESTOR_ORIGIN and ANCESTOR_ORIGIN_HASH?

@@ -513,6 +514,21 @@ export class GlobalVariableSource extends VariableSource {
return this.getStoryValue_(storyVariables => storyVariables.pageId,
'STORY_PAGE_ID');
});

this.set('CONTAINER_TOKEN', () => {
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.

this.set('CONTAINER_TOKEN', () => {
let fragment = getFragment(this.ampdoc.win.location.href);
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...

if (!fragment) {
return '';
}
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.

}
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.

@calebcordry
Copy link
Member

to echo @choumx: if the only use case is for analytics we should define this macro here.

We are trying to move as many of these macros out of core as possible. Not only for bloat, but also to prevent too many reserved keywords. You will also need to enable the url-replacement-v2 experiment

@@ -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')

@lannka lannka requested a review from calebcordry February 20, 2018 22:56
@lannka
Copy link
Contributor

lannka commented Mar 2, 2018

@RJSumi are you still on this? Note that @jridgewell is doing a bunch of refactoring on the same file. (merge conflicts :-)).

@lannka
Copy link
Contributor

lannka commented Mar 13, 2018

As discussed offline, @RJSumi will continue in a new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants