The analytics.js library (also known as 'the Google Analytics tag') is a JavaScript library for measuring how users interact with your website. This document explains how to add the Google Analytics tag to your site.

Do that and then go to “Google Analytics Setting” and choose “New Variable” from the dropdown menu. You’ll then be taken to a new window where you’ll be able to enter in your Google Analytics tracking ID. This will send your website’s data straight into Google Analytics where you’ll be able to see it later. Power Queries Do you need to build reports that are outside the scope of the free reports offered by Google? Multiple Account Multi-View Multi-segment Powerful ways to use goals, events, multi-channel funnels Up to ten dimensions and seven metrics - downloaded in one query Re-usable queries over many accounts and views Big data, Efficient Refresh Automated Data Refresh Handles large data. The official Google Analytics mobile app lets you monitor all of your Analytics properties so that you can keep track of your business while you're on the go. With this app, you can: 1) Check key metrics in built-in reports 2) Monitor real-time data 3) Compare date ranges and apply segments 4) Build your own reports with any combination of metrics and dimensions 5) Save any reports.

The Google Analytics tag

  • 1 1 Google Analytics Guide We’re excited that you’re implementing Google Analytics to help you make the most of your website and convert more visitors.
  • On Google's Analytics home page, click Admin (the gear icon) at the bottom left. Select your site in the Account and Property columns and click Tracking Code in the Property column. Copy the Tracking ID that appears. Switch back to your Google Analytics panel, and paste the code into the Tracking ID field. Close the Google Analytics panel.

The Google Analytics tag should be added near the top of the <head> tag and before anyother script or CSS tags, and addthe property ID of the Google Analytics property you wish to work with.

Tip: If you do not know your property ID, you can use the Account Explorer to find it.

The above code does four main things:

  1. Creates a <script> element that starts asynchronously downloading the analytics.js JavaScript library from
  2. Initializes a global ga function (called the ga() command queue) that allows you to schedule commands to be run once the analytics.js library is loaded and ready to go.
  3. Adds a command to the ga() command queue to create a new tracker object for the property specified via the 'GA_MEASUREMENT_ID' parameter.
  4. Adds another command to the ga() command queue to send a pageview to Google Analytics for the current page.

Custom implementations may require modifying the last two lines of the Google Analytics tag (the create and send commands) or adding additional code to capture more interactions. However, you should not change the code that loads the analytics.js library or initializes the ga() command queue function.

Alternative async tag

While the Google Analytics tag described above ensures the script will be loaded and executed asynchronously on all browsers, it has the disadvantage of not allowing modern browsers to preload the script.

The alternative async tag below adds support for preloading, which will provide a small performance boost on modern browsers, but can degrade to synchronous loading and execution on IE 9 and older mobile browsers that do not recognize the async script attribute. Only use this tag configuration if your visitors primarily use modern browsers to access your site.

What data does the Google Analytics tag capture?

When you add either of these tags to your website, you send a pageview for each page your users visit. Google Analytics processes this data and can infer a great deal of information including:

  • The total time a user spends on your site.
  • The time a user spends on each page and in what order those pages were visited.
  • What internal links were clicked (based on the URL of the next pageview).

In addition: The IP address, user agent string, and initial page inspection that analytics.js performs when creating a new tracker object is used to determine things like:

  • The geographic location of the user.
  • What browser and operating system are being used.
  • Screen size and whether Flash or Java is installed.
  • The referring site.

Next steps

For basic reporting needs, the data collected via the Google Analytics tag can suffice, but in many cases there are additional questions you want answered about your users.

The guides on this site explain how to measure the interactions you care about with analytics.js, but before implementing a particular feature, it's highly recommended that you read the guides listed under the Fundamentals section in the left-side navigation. These guides will give you a high-level overview of the analytics.js library and help you better understand the code examples used throughout the site.

The next guide in this series explains how analytics.js works.


Connects Google Analytics to WordPress
Supports Universal Analytics / analytics.js
Supports Global Site Tag / gtag.js
Supports Google Analytics 4

This plugin enables Google Analytics for your entire WordPress site. Lightweight and fast with plenty of great features.

GA Tracking Options

  • Universal Analytics / analytics.js
  • Global Site Tag / gtag.js
  • Legacy / ga.js

