Archive for the ‘Google Analytics’ Category

How to add Google Analytics Code to GeneratePress Theme

Saturday, December 2nd, 2023


Integrating Google Analytics into a WordPress website is a crucial step for website owners looking to gain insights into their visitor behavior and site performance.

Whether you’re using GeneratePress as your theme or any other, there are straightforward methods to add your Google Analytics tracking ID.

The two most common approaches include using the Google Site Kit plugin for a more automated process or manually inserting the tracking code into your site’s header.

This guide will walk you through both methods, helping you choose the best option for your needs and ensuring that your website is well-equipped to gather valuable analytics data.

Google Site Kit

Google Site Kit is an invaluable tool, especially for non-tech savvy WordPress users GeneratePress theme.

As an official plugin developed by Google, Site Kit simplifies the process of adding Analytics to your website. It allows you to connect directly to your Google Analytics account and automatically embeds the necessary tracking code across all pages of your site. This eliminates the need for manual code insertion, making it an ideal solution for those who prefer a more streamlined and user-friendly approach.

Additionally, Google Site Kit provides the convenience of viewing key analytics data directly within your WordPress dashboard, offering a seamless integration that enhances your site management experience.

Adding Google Analytics Code Using Google Site Kit Plugin

Before we begin, you will need first need to create a Gmail account, then enroll that email account with Google Analytics and Google Search Console platforms (click here if you need instructions).

Step # 1 – Install Google Site Kit Plugin:

  • Go to your WordPress dashboard.
  • Navigate to ‘Plugins’ > ‘Add New’.
  • Search for ‘Google Site Kit’, install, and activate it.

Step # 2 – Setup Google Site Kit:

  • Once activated, go to the new ‘Site Kit’ menu.
  • Follow the setup instructions to connect your Google account.

Step # 3 – Connect Google Analytics:

  • In the Site Kit dashboard, find and connect the Google Analytics module.
  • Follow the on-screen instructions to link your Google Analytics account and select the correct property (your website).
  1. Verification and Ready to Go:
    • Google Site Kit will automatically add the tracking code to your site.
    • You can view analytics data directly in your WordPress dashboard.

Manually Adding the Tracking Code


Manually adding the Google Analytics tracking code offers a hands-on approach for WordPress users who prefer direct control over their site’s configuration.

This method involves accessing the Google Analytics platform to obtain your unique tracking code and then embedding it into your WordPress site, typically within the header section. This is done either by editing the theme files directly or using the theme’s custom code options, such as in the GeneratePress theme.

While this approach requires a bit more technical know-how compared to using a plugin like Google Site Kit, it provides flexibility in terms of code placement and ensures that the tracking code remains intact even if you change plugins or themes in the future.

It’s an effective choice for those who have a specific setup in mind or want to maintain a minimal number of plugins on their site.

  1. Access the WordPress Customizer:
    • Go to your WordPress dashboard.
    • Navigate to ‘Appearance’ > ‘Customize’.
  2. Navigate to Widgets:
    • In the Customizer, look for the ‘Widgets’ section.
    • Click on it to access the widget areas provided by your theme.
  3. Select the Header Widget Area:
    • Find the ‘Header’ widget area. The availability of this area depends on your theme configuration, so ensure your version of GeneratePress includes it.
    • Click on the Header area to add a widget to it.
  4. Add a Custom HTML Widget:
    • Click ‘Add a Widget’ and choose ‘Custom HTML’ from the list of available widgets.
    • Paste your Google Analytics tracking code into the content area of the Custom HTML widget.
  5. Save and Publish:
    • After adding the code, click ‘Publish’ to save your changes.
    • This will add the Google Analytics tracking code to every page of your site, as the header is typically loaded on every page.
  6. Verify the Tracking Code:
    • After publishing, you can check your site’s source code or use tools like Google Tag Assistant to verify that Google Analytics is properly set up and receiving data.

Wrapping Up

In conclusion, integrating Google Analytics with the GeneratePress theme on your WordPress site can be effectively achieved through two distinct methods: using the Google Site Kit plugin or manually inserting the tracking code.

The Google Site Kit plugin offers a user-friendly and streamlined approach, ideal for those who prefer a simple, plugin-based solution that also allows for easy access to analytics data within the WordPress dashboard.

On the other hand, manually adding the tracking code, either through a Custom HTML widget in the header or by editing theme files (especially when using a child theme), provides more control and flexibility, particularly for users comfortable with a bit of coding.

