amp-next-page: Pause analytics component on page change
Describe the new feature or change to an existing feature you'd like to see
amp-next-page does not inform amp-analytics timer triggers that a user is no longer on the original page, so our Chartbeat tracking pings continue to fire from the original page even when it’s no longer in view. As a new page is scrolled to, both the original page A, the new page B, and the upcoming (but not yet opened) page C starts sending us mixed-up data. This leads to inflated pageviews for articles that are not currently being viewed, and incorrect data is sent to our system (e.g. I scroll from article A to article B, and we see a Chartbeat tracking ping containing a title from page A sent with the page path from page B; then, before even reaching page C, I see pings with data that pulls from page A, B and/or C).
We would like to pause the analytics component from the previous page once the user scrolls to a new page, and we would like all data sent to either be about page A, B, or C.
Describe alternatives you've considered
We've tried the following updates to our AMP code (see our AMP docs here) using both the amp-next-page-scroll and amp-next-page-click events, but the problem persists albeit with slight mutations.
When testing these 2 alternatives, we did find that the first page stops pinging once it’s out of view, but we immediately see pings for both article B and article C (even though this article C has not yet come into view) and the ping data is mixed up again (e.g. a ping contains the path of article C with the title of article B).
<amp-analytics type="chartbeat">
<script type="application/json">
{
"vars": {
"uid": "12345",
"domain": "yoursite.com",
"sections": "section 1,section 2",
"authors": "John Doe"
}
"triggers": {
"trackInterval": {
"on": "timer",
"timerSpec": {
"interval": 15,
"maxTimerLength": 7200,
"stopSpec": {
"on": "amp-next-page-scroll"
}
},
"request": "interval",
"vars": {
"decayTime": 30
}
},
"trackAnchorClick": {
"on": "click",
"selector": "a",
"request": "anchorClick",
"vars": {
"decayTime": 30
}
}
},
}
</script>
</amp-analytics>
We've also tried using the following triggers with verticalBoundaries and with timerSpec, but the problem persists.
"triggers": {
"trackInterval": {
"on": "scroll",
"scrollSpec": {
"verticalBoundaries": [10, 20, 30, 40, 50, 60, 70, 80, 90],
},
"request": "interval",
"vars": {
"decayTime": 30
}
},
"triggers": {
"trackInterval": {
"on": "timer",
"timerSpec": {
"interval": 15,
"maxTimerLength": 60
},
"request": "interval",
"vars": {
"decayTime": 30
}
},
Tagging @ampproject/wg-analytics for potential review as this relates to the Chartbeat (and probably others) amp-analytics implementation
Hi, what about something like
"timerSpec": {
"interval": 5,
"startSpec": {
"on": "visible",
"selector": ":root"
},
"stopSpec": {
"on": "hidden",
"selector": ":root"
}
},
Thank you for this suggestion @zhouyx, but unfortunately this didn't work either. As we scroll through the articles, new
Hmmm I'd hope that startSpec: {on: visible} will only enable the timer trigger when the document becomes visible. It could be that the next page manager set the document's visibility too early.
@kristen-peck Do you have an example page?
@zhouyx Here is a page that is using our Chartbeat AMP code and amp-next-page. And another here. I've been using local overrides to update their Chartbeat code with these test triggers, and to change their existing 'domain' (and 'section' or 'author') variables to some fake data:
<amp-analytics type="chartbeat">
<script type="application/json">
{
"vars": {
"uid": "65713",
"domain": "test.com",
"sections": "COD section art",
"authors": "COD teaser art"
},
"triggers": {
"timerSpec": {
"interval": 5,
"startSpec": {
"on": "visible",
"selector": ":root"
},
"stopSpec": {
"on": "hidden",
"selector": ":root"
}
},
"trackAnchorClick": {
"on": "click",
"selector": "a",
"request": "anchorClick",
"vars": {
"decayTime": 30
}
}
}
}
</script>
</amp-analytics>
cc @nainar @alanorozco
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.
Please, this issue still needs a solution