How to add more parameters in Google Analytics for AMP

Let’s see how to add Advanced Google Analytics like page, event, social tracking in AMP.

1. Enable the Options

You will find this option in the WordPress Admin Area -> AMP option panel -> Settings -> Analytics

  • Google Analytics: First enable the Google Analytics option and Enter the Analytics ID.

2. Add the Advanced Analytics Code

  • Advanced Google Analytics: Enable the Advanced Google Analytics option. As you can see there is a JavaScript editor to add the Analytics code in JSON format.
  • Change the “UA-xxxxxxx-x” with your Google Analytics ID.
  • Enter other tracking code in place of “// Enter your Advanced Analytics code here”.

Example code:

"trackEvent": {
        "selector": "#event-test",
        "on": "click",
        "request": "event",
        "vars": {
          "eventCategory": "ui-components",
          "eventAction": "click"
        }
      }

You can insert title, URL, and id as {title}, {url} and {id} respectively.

For example:

"url": "{url}",
"title": "{title}",
"id": "{id}"

URL, Title and post ID can be passed shown below.

"trackEvent": {
        "selector": "#event-test",
        "on": "click",
        "request": "event",
        "vars": {
          "eventCategory": "ui-components",
          "eventAction": "click",
          "url": "{url}",
          "title": "{title}",
          "id": "{id}",
          "author-id": "{author_id}",
          "author-name": "{author_name}",
          "category": "{category}",
          "published-at": "{published_at}",
          "tags":"{tags}",
          "seo-score":"{seo_score}",
          "focus-keyword":"{focus_keyword}"
        }
      }

Before adding this two variable make sure you need to activate Yoast SEO plugin.

After adding another tracking code, your code should look like this:

Note: This is just an example code used only for demonstration purpose. 

I hope this tutorial helps you to successfully add the Analytics on your site and If you encounter any issue you can reach us for the help here.

Google Documentation for AMP analytics: https://developers.google.com/analytics/devguides/collection/amp-analytics/

That’s it for this tutorial!

We hope it helped you. If you have any feedback or questions, then please share them in the comments section below.

Share
Published by
Marqas

How to create an AWeber form in AMP

If you want to add an AWeber form in AMP then first you need to…

3 years ago

How to setup webpushr notification in AMP

Webpushr is the fastest growing web push notifications platform that marketers love & developers rely…

3 years ago

How to add Adobe Analytics in AMP

Follow these steps to add Adobe Analytics in AMP Step 1: Go to WordPress Admin Area -> AMP…

3 years ago

What is the CWV plugin all about

Core Web Vitals are the subset of Web Vitals that apply to all web pages,…

4 years ago

How to fix “Alternate page with proper canonical tag” Page Index issue in Google Search Console

The following reasons can be shown for non-indexing. Server error (5xx) Your server returned a 500-level…

4 years ago

Google Analytics ( GA4 ) integration in AMPforWP

We have added the Google Analytics 4 ( GA 4 ) integration in AMPforWP v1.0.80.…

4 years ago