Analytics
2.5K members online now
2.5K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

AMP Project - Google Analytics Tracking Code with assigned Content Grouping

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

I am looking for a way to assign my content grouping variables in AMP the same way I am able to assign them as part of the page view call in my normal html pages.

 

For code examples I have posted a detailed example on Stack Overflow:

 

https://stackoverflow.com/questions/40220904/amp-project-google-analytics-content-grouping-amp-analy...

1 Expert replyverified_user

Re: AMP Project - Google Analytics Tracking Code with assigned Content Grouping

Top Contributor
# 2
Top Contributor

Hi Sam,

 

to use Content Groups, you'll have to extend the AMP tracking code, like so:

 

<amp-analytics type="googleanalytics" id="analytics1">
<script type="application/json">
{
  "requests": {
    "pageviewWithCG1": "${pageview}&cg1=${cg1}"
  },
  "vars": {
    "account": "UA-XXXXX-Y"
  },
  "triggers": {
    "trackPageviewWithCustom" : {
      "on": "visible",
      "request": "pageviewWithCG1",
      "vars": {
        "cg1": "My Content Group value here"
      }
    }
  }
}
</script>
</amp-analytics>

Notice where cg1 is defined? That's where your AMP code will need to be adapted to reflect the content group value

VP & Chief Evangelist at Hub'Scan | Contact me
Level 80 Digital Analytics Warrior, KPI Therapist and Keeper of the One True Tagging Plan

AMP Project - Google Analytics Tracking Code with assigned Content Grouping

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Julien, Thank you for your answer. I have been using the new tracking code, but I am not sure if it is working. I have noticed I have no amp URLs in my content groups and I appear to be having less AMP traffic overall.

 

I was looking for documentation on this and was only able to find this page: https://developers.google.com/analytics/devguides/collection/amp-analytics/ it uses a similar code but it is for "Custom Dimensions" and not "Content Groups". Is there any documentation that will let me know for sure that Google treats the "cg1" query string variable as "Content Group 1"? Or are there step I have to take in my Google Analytics settings to accept these custom query string variables?

 

My code for reference:

 

 

<amp-analytics type="googleanalytics" id="analytics1">
<script type="application/json">
{
    "requests": {
        "pageviewWithCG1CG2CG3": "${pageview}&cg1=${cg1}&cg2=${cg2}&cg3=${cg3}"
    },
    "vars": {
        "account": "UA-XXXXXXXX-Y"
    },
    "triggers": {
        "trackPageviewWithCustom" : {
            "on": "visible",
            "request": "pageviewWithCG1CG2CG3",
            "vars": {
                "cg1": "Category Name",
                "cg2": "Author Type",
                "cg3": "Author Name"
            }
        }
    }
}
</script>
</amp-analytics>

 

AMP Project - Google Analytics Tracking Code with assigned Content Grouping

Visitor ✭ ✭ ✭
# 4
Visitor ✭ ✭ ✭

UPDATE: I was able to find a resource that shows cg1 will be accepted as a valid parameter for Content Group 1 https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#cg_

 

AMP Project - Google Analytics Tracking Code with assigned Content Grouping

Top Contributor
# 5
Top Contributor

Yeah sorry, I just know the parameter structure by heart, I can guarantee what I posted works for CG capture Smiley Wink

 

VP & Chief Evangelist at Hub'Scan | Contact me
Level 80 Digital Analytics Warrior, KPI Therapist and Keeper of the One True Tagging Plan

AMP Project - Google Analytics Tracking Code with assigned Content Grouping

Visitor ✭ ✭ ✭
# 6
Visitor ✭ ✭ ✭

Are there any other steps I am missing?

 

It has been two days now and I am still not seeing URLs with /amp showing up in any of my content groups. I have new articles going up every day so Google AMP chache shouldn't be an issue. I have double checked my Account ID in my code and when I look at Google Analytics real time data I see my AMP URL listed but it is still not showing up in my Content Groupings.

AMP Project - Google Analytics Tracking Code with assigned Content Grouping

Top Contributor
# 7
Top Contributor

what's your site's URL?

 

VP & Chief Evangelist at Hub'Scan | Contact me
Level 80 Digital Analytics Warrior, KPI Therapist and Keeper of the One True Tagging Plan

AMP Project - Google Analytics Tracking Code with assigned Content Grouping

Visitor ✭ ✭ ✭
# 8
Visitor ✭ ✭ ✭

onlyinyourstate.com

 

here is a link to the AMP Article I am looking at. I am able to see the Google Analytics code complete with data at the bottom of the page when I inspect it using a mobile view in Development Tools

https://www.google.com/amp/www.onlyinyourstate.com/nebraska/nelson-cemetery-ne/amp/

AMP Project - Google Analytics Tracking Code with assigned Content Grouping

Top Contributor
# 9
Top Contributor

I can confirm content group data is being sent to your property. 

How are your content groups defined in your view?

 

VP & Chief Evangelist at Hub'Scan | Contact me
Level 80 Digital Analytics Warrior, KPI Therapist and Keeper of the One True Tagging Plan

AMP Project - Google Analytics Tracking Code with assigned Content Grouping

Visitor ✭ ✭ ✭
# 10
Visitor ✭ ✭ ✭

I am not sure what you mean by "defined in my view".

 

We set up the three content groupings we are using through the Google Analytics Admin menu under "Account" > "Property (onlyinyourstate.com)" > "All Website Data" > "Content Groupings". Each one is set up with "Tracking Code Enabled" and they are in slot 1, 2 and 3.

 

Is that the information you were requesting?