To enable Google Analytics 4:

  1. Follow this guide to create a GA 4 account
  2. During account creation, you’ll get a tracking (measurement) ID
  3. Add your new tracking ID to the plugin setting, “GA Tracking ID”
  4. Select “Global Site Tag” for the plugin setting, “Global Site Tag”

Save changes and done. Wait 24-48 hours before viewing collected data in your GA account.

GA Feature Support

  • Supports Google Analytics 4
  • Supports Display Advertising
  • Supports Enhanced Link Attribution
  • Supports IP Anonymization
  • Supports Force SSL
  • Supports Tracker Objects
  • Supports Google Optimize
  • Supports User Opt-Out

Download Google Analytics Report

Also supports tracking links and conversions via the Custom Code setting. Learn more about Google Analytics!


  • Blazing fast performance
  • Does one thing and does it well
  • Drop-dead simple and easy to use
  • Regularly updated and “future proof”
  • Stays current with the latest tracking code
  • Includes tracking code in header or footer
  • Includes tracking code on all WordPress web pages
  • Includes option to add your own custom markup
  • Sleek plugin Settings page with toggling panels
  • Option to disable tracking of admin-level users
  • Option to enable page tracking in the Admin Area
  • Works with or without Gutenberg Block Editor
  • Easy to customize the tracking code
  • More features available in the Pro version

This is a lightweight plugin that inserts the required GA tracking code. To view your site statistics, visit your Google Analytics account.

Pro Version

GA Google Analytics Pro includes the same features as the free version, PLUS the following:

  • Visitor Opt-Out Box (frontend UI)
  • Configure multiple tracking codes
  • Live Preview of all tracking codes
  • Choose location of multiple tracking codes
  • Supports Custom Code in header or footer
  • Disable tracking of all logged-in users
  • Disable Tracking for any Post IDs, User Roles, Post Types
  • Disable Tracking for Search Results and Post Archives
  • Display Opt-Out Box automatically or via shortcode
  • Complete Inline Help/Documentation
  • Priority plugin help and support

Learn more and get GA Pro »


User Data: This plugin does not collect any user data. Even so, the tracking code added by this plugin is used by Google to collect all sorts of user data. You can learn more about Google Privacy here.

Cookies: This plugin uses simple cookies for the visitor Opt-Out Box to remember user preference for opt-in or out of Google Analytics.

Services: This plugin does not connect to any third-party locations or services, but it does enable Google to collect all sorts of data.

Support development of this plugin

I develop and maintain this free plugin with love for the WordPress community. To show support, you can make a donation or purchase one of my books:

And/or purchase one of my premium WordPress plugins:

  • BBQ Pro – Super fast WordPress firewall
  • Blackhole Pro – Automatically block bad bots
  • Banhammer Pro – Monitor traffic and ban the bad guys
  • GA Google Analytics Pro – Connect WordPress to Google Analytics
  • USP Pro – Unlimited front-end forms

Links, tweets and likes also appreciated. Thanks! 🙂


How to install the plugin

  1. Upload the plugin to your blog and activate
  2. Visit the settings to configure your options

After configuring your settings, you can verify that GA tracking code is included by viewing the source code of your web pages.

Note: this plugin adds the required GA code to your web pages. In order for the code to do anything, it must correspond to an active, properly configured Google Analytics account. Learn more at the Google Analytics Help Center.

How to use the plugin

To enable Google Analytics tracking on your site, follow these steps:

  1. Visit the “Plugin Settings” panel
  2. Enter your GA Tracking ID
  3. Choose either Universal Analytics or Global Site Tag*
  4. Configure any other plugin settings as desired (optional)

Save changes and done. After 24-48 hours, you can log into your Google Analytics account to view your stats.


Global Site Tag is required for Google Analytics 4. For steps on setting up GA 4, check out the plugin homepage (under “GA Tracking Options”).

Also note that it can take 24-48 hours after adding the tracking code before any analytical data appears in your Google Analytics account. To check that the GA tacking code is included, look at the source code of your web page(s). Learn more at the Google Analytics Help Center.

Upgrading Analytics

