Knowledgebase Home / How to Add Google Analytics Code to WordPress Without a Plugin
// View Comments //

How to Add Google Analytics Code to WordPress Without a Plugin

If you don’t want to use a plugin, you can add Google Analytics code to your WordPress site by putting the tracking code in the header or bottom of your theme. Here is a step-by-step guide on how to add GA4 to WordPress without a plugin.

Quick Steps

  1. Create a new or log into your Google Analytics account
  2. Copy the tracking code for GA4
  3. Edit the header/footer of your WordPress theme and save it once the tracking code is added

Manually Add Google Analytics Code to Your WordPress Site Without a Plugin

Google Analytics is the most popular and effective web analytics service, providing important insights into a website’s performance, user behavior, and traffic trends for website owners and digital marketers. Google introduced this free service in 2005, and since then it has become an integral part of all current digital marketing campaigns, allowing companies of all sizes to make data-driven decisions that improve their online visibility. Google Analytics allows its users to get insight into their audience by monitoring and analyzing data like page visits, bounce rates, conversion rates, and user demographics, all with the end goal of improving the site’s usability.

The most recent version of Google’s online analytics service, Google Analytics 4 (GA4), includes support for sophisticated features and machine learning. GA4 is a comprehensive monitoring solution for websites and mobile apps that gives actionable intelligence to boost conversions and user loyalty.

How to get the tracking code for Google Analytics 4

  1. Go to https://analytics.google.com/ to log in to your Google Analytics account.
  2. If you don’t have an account, follow the steps on the screen to make one.
  3. Click on the “Admin” (the gear icon) in the lower left area of the screen.
  4. Choose or make the account you want to use in the “Account” field.
  5. Click the blue “+” button in the “Property” section, and then click “Create Property.”
  6. Fill in the necessary information for your property, like “Property name” and “Reporting time zone,” and click “Next.”
  7. Give some details about your business, and then click “Create.”
  8. On the Admin page, in the “Property” box, click “Data Streams.”
  9. Click on the one that works best for your page. (Web, iOS, or Android).
  10. Enter the URL of your website and a name for the stream, then click “Create stream.”

After making the data stream, you will see the “Measurement ID” and the “Global Site Tag (gtag.js)” code piece for GA4.

This is how the GA4 tracking code should look:

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'GA_MEASUREMENT_ID');
</script>

Put your real GA4 Measurement ID in place of G-XXXXXXXXXX. This tracking code can now be added to your page.

How to Add GA4 to WordPress Without a Plugin

In order to add GA4 to WordPress without a plugin, follow the simple steps below.

  1. Go to your WordPress homepage and log in.
  2. Click on “Appearance” and then “Theme Editor.”
  3. A list of theme files will be on the right. Find the file called “header.php” and click on it. If you can’t find the file “header.php,” try looking for the file “footer.php.”
  4. Find the opening tag in the “header.php” file. If you’re using the “footer.php” file, look for the tag at the end of the file.
  5. Paste the code you copied earlier right after the <head> tag or right before the </body> tag, based on which file you’re editing.
  6. To save your changes, click “Update File.”

Now, the Google Analytics tracking code will be added to your WordPress site, and you won’t need another plugin to track how many people visit your site. Remember that if you change your theme, you will need to go through these steps again to add the tracking code to the new theme.

Conclusion

You have learned how to add Google Analytics Code to Your WordPress Site Without using a plugin


If you have any web hosting questions please feel free to reach out to us. We're happy to help.
Shared Hosting | Reseller Hosting | Managed WordPress Hosting | Fully Managed VPS Hosting

Our Guiding Principles

  • Provide consistent, stable, and reliable web hosting services.
  • Ensure rapid ticket response and quick resolutions to issues.
  • Never saturate or over-provision servers to ensure stability and speed for our customers.
  • Use only high-quality enterprise-class hardware to ensure minimal downtime from hardware failures.
  • Provide clear pricing with no hidden fees or gotchas.
Subscribe to comment notifications
Notify of
guest
0 Comments
Inline Feedbacks
View all comments