Measurement options for web pages

Learn about other ways to implement Google Analytics.

Web pages using gtag.js will have the latest web page reporting features in Google Analytics. If you would like to explore other methods for measuring web pages, there are several additional options to choose from.

In this article:

Track using gtag.js

The Global Site Tag provides streamlined tagging across Google’s site measurement, conversion tracking, and remarketing products – giving you better control while making implementation easier. By using gtag.js, you will be able to benefit from the latest dynamic features and integrations as they become available. Learn more about getting started with Google Analytics.

Implement a Universal Analytics tag via Google Tag Manager

Use Google Tag Manager container to easily configure and deploy a Universal Analytics tag, or any supported 3rd party tags.

 

To set up a Universal Analytics tag via Tag Manager, follow these steps:

 
  1. If you haven't done so already, create a Tag Manager account.
  2. Install the Tag Manager container snippet in your website's code
  3. Configure a Tag Manager container.
  4. Create your Google Analytics tag in Tag Manager.
  5. Publish your Tag Manager container
 

Once your website has been configured with Tag Manager, you can add any additional tracking tags from the Tag Manager interface with no need to redeploy your website code.

Use analytics.js

The gtag.js library is the recommended tracking code for new implementations. However, there may be cases where you would prefer to use analytics.js (e.g., your site already makes use of analytics.js.) See the developer documentation for more information.

Use the Measurement Protocol

The Google Analytics Measurement Protocol is a standard set of rules for collecting and sending hits from any Internet-connected device to Analytics. It's particularly useful when you want to send data to Analytics from a kiosk, a point of sale system, or anything that is not a website or web page. Because, while the Analytics JavaScript and mobile SDKs automatically build hits to send data to Analytics from websites and web pages, you must manually build data collection hits for other kinds of devices. The Measurement Protocol defines how to construct the hits and how to send them to Analytics.

Tips for dynamic websites

A dynamic website is one for which the web pages are generated using a programming language like Python, Ruby, or PHP. You can use an include statement or template to push the tracking code dynamically to each page:

  1. Find the JavaScript tracking-code snippet for your property, and then copy the entire snippet. Don't make any changes to the snippet.

  2. Paste the entire snippet into its own include file, then add the include statement to your page header so that the snippet appears right after the opening <head> tag.

PHP includes
Copy the JavaScript tracking code snippet and add it to a file named analyticstracking.php. Then include the analyticstracking.php file on each PHP template page. For each template page, immediately after the opening <body> tag, add the following code:

<?php include_once("analyticstracking.php") ?>

Was this article helpful?
How can we improve it?