Add Google Analytics or Tag Manger Codes to WordPress without a Plugin

Google Analytics and Tag Manager are powerful tools that provide insights into website traffic, user behavior, and other important metrics. Integrating these tools with a WordPress website can help website owners make data-driven decisions to improve their online presence. In this article, we will discuss how to add Google Analytics or Tag Manager scripts into WordPress after the <head> and <body> tags using the functions.php file.

Step 1: Create a Google Analytics or Tag Manager account

Before integrating Google Analytics or Tag Manager with your WordPress website, you need to create an account on the respective platform. Follow the steps below to create a Google Analytics account:

  1. Go to the Google Analytics website (https://analytics.google.com/analytics/web/) and sign in with your Google account.
  2. Click on the “Sign up” button to create a new account.
  3. Fill in the necessary details, such as account name, website URL, and industry category.
  4. Accept the terms and conditions and click on the “Create” button.
  5. Follow the instructions to set up tracking code for your website.

For Tag Manager, follow the same steps to create an account and add the necessary tags to your website.

Step 2: Add the tracking code to your WordPress website

Once you have created an account on Google Analytics or Tag Manager, the next step is to add the tracking code to your WordPress website. You can do this by adding the code to the header and footer of your website.

  1. Log in to your WordPress dashboard.
  2. Go to Appearance > Editor.
  3. Click on the functions.php file on the right side of the screen.
  4. Scroll down to the bottom of the file and add the following code:
add_action('wp_head', 'add_google_analytics');
function add_google_analytics() { ?>
  <!-- Paste your Google Analytics code here -->
<?php } ?>

add_action('wp_body_open', 'add_google_tag_manager');
function add_google_tag_manager() { ?>
  <!-- Paste your Google Tag Manager code here -->
<?php } ?>
  1. Replace the comment sections with your Google Analytics or Tag Manager tracking code.
  2. Click on the “Update File” button to save the changes.

Step 3: Verify that the tracking code is working

To make sure that the tracking code is working properly, you can use Google Analytics or Tag Manager debugging tools. Follow the steps below to verify that the tracking code is working:

  1. Log in to your Google Analytics or Tag Manager account.
  2. Go to the “Real-Time” section.
  3. Visit your website in a new tab.
  4. Refresh the “Real-Time” section to see if your visit is tracked.

If your visit is tracked, it means that the tracking code is working correctly. If not, you need to check the code for any errors or issues.

In conclusion, adding Google Analytics or Tag Manager scripts into WordPress after the <head> and <body> tags is a straightforward process. By following the steps outlined above, you can easily integrate these powerful tools with your website and start tracking important metrics. Remember to verify that the tracking code is working correctly before relying on the data to make informed decisions.

While adding Google Analytics or Tag Manager scripts to WordPress is a relatively simple process, some website owners may encounter issues or prefer to have a professional handle the task. If you are facing any challenges with adding tracking codes to your website, consider hiring a pro to help you out. A professional can ensure that the tracking codes are correctly integrated with your website, and you can focus on making informed decisions to grow your online presence.

Share on Social Media:
Avatar photo
Yaroslav Volkov
Articles: 13

Leave a Reply

Your email address will not be published. Required fields are marked *