In this guide, I’ll show you how to track GA EEC (Google Universal Analytics Enhanced E-Commerce) on AMP Pages 🙂
Introduction
AMP (https://amp.dev/) is an open-source HTML framework for the creation of user-first websites, stories, ads, and email.
Launched on October 7, 2015, it was originally created by Google as a competitor to services like Facebook Instant Articles and Apple News. AMP is optimized for mobile web browsing and conceived for crafting web pages with a very fast loading time.
AMP is used even on the mobile Google SERP:
How does Google AMP work?
The AMP pages are nothing more than HTML5 with a set of specifications (requirements and restrictions).
As Google’s AMP Product Manager RudyGalfi said to SearchEngineLand.com, “…the optimization is powered by JavaScript, styling can be customized via CSS3, and pages are cached.”
The type attribute can be used to load a configuration made by a specific vendor. Of course, Google is in the vendor list of amp-analytics type attribute 🙂
In detail, here are the parameters to be set for some Google tools:
for Google Universal Analytics, use the type attribute value googleanalytics
for the gtag library, use the type attribute value gtag
for Google Tag Manager there isn’t a type attribute value, because GTM injects the type attribute on the AMP page through the tags that you have published in GTM
In this guide, I’ll cover the tracking of GA EEC (Google Universal Analytics Enhanced E-commerce) into AMP Pages with the googleanalytics version of the type attribute, and not with the gtag version.
Now let’s dive into event tracking.
To measure events in AMP pages, we need to use triggers and we need to define their parameters.
Trigger parameters are used to track actions like pageviews, render-start, ini-load, click, scroll, timer, visible, hidden, user-error, access-*, video-*, and so on.
In a trigger configuration, we can use the following properties:
on: specifies the type of event (i.e. click)
selector: a CSS selector which specifies the target element or elements (i.e. .buttonclass)
vars: specifies the event name and add additional parameters if necessary (in the following code example, vars refers to the second occurrence of the property, indicated in blue)
In AMP you can track pageviews and events just like you would do in a non-AMP webpage.
For example, you can use this code to track button clicks with the .buttonclass .cta CSS selector:
<script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script> <amp-analytics type="googleanalytics"> <script type="application/json"> {
"vars":{
"account":"UA-XXXXX-Y"
},
"triggers":{
"buttonClick":{ // this is the event name
"on":"click",
"selector":".buttonclass .cta",
"request":"event",
"vars":{
"eventCategory":"click",
"eventAction":"button",
"eventLabel":"cta button"
}
}
}
}
</script>
</amp-analytics>
Great!
“Yeah, that’s great! But…what about the enhanced e-commerce tracking?”
Oh… well… there is a little problem.
“What’s the problem?”
There is no official Google documentation to do it.
“What? Are you kidding me?”
Nope. There are no specific parameters in googleanalytics or gtag to do it 🙁
“Doh! So what can we do?”
Non c’è problema [nón ˈtʃɛ pro·blè·ma]. I found a nice #barbatrucco (which stands for trick, in Italian) to do it.
How to track GA EEC (Google Universal Analytics Enhanced E-commerce) in AMP Pages
As you probably know, Enhanced E-commerce actions are nothing more than extra parameters included in the Google Analytics pageview hit or event hit.
So, the question is: “can I add extra parameters even on AMP analytics?”
The answer is… YES 🙂
What are the Extra URL Parameters in AMP?
An AMP-analytics request can contain an extraUrlParams configuration object; this object specifies additional parameters to be included in the pageview request or event request.
These additional parameters are the Extra URL Parameters.
By default, the extra URL parameters are appended to the query string of a request URL via the usual query string syntax (i.e. https://example.com?a=1&b=2&c=3)
Here’s an example that would append ?a=1&b=2&c=3 to a AMP request:
As you can see in this example, the EEC Parameters (currencyCode, impressions, name, id, price, brand, category, etc. ) are the additional parameters that specify the details about the Product Impressions.
Keep them in mind, because soon we will “convert” them as promised.
Now let’s go back to the extra URL parameters in AMP.
The next question is:
“WhichExtra URL Parameters do I need to use in AMP? And where I can find them?”
The short answer is: in the Measurement Protocol.
The Measurement Protocol
According to Google, the Measurement Protocol is “a standard set of rules for collecting and sending hits from any internet-connected device to Analytics”.
We can think of the Measurement Protocol as the source code of Google Analytics, where data are displayed in their raw form.
This raw form data may seem intimidating at first, but actually, it is nothing more than a query string with some parameters attached.
Having said that, the best way of approaching the Measurement Protocol is by far with a real-world example.
Open the Network Tab of your Google Chrome DevTools
Filter for “v=1”
Select one of the hits of Google Analytics
Click the Headers Tab
Check the parameters
As you can see in Step 3, the “collect?v=1&_v=j89…” part is a query string with several parameters related to the product impression.
Let’s see them in detail:
&il1nm=homepage // this parameter is the Product Impression "Search Results" or list
&il1pi1id=9bdd2 // this parameter is the Product Impression ID
&il1pi1nm=Compton%20T-Shirt // this parameter is the Product Impression name
&il1pi1pr=44.00 // this parameter is the Product Impression price
&il1pi1br=Compton // this parameter is the Product Impression brand
&il1pi1ca=T-Shirt // this parameter is the Product Impression category
See any familiarity with the EEC Parameters? I bet you do!
This list of parameters coincides with the extraUrlParams that we need to insert into the JSON of the amp-analytics component.
As you can see, there is a correspondence between the Measurement Protocol Parameters and the dataLayer parameters that we have seen earlier.
Here is a summary table that I hope you’ll find useful:
Tracking type
Measurement Protocol parameter
dataLayer parameter
Example value
JSON parameter
Product Impressions
il1nm
list
Search Results
"il1nm":"Search Results",
Product Impressions
il1pi1id
id
19
"il1pi1id":"19",
Product Impressions
il1pi1nm
name
Triblend Android T-Shirt
"il1pi1nm":"Triblend Android T-Shirt",
Product Impressions
il1pi1ca
category
Google
"il1pi1ca":"Google",
Product Impressions
il1pi1br
brand
Apparel
"il1pi1br":"Apparel",
Product Impressions
il1pi1pr
price
15,25
"il1pi1pr":"15,25",
Product Impressions
il1pi1ps
position
1
"il1pi1ps":"1",
Product Impressions
il1pi2id
id
717
"il1pi2id":"717",
Product Impressions
il1pi2nm
name
Donut Friday Scented T-Shirt
"il1pi2nm":"Donut Friday Scented T-Shirt",
Product Impressions
il1pi2ca
category
Apparel
"il1pi2ca":"Apparel",
Product Impressions
il1pi2br
brand
Google
"il1pi2br":"Google",
Product Impressions
il1pi2pr
price
33,3
"il1pi2pr":"33,3",
Product Impressions
il1pi2ps
position
2
"il1pi2ps":"2",
How to validate the JSON
Now we need to make sure that our JSON is working smoothly.
To send all Enhanced E-commerce actions with Google Universal Analytics requests, I set up a demo website with the JSON of the amp-analytics component.
dataLayer push (contains an example of the full dataLayer request for the e-commerce action; I used dataLayer because I’m really comfortable with GTM 😀 )
JSON parameters (contains the parameters that you can copy and paste in your JSON)
JSON for AMP (contains the full JSON for AMP request for the e-commerce action)
Of course, I filled the Google Sheet with ALL the Enhanced E-commerce action examples 🙂
As you will see, in the J column (JSON for AMP) I included the full JSON code to be inserted in the AMP page.
Here’s how I did it (and how you can create your own JSON code):
I copied the googleanalytics Pageview JSON for AMP code from the “How to track AMP Pages with Google Universal Analytics” section of this guide (you can find it on the top of this page)
I added the “extraUrlParams: { … }” code portion to the JSON for AMP and filled it with the list of JSON parameters listed in the Google Sheet
I copied the JSON for AMP
I pasted it on JSON Formatter & Validator online website (it’s free!), so I got some validated and formatted code
I pasted the validated and formatted code on the column JSON for AMP of the Google Sheet
Great!
“Yeah! But how can I test this code?”
Let’s do it together!
How to test Enhanced E-commerce tracking on AMP Pages
Of course, to test AMP Pages I had to use a website demo with AMP Pages. To do this:
Paste the JSON code that you have copied into the JSON Configuration section. (Important: don’t forget to change the example Google Universal ID tracking (UA-1111111-1) with your ID, and pay attention to the double-quote character (use the character “ because the character “or the character ” will not work)
Save
In this case, the extraUrlParams will be sent on every pageview.
Step three:
Open the Network tab on your Chrome DevTools by pressing Control + Shift + J or Command + Option + J (Mac). The Console panel opens. You might prefer to dock DevTools to the bottom of your window. Click the Network Tab.
Go to the AMP page. To display the AMP page, I just add ?amp to the URL (http://demo.tagmanageritalia.it/esempio/?amp); in the alternative, use Google Chrome Extension like AMP Validator to find the AMP URL.
Find the google-analytics.com requests. Insert google-analytics.com on the search filter (1), select the collect?v=1 request (2) click the Headers Tab (3) then scroll down: you will see the extraUrlParams of Enhanced E-commerce (4).
Step four:
Now we need to use the GTM/GA Google Chrome Extension: it allows you to easily find the Enhanced E-Commerce (EEC) Hit.
Let’s see how to do it.
Select the GTM/GA Debug tab and reload the page. Now select the GA Tab.
To display only the EEC parameters, just click the EEC tab and… Bingo!
Here are the Promo parameters:
Great! Now let’s take a look at other Enhanced E-Commerce actions 🙂
The procedure is the same:
copy the JSON for AMP
paste it into the AMP analytics section of the Plugin
test and debug with Network Tab or GTM/GA Google Chrome Extension
Here is a short summary video:
Test of the Promotion Clicks EEC action
Copy the JSON for AMP Promotion Clicks from the Google Sheet and replace the AMP Analytics section.
Be careful: to track the click-based EEC actions (i.e. Promotion Click, Add to Cart, Product Click, and so on), you should NOT use a JSON trigger pageview event type; use instead a JSON trigger event type, making sure to set up correctly the CSS selector.
Test of the Product Impressions EEC action
Use the same procedure as the previous test:
Test of the Product Clicks EEC action
Use the same procedure as the previous test:
Be careful: to track the click-based EEC actions (i.e. Promotion Click, Add to Cart, Product Click, and so on), you should NOT use a JSON trigger pageview event type; use instead a JSON trigger event type, making sure to set up correctly the CSS selector.
Test of the Product Details EEC action
Use the same procedure as the previous test:
Test of the Add to Cart EEC action
Use the same procedure as the previous test:
Be careful: to track the click-based EEC actions (i.e. Promotion Click, Add to Cart, Product Click, and so on), you should NOT use a JSON trigger pageview event type; use instead a JSON trigger event type, making sure to set up correctly the CSS selector.
Test of the Remove from Cart EEC action
Use the same procedure as the previous test:
Be careful: to track the click-based EEC actions (i.e. Promotion Click, Add to Cart, Product Click, and so on), you should NOT use a JSON trigger pageview event type; use instead a JSON trigger event type, making sure to set up correctly the CSS selector.
Test of the Checkout Step 1 EEC action
Use the same procedure as the previous test:
Test of the Purchase EEC action
Use the same procedure as the previous test:
Test of the Refund EEC action
Use the same procedure as the previous test:
Conclusion
As you can see, it is possible to send Enhanced E-Commerce data to Google Universal Analytics from AMP Pages.
The trick is to understand the Measurement Protocol of GA and then use the parameters of the extraUrlParams configuration object.
ye
17 11 2021
Thank you, It’s helped me a lot
Matteo Zambon
17 11 2021
You’re welcome 🙂
Buon Tag 😉
Nandan
09 04 2021
Great detailed article Thanks for sharing in the community helping us
Matteo Zambon
12 04 2021
Thanks Nandan for your feedback!