Google Analytics code not working for AMP pages

Posted in: Newspaper
Post count: 30

I’m using tagDiv AMP Plugin for my blog. I already implement both codes for AMP in Theme Panel as shown below-

Traffic to non AMP pages is counted and showing correctly.But Google Analytics doesn’t count the traffic for the AMP pages.
I was tried both code as –

{
“vars” : {
“gtag_id”: “<GA_TRACKING_ID>”,
“config” : {
“<GA_TRACKING_ID>”: { “groups”: “default” }
}
}
}

And

{
“vars” :{
“account”: “GA_TRACKING_ID″
},
“triggers”:{
“trackPageview”:{
“on”: “visible”,
“request”: “pageview”
}
}
}

Note: I replaced GA_TRACKING_ID with my analytics ID.

So pl. guide me.

Post count: 35449

Hi,

The analytics code for AMP should be of this form only, please check it
https://www.screencast.com/t/xL301xKgf
If you enter it like that it will be loaded in AMP pages.

From what I can find online, maybe it would be better to use different tracking for AMP
https://moz.com/blog/amp-reporting

Thanks

Post count: 30

Thanks for your reply,

First,
the link you provided
https://www.screencast.com/t/xL301xKgf
is already implement by me and I told in my question.

and the second link is complete useless for me as there is not clear analytics code, it is only about to channel grouping.

it is ok that some traffic shown under referral section at – www-itkhoj-com.cdn.ampproject.org

but the is only near about 1000 only.
and when I open AMP page, why it doesn’t show in “real time” traffic.

Also there is huge difference in Google Adsense and Google analytics. Google analytics only shows half of the traffic as compared to Google Adsense.

And all this happens after I change the theme.

So I hope instead of giving me screen shot, you provide me actual analytics code which will work in AMP.

Post count: 35449
Post count: 11

Hi itkhoj, you have to go in wordpress > Newspaper > AMP > Analytics and remove code from there.

Now, you open your FTP software (i use FileZilla) and you go to: /wp-content/plugins/td-amp/templates and open “html-start.php”

copy this at line 18 under “style”: <script async custom-element=”amp-analytics” src=”https://cdn.ampproject.org/v0/amp-analytics-0.1.js”></script&gt;

copy this at line 23 under “body”:

<amp-analytics type=”gtag” data-credentials=”include”>
<script type=”application/json”>
{
“vars” : {
“gtag_id”: “INSERT YOUR ANALYTICS ID”,
“config” : {
“INSERT YOUR ANALYTICS ID”: { “groups”: “default” }
}
}
}
</script>
</amp-analytics>

Where you see “INSERT YOUR ANALYTICS ID” you have to write your analytics code. CLOSE AND SAVE FILE

My html-start is like this:
html-start

Post count: 38

Thank you Ducacordero,

Anybody tried the above solution? There is a problem with the Analytics report and the tagDiv AMP Plugin. It is not matching the page view numbers and the additional test shows that the AMP plugin is not counting the AMP Page visits with GA Code.

The WordPress AMP plugin is displaying the visits properly. However, the tagDiv AMP plugin offers more features related to the theme and can’t get rid of it.

Expecting the solution from the Dev team.

  • This reply was modified 7 years by kodiyan.
Post count: 28

I implemented with google tag manager and it worked.

Tag manager has a specific option for tracking AMP pages. Identical setup just choose AMP.

  • This reply was modified 7 years by Rikk.
Post count: 38

Rikk,

Google Tag Manager has a code to add in website header and footer, right? TagDiv AMP plugin doesn’t have the option to add Header and Footer code in AMP Pages. So how did you achieve this? I’m using Google Tag manager for regular posts, but not working with AMP posts.

Google Analytics can see traffic on: http://www.wesbite.com/postxx/
But it does not count the traffic to: http://www.wesbite.com/postxx/amp/

  • This reply was modified 7 years by kodiyan.
Post count: 28

Yes, it would certainly help if TAGDIV team added an additional field for the secondary code snippet.

I did as Ducacordero stated, put the Google tag manager code in the AMP template. Its only one file edit.

TEAM note .. this is a request. Note also that Google now recommends that everyone use tag manager for implementation of GA code.

  • This reply was modified 7 years by Rikk.
Post count: 35449

Hi,

We are aware of google now recommends and is possible that in the coming updates this to be implemented.

Thank you for your understanding!

Post count: 38

@Rikk,
Thank you for your help. Managed to get it run until TagDiv team bring AMP header/footer option to add Tag Manager.

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