amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

amp-next-page: Pause analytics component on page change

Open kristen-peck opened this issue 6 years ago • 8 comments

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

kristen-peck avatar Aug 24 '20 18:08 kristen-peck

Tagging @ampproject/wg-analytics for potential review as this relates to the Chartbeat (and probably others) amp-analytics implementation

joshschwartz avatar Aug 25 '20 22:08 joshschwartz

Hi, what about something like

    "timerSpec": {
      "interval": 5,
      "startSpec": {
        "on": "visible",
        "selector": ":root"
      },
      "stopSpec": {
        "on": "hidden",
        "selector": ":root"
      }
    },

zhouyx avatar Aug 25 '20 22:08 zhouyx

Thank you for this suggestion @zhouyx, but unfortunately this didn't work either. As we scroll through the articles, new tags are added to the page for each new article, and we keep picking up data from each article's chartbeat tag as they're added.

kristen-peck avatar Aug 27 '20 00:08 kristen-peck

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 avatar Aug 27 '20 00:08 zhouyx

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

kristen-peck avatar Aug 27 '20 17:08 kristen-peck

cc @nainar @alanorozco

zhouyx avatar Aug 27 '20 21:08 zhouyx

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.

stale[bot] avatar Feb 20 '22 10:02 stale[bot]

Please, this issue still needs a solution

fxmoralestot avatar Oct 25 '23 09:10 fxmoralestot