Analytics code for AMP pages

Posted in: Newspaper
Post count: 12

Hi, what kind of code should I enter here https://i.imgur.com/AAvkVdc.jpg ?

The Universal Analytics?
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-53020307-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'UA-53020307-1');
</script>

Or this?
{
"vars":{
"account":"UA-53020307-1"
},
"triggers":{
"trackPageview":{
"on":"visible",
"request":"pageview"
}
}
}

Post count: 20688

Hi,

The AMP analytics code should be of this form – http://prntscr.com/mzhl3u Enter it like that and there will be no problem. The last code you mention is the one that should be entered there.

Thanks

Post count: 77

Just to avoid duplicate topic… I’m pretty sure that GA code doesn’t work properly when “AMP + mobile” was chosen. I pasted my code directly to AMP plugin (not in Mobile Theme panel). It works great on “AMP” but not on “AMP + mobile. My site: https://radioklinika.pl (now set on “AMP+mobile”)

My code is:
{
“vars”: {
“account”: “UA-2415269-29”
},
“triggers”: {
“trackPageview”: {
“on”: “visible”,
“request”: “pageview”
},
“scrollPings”: {
“on”: “scroll”,
“request”: “event”,
“scrollSpec”: {
“verticalBoundaries”: [
50
]
},
“vars”: {
“eventCategory”: “AMP Scroll Depth”,
“eventAction”: “Scrolled”,
“eventLabel”: “${verticalScrollBoundary}%”
}
},
“pageTimer”: {
“on”: “timer”,
“timerSpec”: {
“interval”: 90,
“maxTimerLength”: 90,
“immediate”: false
},
“request”: “event”,
“vars”: {
“eventCategory”: “AMP Engagement”,
“eventAction”: “more than 90s”
}
}
}
}

  • This reply was modified 7 years by Jumich.
Post count: 20688

On just mobile version the code from the main theme panel analytics section will be loaded
http://prntscr.com/n0wj5j
The one from AMP will load only when AMP is loaded. In the AMP section enter it as mentioned in the documentation, in the theme panel main analytics section enter it as provided (full code) – http://prntscr.com/n0wkw5

Post count: 77

OMG… I told you… when I set my site on “AMP”, my code wich was pasted in AMP plugin works perfectly. When I swich to “AMP + mobile” it dosn’t work. I’ve tried also to paste this code into Mobile Theme filed but nothing happend. Would you be so kind and check it for me? My site: https://radioklinika.pl Situation on this moment: for desktop I have GA code on my GTM. I pasted the second json code into AMP plugin and Mobile Theme. So in fact I have two kinds of code in 3 different placement… On AMO and Mobile Theme it doesn’t work!

Post count: 20688

On AMP pages this code will load – http://prntscr.com/n10gt1
On desktop and mobile theme this one – http://prntscr.com/n10h30

If you want a separate analytics code just for the mobile theme, you could enter it in the mobile theme files directly, but the one from desktop will still load (could be removed with a modification if needed). But this will have to be all redone after a theme update when the mobile theme files will be replaced.

This would be all there is to it.

Viewing 6 posts - 1 through 6 (of 6 total)
The forum ‘Newspaper’ is closed to new topics and replies.