Tracking Code for Google Analytics


Tracking Code For Google Analytics is a simple, lightweight WordPress plugin for inserting your Google Analytics Universal Analytics tracking code. The plugin does one thing and one thing only; prints the standard Google Analytics tacking script to the <head> of your website. To insert your tracking ID, navigate to Settings > General and then scroll to the bottom of the page.


composer require claytoncollie/tracking-code-for-google-analytics


If you want to set the tracking ID without using the wp-admin user interface, use the filter below.

     * Set Google Analytics tracking ID.
     * @param string $tracking_id Tracking ID.
     * @return string
    function ( string $tracking_id ) : string {
        $tracking_id = 'UA-7654321';
        return $tracking_id;


You can also define the tracking ID in your wp-config.php file with the following snippet.



While the purpose of this plugin is to be very tightly scoped, issues and pull requests are welcome on GitHub. I do not guarantee that everything will be merged or support will be given.


If you like this plugin and would like to support my work, please consider a small donation via Coinbase.


  1. Upload tracking-code-for-google-analytics to the /wp-content/plugins/ directory
  2. Activate the plugin through the ‘Plugins’ menu in WordPress
  3. Navigate to Settings > General > scroll to the bottom of the page
  4. Insert your tracking ID
  5. Save your changes


Why did I build this plugin?

The plugins I have used in the past to solve this problem have too many features for my liking. This plugin is comprised two functions. One for registering a settings field on the Options General page. And another for printing the tracking code to the frontend. I want a lightweight solution for the websites that I build without all of the extra bells and whistles. If you are expecting this plugin to do more or grow in the future, please do not use it.

Where is the tracking code inserted?

The tracking code is inserted into the <head> section.

Will this plugin slow down my website?

No. This plugin is intentionally lightweight. All it does is register a settings field, saves to the database, and then inserts the tracking code. Nothing more.

I found a bug. How do I report it?

Can I use this plugin with Composer?


There are no reviews for this plugin.

Contribuidores e desenvolvedores

“Tracking Code for Google Analytics” é um software com código aberto. As seguintes pessoas contribuíram para este plugin.


Registro de alterações


  • Fix readme markdown
  • Bump patch version to deploy


  • Fix readme markdown
  • Bump patch version to deploy


  • Patch version bump to deploy properly


  • Major version. Possible breaking changes. Test locally before updating.
  • Change callback names. Possible breaking change.
  • Bump PHP required version to 7.2
  • Add PHP Namespaces
  • Add PHP parameter type hinting
  • Add PHP return type hinting
  • Add automated static analysis GitHub action
  • Add automated code linting GitHub action
  • Add automated acceptance tests GitHub action
  • Add automated WordPress version checker GitHub action
  • Add donation link to Coinbase
  • Fix URLs in readme files
  • Fix markdown syntax for changelog in readme.txt
  • Ignore phpstan config from deployed plugin
  • Ignore from deployed plugin


  • Add ability to define tracking in wp-config.php
  • Update documentation
  • Test with WordPress 6.0.0


  • Update documentation
  • Test with WordPress version 5.6.0


  • Initial release