I need to pass the pagePath value dynamically into my amp-analytics tag's var value. Can you please advise how i can achieve this. For example, In the below code snippet , I need to replace the pagePath with different values based on the current page path.
<amp-analytics config="https://www.googletagmanager.com/amp.json?id=xxxxxxxxx>m.url=SOURCE_URL" data-credentials="include"
<script type="application/json">
{
"vars" : {
"pagePath" : { Needs to be passed dynamically }
}
}
</script>
<amp-analytics>
You would use variable substitution (https://github.com/ampproject/amphtml/blob/master/spec/amp-var-substitutions.md).
The variable you're interested in is "Canonical Path" (https://github.com/ampproject/amphtml/blob/master/spec/amp-var-substitutions.md#canonical-path).
You would insert the string
${canonicalPath}wherever you want it to be templated in before the analytics request is sent. For example: