I am trying to use Segment to track analytics on Google AMP Stories. I want to track what page of the story a viewer taps to, and other ways they interact with the story.
I am using Segment's AMP Mobile Source and followed the Documentation. I added the Page excerpt of code inside of each amp-story-page component:
<amp-analytics type="segment">
<script type="application/json">
{
"vars": {
"writeKey": "WRITE_KEY",
"name": "my page name"
}
}
</script>
</amp-analytics>
When I tested the code using Segments Debugger tool, it triggered the call to Segment when the pages were loaded, not when they were viewed.
Then I tried to incorporate triggers from the AMP story GitHub page
"triggers": {
"storyPageVisible": {
"on": "story-page-visible",
"request": "event"
}
}
but I could not make this work because I don't have a request handler for segment...when running my code with this trigger I get error:
Ignoring event. Request string not found: event
I also tried using similar code to Washington Post which uses Google analytics to track their AMP stories but I ran into the same problem as the code above. Here is Washington Posts code:
<amp-analytics type="googleanalytics" id="googleanalytics1">
<script type="application/json">
{
"vars": {
"account": "UA-50597120-8"
},
"triggers": {
"trackPageview": {
"on": "story-page-visible",
"request": "pageview",
"extraUrlParams": {
"cd1": "STORY_PAGE_INDEX",
"cd2": "STORY_PAGE_ID",
"cd3": "13"
}
}
}
}
</script>
</amp-analytics>
If anyone can help me track when my AMP story pages are viewed, that would be great.