Track WordPress Author On AMP Pages In Google Analytics With PageFrog Plugin

0
42
Track WordPress Author On AMP Pages In Google Analytics With PageFrog Plugin

Here we can see, “Track WordPress Author On AMP Pages In Google Analytics With PageFrog Plugin”

You’re an AMP and WordPress pioneer, but simply measuring pageviews isn’t enough for you. Yes, the PageFrog WordPress plugin for Facebook Instant Articles & Google AMP Pages makes your life easier, but are you willing to give up your cherished Custom Dimensions in Google Analytics since the feature isn’t built-in? I don’t believe so!

In this article, I’ll teach you how to use the Facebook Instant Articles & Google AMP Pages by PageFrog plugin to submit the author’s name of a WordPress post to Google Analytics as a custom dimension using AMP Analytics variables.

To make this work, we’ll need to do the following:

  • In Google Analytics, create a Custom Dimension called “author.”
  • To assign the post author’s name to the “author” Custom Dimension in the Google Analytics script, edit the PageFrog plugin code.
Also See:  PS5 SSD Expansion Support to Arrive With Forthcoming Update

How To Track The WordPress Author As A Custom Dimension In Google Analytics With The PageFrog AMP Plugin For WordPress

  1. Log into Google Analytics, go to the ADMIN part of your account, and under the PROPERTY heading, choose Custom Dimensions.
  2. Tap Create after adding a Custom Dimension called author.
  3. On the Custom Dimensions page, take note of the author index. This is how we’ll inform the Analytics code to which dimension our author variable should be assigned. The author is index 1 in my case.
  4. In your favourite editor, open the file /wp-content/plugins/pagefrog/public/partials/amp-google-analytics-template.php. The file looks like this by default:
<amp-analytics type="googleanalytics">
    <script type="application/json">
        {
            "vars": {
                "account": "<?php echo $analytics->get_google_analytics_site_id(); ?>"
            },
            "triggers": {
                "trackPageview" : {
                    "on": "visible",
                    "request": "pageview"
                }
            }
        }
    </script>
</amp-analytics>

5. Get the name of the WordPress article author and submit it to Google Analytics as an AMP Analytics Variable as a Custom Dimension by modifying the code as follows:

<amp-analytics type="googleanalytics">
	<script type="application/json">
	    {
	        "requests": {
	            "pageviewWithCd1": "${pageview}&cd1=${cd1}"
	        },      
	        "vars": {
	            "account": "<?php echo $analytics->get_google_analytics_site_id(); ?>"
	        },
	        "triggers": {
	            "trackPageviewWithCustom" : {
	                "on": "visible",
	                "request": "pageviewWithCd1",
	                "vars": {
	                    "cd1": "<?php global $post; $author_id=$post->post_author; the_author_meta( 'display_name', $author_id ); ?>"
	                }
	            }
	        }
	    }
	</script>
</amp-analytics>

6. Open the inspector in Google Chrome and look for the Google Analytics code just after the opening body> tag to see if the author’s name is being added to your HTML.

7. Open the JavaScript console in Google Chrome and browse your AMP website with #development=1 attached to the url to ensure the AMP code is legitimate. You’re good to go if you notice “AMP Validation Successful.”

WordPress Author: Identified

Congratulations on being one of the two or three individuals who found this article fascinating enough to read it now that you’re AMPed because you’re tracking each author’s performance in Google Analytics. We need to stick together as WordPress AMP pioneers, and I’m delighted you found the answer you were looking for here. If it worked, please comment below alternatively if it didn’t.

Conclusion

I hope you found this guide useful. If you’ve got any questions or comments, don’t hesitate to use the shape below.

User Questions

1. Is it possible to use Google Analytics to track WordPress?

You can also add tracking code for Google Analytics to the WordPress functions file. It will then automatically install the tracking code to every page on your WordPress site. This code must be added to your theme’s functions.

2. In Google Analytics, where can I see AMP pages?

Log into your Google Analytics account and pick the website for which you’d like to access your AMP statistics. Select Behavior » Site Content » All Pages from the drop-down menu. Use the phrase /amp in the search field above the table to see only the data for your AMP sites.

3. What is the location of WordPress analytics?

To begin, use the WordPress Dashboard to receive a fast summary of your metrics. The number of sessions, pageviews, bounce rate, top posts and pages, and more may be found here. Navigate to Insights » Reports from the WordPress dashboard for more thorough reports on your WordPress analytics.

Also See:  Rainbow Six Extraction Release Date Seemingly Confirmed In Updated Post

4. How to “add” AMP to WordPress – with Google Analytics

How to "add" AMP to WordPress – with Google Analytics tracking working from WordPress

5. Google AMP analytics : WordPress – Reddit

Google AMP analytics from WordPress