Google Analytics tracking methods change over time. First there was urchin.js, then ga.js, and now analytics.js, soon to be replaced officially by gtag.js. If you are using an older version and want to upgrade, check out these Google docs:

Plugin Upgrades

To upgrade GA Google Analytics, remove the old version and replace with the new version. Or just click “Update” from the Plugins screen and let WordPress do it for you automatically.

Note: uninstalling the plugin from the WP Plugins screen results in the removal of all settings from the WP database.

For more information, visit the GA Plugin Homepage.

Restore Default Options

To restore default plugin options, either uninstall/reinstall the plugin, or visit the plugin settings > Restore Default Options.


GA Google Analytics cleans up after itself. All plugin settings will be removed from your database when the plugin is uninstalled via the Plugins screen. Your collected GA data will remain in your Google account.

Pro Version

Want more control over your GA Tracking codes? With awesome features like Opt-Out Box and Code Previews? Check out GA Pro »

Like the plugin?

If you like GA Google Analytics, please take a moment to give a 5-star rating. It helps to keep development and support going strong. Thank you!


How to enable Google Analytics 4?

To enable Google Analytics 4:

  1. Follow this guide to create a GA 4 account
  2. During account creation, you’ll get a tracking (measurement) ID
  3. Add your new tracking ID to the plugin setting, “GA Tracking ID”
  4. Select “Global Site Tag” for the plugin setting, “Global Site Tag”

Save changes and done. Wait 24-48 hours before viewing collected data in your GA account.

Tracking code is not displayed in source code?

If you check the source code of your pages and don’t see the GA tracking code, check the following:

  • Check that your theme includes the hooks, wp_head and wp_footer
  • If you are using a caching plugin, try clearing the cache

If the GA tracking code still is not displayed, most likely there is interference from another plugin or theme. In this case, the best way to resolve the issue is to do some basic WordPress troubleshooting.

Google Analytic says tracking code is not detected?

You need to wait awhile for Google to collect some data, like at least a day or whatever. Standard stuff for Google Analytics. For more information, check out the Google Analytics Help Center.

Can I filter the output of the “Custom GA Code” setting?

Yes, you can use the gap_custom_code filter hook.

How to implement Google Optimize?

Google Analytics App Download

Here are the steps:

  1. Enable Universal Analytics in the plugin settings
  2. Add the Optimize plugin (e.g., ga('require', 'GTM-XXXXXX');) to the setting, “Custom GA Code”
  3. Add the Page Hiding (flicker) snippet to the setting, “Custom <head> Code”
  4. Enable the setting, “Custom <head> Location”

Done! You can view the source code of your web pages to verify the results.

More info about Google Optimize.

How to enable Opt-out of tracking?

Here are the steps:

  1. Add the following code to the plugin setting, “Custom Code”: <script>window['ga-disable-UA-XXXXX-Y'] = true;</script>
  2. Check the box to enable the setting, “Custom Code Location”.

Done! You can view the source code of your web pages to verify the results.

More info about user opt-out.

How to disable the “auto” parameter in ga(create)?

By default the plugin includes the auto parameter in the tracking code:

However some tracking techniques (such as Site Speed Sample Rate) require replacing the auto parameter. To do it:

First disable the auto parameter by adding the following code to WordPress functions or custom plugin:

Now that auto is disabled, you can replace it with your own parameter(s). For example, to implement Universal Analytics Site Speed Sample Rate, enter the following code in the plugin setting “Custom Tracker Objects”:


Save changes and done. The resulting tracking code will now look like this:

So can adjust things as needed to add any parameters that are required.

Got a question?

To ask a question, suggest a feature, or provide feedback, contact me directly. Learn more about Google Analytics and GA tracking methods.

Based on Stephen King's best-selling novel, The Outsider begins by following a seemingly straightforward investigation into the gruesome murder of a young boy. But when an insidious supernatural force edges its way into the case, it leads a seasoned cop and an unorthodox. The outsiders hbo series. The Outsiders is a 30+ year-old movie, there isn’t a lot of value in reviewing the story, directing, acting, etc. These many years later. Some people will like it, some won’t. I saw it for the first time in early 2017 on one of those obscure old-movie channels on cable and got hooked.


This developer really knows his stuff. A very easy to use plugin that saves a lot of time.
Coments are closed
Scroll to top