InMotion Hosting Support Center

In this article, we'll show you how you can include your Google Analytics tracking code with PHP. Be sure to check out our full guide on signing up for Google Analytics.

In order for these steps to work properly, your site should already be coded with PHP. For most content management systems (like WordPress or Joomla), this is already the standard. If you are unsure about whether or not your site is coded with PHP, be sure to check with your developer.

The reason you will need PHP is because we will be using an "include" code. This means we will be including the code from one file into another. PHP is required in order to accomplish this.

  1. Copy your tracking code from Google
  2. Create a new file in your document root called gtag.txt (you can name this file anything you want, this is only an example)
  3. Paste your Google tracking script in the gtag.txt file
  4. Insert this code into your website's index file (typically index.php:
    <?php include_once "gtag.txt";?>

This code "includes" the content of your "gtag" file in your site's code. If you index file loads on every page (as it does in a CMS like WordPress), the tracking code will also load on every page.

Was this article helpful?

Related Questions

Here are a few questions related to this article that our customers have asked:
Ooops! It looks like there are no questions about this page.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Support Center Login

Our Login page has moved, Click the button below to be taken to the login page.

Post a Comment

Name:
Email Address:
Phone Number:
Comment:
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

0 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!