Both methods ensure that your Google Analytics is set up correctly, enabling you to track visitor data and gain valuable insights into your website’s performance.

There are other methods of adding the Google Analytics tracking code, such as modifying the header.php or functions.php files, but I do not recommend them as they are tricky to add and can break your site.

Google Universal Analytics GA3 – Two Code Versions

Wednesday, January 4th, 2023

Google Analytics has been around since 2005 when Google acquired a web analytics company called Urchin.

Urchin Code (circa 2005)

  • Based on “Urchin on Demand” codebase
  • August 2006 – implemented “asynchronous tracking” code between <head>tags

Google Analytics (GA2)

  • April 2011 – Implemented new dashboards, reports, etc.
  • September 2011 – Launched Real-Time analytics

Google Universal Analytics (GA3) – Version A

  • October 2012 – New features including cross-platform tracking, flexible tracking data collection from multiple devices, and the introduction of custom dimensions and metrics
  • Used the ga.js library
Google Analytics GA3 – Circa 2017 (gtag.js library)
  • ga.js library includes:
    • The basic tracking functions for a default setup of Google Analytics
    • Uses multiple functions to send data
    • The _setAccount function associates the tracking code with your specific Google Analytics account by setting the account number (which is provided to you when you create your account)
    • The _trackPageview function tracks a pageview on your website (i.e. “hits”).
  • ga.js is designed to support Google Analytics (i.e. no other Google products)

Google Analytics 360

  • March 2016 – primarily targeted for enterprise customers; included tag manager, optimize, data studio, etc.

Google Universal Analytics (GA3) -version B

  • October 2017 – Implemented “Global Site Tag” data collection method (gTag.js) to unify the tagging system
  • gtag.js code is similar to ga.js code but has a slightly different syntax. Here is an example of the tracking code for Google Analytics using gtag.js:
  • gtag.js code includes the same basic tracking functions as the ga.js library, but the syntax is slightly different:
    • A single ‘gtag' function is used to send data to Google Analytics and other Google Products, and the config' command is used to set the account number for your Google Analytics account
  • ga.js is designed to support multiple Google marketing products (i.e. Google Analytics, Google Ads, Google Tag Manager,, and Google Optimize)
  • Scheduled to stop collecting data on July 1, 2023

Google Analytics 4 (GA4)

  • October 2020 – Released GA4
  • Integrated with Google’s ‘BigQuery”; Tracks “events” instead of “sessions”
  • The gtag.js similar to the code found in UA (GA3) 2017 version except:
    • It includes the basic tracking functions for a default setup
    • The ‘gtag‘ function is used to send data to GA4
    • The ‘config‘ command is used to set the measurement ID for your GA4 property
    • The measurement ID is a unique identifier that is provided to you when you create a GA4 property
  • In addition gtag.js, you will also need to implement event tracking in order to capture user interactions with your website. Here is an example of how you might track a button click event in GA4:
  • As of January 2023, GA4 is still work-in progress

“gtag.js” used in Google Universal Analytics and Google Analytics G4

gtag.js is a JavaScript library that is used to send data to Google Analytics and other Google marketing and analytics products. There are two main versions of gtag.js:

  • one that is used for Universal Analytics (the previous version of Google Analytics)
  • one that is used for Google Analytics 4 (GA4)

“gtag.js” used in Google Universal Analytics (G3, 2017)

The version of gtag.js that is used for Universal Analytics is designed to support the traditional pageview-based tracking model of Universal Analytics.

It includes functions that allow you to track pageviews, set custom dimensions and metrics, and configure other aspects of your Universal Analytics tracking.

Here is an example of the gtag.js code for Universal Analytics:

“gtag.js” used in Google Analytics (G4, 2020)

The version of gtag.js that is used for GA4 is designed to support the event-driven tracking model of GA4.

It includes functions that allow you to track specific events (such as button clicks or pageviews) and send them to GA4 for analysis.

Here is an example of the gtag.js code for GA4:

Key Takeaways

As of now, Google Universal Analytics (UA or G3) is going away on July , 2023 so it is imperative that you start collecting web traffic data for now with GA4.

It is unclear if Google will retain historical data under UA so it might be a good idea to export data you want to keep.

  • GA4 should be implemented even if is is not prime-time ready
  • Installing GA4 should not impact GA3 (UA) data collection
  • If you are still using GA3 (FY2012) version without issues, do not upgrade to GA3 (2017) which uses gTag.js library before installing GA4. There are un-documented reporting discrepancies between ga.js and gtag.js