-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ import { | |
} from '../service'; | ||
import { | ||
parseUrl, | ||
getFragment, | ||
removeFragment, | ||
parseQueryString, | ||
addParamsToUrl, | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to check Better yet, you can use |
||
if (!fragment) { | ||
return ''; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whitespace... |
||
} | ||
let args = parseQueryString(fragment.substring(1, fragment.length)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'll parse with the |
||
if (!args.ct) { | ||
return ''; | ||
} | ||
return args.ct; | ||
}); | ||
this.set('CONTAINER', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Likely we'll need better naming. |
||
return document.location.ancestorOrigins[0]; | ||
}); | ||
} | ||
|
||
/** | ||
|
@@ -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) { | ||
|
There was a problem hiding this comment.
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 haveFRAGMENT_PARAM('ct')