1. Home
  2. Third-Party Integration
  3. Google
  4. How to Add Google Analytics to a WordPress Site

How to Add Google Analytics to a WordPress Site

WP Enthusiast

WP Professional

WP Professional Plus

PairSIM WordPress

You can use Google Analytics to track visitors on your website. You can see what pages they are landing on, where they are navigating to, and when they leave. It can be invaluable knowledge to have when assessing your site.

If you do not have a WordPress site, see our How to Add Google Analytics to an HTML Website article.

Set Up Google Analytics

The first step is to set up the analytics on the Google end and get the tracking ID.

    1. Sign in or create a Google Analytics account
    2. In the left bottom of the sidebar, click Adminadmin interface image
    3. On the right side of the screen, select the account you would like to use or create a new account by clicking the + Create Account buttoncreate account image
    4. Click the + Create Property buttoncreate property image
    5. Select Websitewebsite image
    6. Enter the following information:
      • Website Name: The name you will use to identify your site
      • Website URL: The website’s URL
      • Industry Category: The type of industry that the website falls under
      • Reporting Time Zone: This will determine the time displayed in analytics results
    7. Click the Get Tracking ID buttonget tracking id image
  1. Copy the code on the next page, under the Global Site Tag headerglobal site tag image

Keep this page open. You will need the code for the next step.

Add Analytics Code to WordPress Site

The next step is to add the analytics code to your WordPress website. Because WordPress is a CMS, this process differs from adding code to a simple HTML site.

Go to the Theme’s Function.php File

We will be adding analytics code to the functions.php file of your current theme, so you need to locate your functions.php file.

We recommend having a child theme before adding anything to the functions.php file. If you do not have a child theme, theme updates will overwrite your changes.

To find the theme’s functions.php file, follow these steps:

  1. Log in to your WordPress site’s admin interface
  2. In the left sidebar, hover over Appearance, click Editor in the drop-downeditor image
  3. In the right sidebar, click Theme Functions (functions.php)function button image

Add Code to Your Functions.php File

After you have located your functions.php file, you need to add the analytics code to it.

  1. Paste the following code in the text field

    <?php
    add_action('wp_head', 'pn_add_analytics');
    function pn_add_analytics() { ?>
    
    <!--Paste your Google Analytics code here-->
    
    <?php } ?>
  2. Underneath <!--Paste your Google Analytics code here-->, add the Google Analytics code that you got from the Set Up Google Analytics section
  3. Click Update File at the bottom of the pageupdate file image

Once you have added the tracking code and updated the file, you can test to see if it’s working by visiting the live site, then looking at the REAL-TIME page in the analytics interface. If working, it should show that a visitor is viewing the page.real time image

Google Analytics is provided by Google. Google Analytics is not a product of Pair Networks, Inc., and Pair Networks provides no warranty for Google Analytics.

Please note that there are many levels of website analytics products available. Please consult with your IT professional for advice and guidance on an appropriate analytic tracker. This specific product may or may not meet your needs. Pair Networks, Inc. is providing support for this analytics tracker for your convenience and is not responsible for Google Analytics' performance.

Please read carefully the terms and scope of services for any online service or product you are considering purchasing or using.

Updated on February 20, 2020

Was this article helpful?

Related Articles

Need Support?
Can't find the answer you're looking for?
Contact Support