The ID is read-only and dynamically generated. You shouldn’t be manually putting anything into it. Why are you trying to modify it?
Hi Weston,
Thanks for your response. I am wanting to add Google Analytics to my AMP pages and posts.
So I thought I must add the analytics code and ID into this section… ?
What am I doing wrong?
Hi Weston,
Thanks for your guidance.
I have followed these instructions, added googleanalytics to the type field, left the ID field blank and added my google analytics tracking code to the JSON Configuration field.
However, it gives a message of Invalid analytics config JSON.
What must I do to convert my tracking code into the correct format?
I appreciate your help, could you advise me further or point me in the direction of a guide to do so.
Best wishes
Dave
You’ll need to share the JSON code you entered here for us to be able to help.
Hi @davekehoe84,
Thanks for letting us know how this went.
Does what you added to the “JSON Configuration” field look something like the JSON inside the <script type="application/json"> here?
https://developers.google.com/analytics/devguides/collection/amp-analytics/#page_tracking
Is there a way I can give you this code privately?
Why? It will be displayed publicly on your site anyway.
Ok,
This is the tracking code I get from Google Analytics, which I am trying to add to the AMP plugin.
<!– Global site tag (gtag.js) – Google Analytics –>
<script async src=”https://www.googletagmanager.com/gtag/js?id=UA-42994922-6″></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag(‘js’, new Date());
gtag(‘config’, ‘UA-42994922-6’);
</script>
OK, you’re pasting in the non-AMP Google Analytics JavaScript code. You need to paste in the AMP JSON code. It should look something like this for you:
{
"vars": {
"account": "UA-42994922-6"
},
"triggers": {
"trackPageview": {
"on": "visible",
"request": "pageview"
}
}
}
Refer to the docs for configuration: https://developers.google.com/analytics/devguides/collection/amp-analytics/
Thank you Weston, that code has been accepted by the plugin so I think the analytics should start working now.
I must admit, I am very confused by this setup. No-where in any docs could I find simple instructions as to what to do, so thanks again for helping me.
Exactly what will this code offer data on then in analytics?
Is it just page views? Or behaviours? Referrals? Etc
Does a separate piece of code need to be added for each event?
I appreciate you helping me get this setup.
Best wishes
Dave Kehoe
@davekehoe84 I’m not an analytics expert myself, but you can see from the Google Analytics docs what kinds of things that can track: https://developers.google.com/analytics/devguides/collection/amp-analytics/
Otherwise, I suggest inquiring of the Google Analytics support forums to get more details.