Add Google Analytics to WordPress

Contributors

@ali-al-difaie @mejoananyambura-com


Business Benefits

Track user activity on your WordPress site.


Install and activate a plugin for inserting codes into the header and footer of WordPress pages.

  1. In the WordPress dashboard, go to Appearance > Themes and click on the active theme. Navigate to the support website to find out if the theme settings include a module for inserting header scripts - also commonly called tracking codes. If the theme has an appropriate module, skip to the next step.
  2. If your theme doesn’t include GA tracking, install a plugin like Insert Headers and Footers, Header and Footer Scripts, Head, Footer and post injections, or Head and Footer Scripts Inserter.
  3. If you are using a plugin other than Insert Headers and Footers, make sure that the code appears on all pages.

Create or sign in to your Google Analytics (GA) account.

If you have several Google accounts tied to different email addresses, ensure that you’re signed in to the correct account.

Copy the Global Site Tag tracking code from Admin > Property column > Tracking info > Tracking code.

If you use Google Tag Manager, you can add the tracking ID to your tag manager account without modifying WordPress further.

?

Navigate to the settings for your WordPress theme or plugin and paste the tracking code into the `` code section.

If you see existing code in this section, be careful not to modify it. Paste your code immediately after the `` tag and before any existing content.

Save your plugin or theme settings.

Navigate back to Admin > Property column > Tracking info > Tracking code in Google Analytics and click on Send test traffic.

Google Analytics will display a pop up window to confirm that you have successfully added the GA tracking code to your website, or to tell you that something went wrong.