Google Universal Analytics Destination

Destination Info
Components
Connection Modes
Device-mode Cloud-mode
Web Web
Mobile Mobile
Server Server

Google announced that all standard Universal Analytics properties will stop processing new data on July 1, 2023. 360 Universal Analytics properties will receive a one-time processing extension ending on July 1, 2024. Segment recommends migrating to Google Analytics 4 as soon as possible. Learn more about when Google Analytics 4 will replace Universal Analytics.

Migrate mobile implementations to Firebase

Google ended support for Google Analytics classic on iOS and Android mobile apps on October 31st 2019. To continue measuring and optimizing user engagement in your mobile apps, migrate your implementation to use the Firebase SDKs. If you are using Google Analytics 360 you do not need to migrate.

Which Google destination should I use?

If your Google Measurement ID starts with a G, you’re using G-Codes from Google Analytics 4, and should consider using Segment’s Google Analytics 4 destination.

Although GA4 is now the default when you create a new property, you can still create a Universal Analytics property. You can use a UA property with Segment’s Google Universal Analytics destination.

Different Measurement IDs begin with different prefixes, which indicate which Google destination you should use.

Prefix Google Account type Segment Settings
UA Your global site tag is controlled by Google Universal Analytics. The ID is your Google Universal Analytics Measurement ID. To find the property associated with this ID, use the account search feature in Google Universal Analytics. If the property doesn’t appear, you probably don’t have access to it. Google Universal Analytics: Tracking ID
G Your global site tag is controlled by Google Analytics 4 (GA4). The ID is your Google Analytics Measurement ID. Google Analytics 4: Measurement ID
AW Your global site tag is controlled by Google Ads. The numeric string following the AW prefix is your Google Ads Conversion ID. Google Ads: Google Conversion ID
DC Your global site tag is controlled by a Floodlight tag. The numeric string following DC is your Advertiser ID. Floodlight: DoubleClick Advertiser ID
other Your global site tag is controlled by a different Google product or may be implemented incorrectly. Use the Tag Assistant extension for Google Chrome to verify. n/a

Getting Started

Segment supports Google Universal Analytics client-side and server-side tracking. To use Google Universal Analytics for mobile devices, you must use Google Firebase instead of the original Google Universal Analytics destination. See the migration guide for more instructions.

When you enable the Google Universal Analytics destination in Segment:

  • Your changes appear in the Segment CDN in about 45 minutes, and then Analytics.js starts asynchronously loading Google Universal Analytics JavaScript library on your web page. This means you should remove Google’s snippet from your page.

  • Your Google Universal Analytics real-time dashboard starts showing live, concurrent visitors.

  • Google Universal Analytics starts automatically collecting data on your site. It takes several hours for Google to process this data and add it to your reports, but you should still see events appear in the Google Universal Analytics real-time events dashboard.

Consent Mode

Google is enforcing consent starting March 6, 2024 for European Economic Area (EEA) users. Google Analytics won’t be updated to support Consent Mode due to planned deprecation by Google. Segment recommends you to migrate to Google Analytics 4 as soon as possible.

Classic tracking deprecated

These docs cover Google Analytics Universal features, since the Classic tracking method has been depreciated.

Page and Screen

When you make a Page call, Segment sends a pageview to Google Universal Analytics. You can send pageviews from the browser, or using any of the Segment server libraries.

The resulting page event name in Google Universal Analytics corresponds to the fullName of the page event. fullName consists of a combination of the category and name parameters. For example, analytics.page('Home'); produces a Page event called Home in the Google Universal Analytics dashboard, but analytics.page('Retail Page', 'Home'); produces an event called Retail Page Home.

When you send Page events from a server library you must include a url property, or else Google Universal Analytics silently rejects the Page event.

If you send a screen call using a server library, you must pass in an application name using Segment’s context.app.name object, or Google rejects your event.

Virtual Pageviews

Virtual pageviews are when you send a pageview to Google Universal Analytics when the page URL didn’t actually change, for example when a full-screen modal dialog appears. You can do this with Segment by making a Page call with optional properties, like in the following example. Include both the category and name, in addition to the properties.

analytics.page('Form', 'Signup Modal', {
  title: 'Signup Modal',
  url: 'https://segment.com/#signup',
  path: '/#signup',
  referrer: 'https://segment.com/'
});

Including URL Query Strings

By default Segment only sends the domain and path to Google Universal Analytics. For example, if someone views a page with the url http://example.com/pagename/?xyz=123&r=5, Segment sends http://example.com/pagename/ to Google Universal Analytics as the URL.

In some cases, for example if you’re tracking search queries, you might want to include the whole URL including the query string to Google Universal Analytics. To do this, go to the Google Universal Analytics destination settings in the Segment App, navigate to the Advanced Options section, and check Include the Query String in Pageviews.

Identify

It is against Google’s terms of service to pass Personally Identifiable Information (PII) to the Google Universal Analytics reporting interface. For that reason Segment never passes anything from an Identify call to Google unless you specifically tell it to. You can read about Google’s best practices for avoiding this here.

User ID

Google Universal Analytics Universal tracking method allows you to set a user ID for your identified visitors.

To use this feature you must set up User-ID in your Google Universal Analytics property and create a User-ID view.

To pass the id from your Identify calls to Google Universal Analytics, go to the Google Universal Analytics destination settings in the Segment App, navigate to the Advanced Options section, and enable the Send User-ID to GA setting.

An example call might look like the following:

analytics.identify('12345', {
  email: 'jakep@example.com',
  name: 'Jake Peterson'
});

In this example set the User-ID to 12345 for Google Universal Analytics, but don’t share the email or name traits with Google.

If you are passing an email, phone number, full name or other PII as the id in an Identify call do not use this feature. That is against the Google Universal Analytics terms of service and your account could be suspended.

Custom Dimensions

Google Universal Analytics has multiple scopes for each custom dimensions: hit (synonymous with events), session, user, product (which requires that enhanced ecommerce be enabled). Segment’s device-mode Analytics.js library supports all of them.

Setting up Custom Dimensions

First, configure the Custom Dimensions from your Google Universal Analytics admin page.

Once you finish this set up in Google Universal Analytics, you can map traits and properties to your custom dimensions. Go to the Google Universal Analytics destination settings in the Segment App and locate the Custom Dimensions setting. This is where you will enter your mapping. You can only map each trait or property to one Custom Dimension at a time.

When you finish mapping dimensions and save the settings, Segment checks if the user traits and properties in Identify, Track and Page calls are defined as a dimension. If they are defined in your mapping, Segment sends that dimension to Google Universal Analytics.

In the server-side integration, you can opt-in to mapping top-level and context object fields to dimensions and metrics using the Enable Mappings from Top-Level or Context Fields - Server Side Only setting. If this setting is enabled, top-level and context object fields defined in the Custom Dimensions mapping and found in Identify, Track, Page and Screen calls are sent to Google Universal Analytics.

Traits in Identify calls that map to Custom Dimensions are only recorded to Google Universal Analytics when the next Track call or Page call is fired from the browser.

Continuing the example above, we can set the Gender trait with the value of Male, which maps to dimension9, and it will be passed to Google Universal Analytics when we make the ‘Viewed History’ Track call.

You would make the following Identify call:

analytics.identify({
  Gender: 'Male'
});

And then the following Track call:

analytics.track('Viewed History');

Server side Identify

If you are sending Identify calls from your server libraries or have Segment Cloud App sources that send back Identify calls with enriched user traits, you can send that data to your GA account using custom dimensions and metrics.

Unlike the device-mode destination which runs directly on the device, and which can use the browser and the global window ga tracker, in a server library implementation Segment checks your traits, then checks your settings for custom dimension or metric mappings, and then sends the Identify with an explicit event.

You can specify what the event action should be called in the Google Universal Analytics settings. If you don’t specify a name, Segment uses a default of event ‘User Enriched’. Since an event category is also required, you can specify which trait you want Segment to set this value to. For example, if you send a trait such as type, Segment sets the value of traits.type as the event category if defined, and if it is not, sets it to the default value ‘All’.

Note: Segment marks enriched user trait events as a Non-interaction event. Non-interaction events are available if you’re using Google Universal Analytics.

A/B Test Versions to Dimensions

Segment makes it simple to save your A/B testing versions to custom dimensions in Google Universal Analytics by mapping an experiment to a custom dimension in the Google Universal Analytics destination settings.

If you are using cloud-mode or server-side Google Universal Analytics destinations, you can also send this data automatically using the experiment_id, experiment_name, variation_id, and variation_name properties. If both an experiment and variation are defined, then this is sent automatically. Segment uses the ids before using the names. If both an ID and a name exist, Segment sends the ID first. For example, if you have an experiment_id, an experiment_name, and a variation_name in a call, only the experiment_id and variation_name are sent to Google Universal Analytics.

When you have an active A/B test on a page, Segment either sets that experiment as a property or a user trait, depending on how you choose to send experiment data to other tools on your A/B testing tool’s Segment settings page. The property or trait for A/B test experiments are labeled like the following examples:

'Experiment: EXPERIMENT_NAME': 'EXPERIMENT_VARIATION'

For example, if you have an experiment called Home CTA and a visitor sees a variation called Create free account now, Segment sets the following property or trait:

'Experiment: Home CTA': 'Create free account now'

To record that property or trait as a custom dimension you would map Experiment: Home CTA to a custom dimension, as in the following example:

a b test custom dimension mapping screenshot

Remember to set up dimension13 in your Google Universal Analytics Admin first, as described above.

Track

Segment records a Google Universal Analytics event whenever you make a Track call. You can see your events inside Google Universal Analytics under Behavior -> Events -> Overview. Keep reading for more details about the Google Universal Analytics event category, action, label, value and how to populate them.

You can send events from the browser or your server. Here’s a basic Track call example:

analytics.track('Logged In');

For this example these event attributes are sent to Google Universal Analytics:

Event Category All
Event Action Logged In

Note: In device-mode only, if you pass category to the page call, Segment will use the category from page instead of setting default Event Category to All.

And another Track call example, this time with all Google Universal Analytics event parameters:

{
  "userId": "12345",
  "action": "track",
  "event": "Logged In",
  "properties": {
    "category": "Account",
    "label": "Premium",
    "value": 50
  }
}

That call creates a Google Universal Analytics event with these attributes:

Event Category Account
Event Action Logged In
Event Label Premium
Event Value 50

For Event Value you can name the event property value or revenue. Segment recommends that you use value for client-side tracking and revenue for more accurate server-side revenue tracking. Calling it revenue is best if the event made you money directly. That way Segment can also pass the revenue data to other destinations you enable.

Non-interaction Events

Google Universal Analytics allows you to tag some events as “non-interaction” events. To create an event with the nonInteraction flag, pass Segment an event property labeled nonInteraction with the value of 1. You can also set all events to be non-interactive by default in the Advanced Options.

Here’s an example:

{
  "action": "track",
  "event": "Viewed Legal Info",
  "properties": {
    "nonInteraction": 1
  }
}

Enhanced ecommerce events cannot be tagged with the nonInteraction flag or Advanced Options. Instead, in device-mode, Segment marks all enhanced ecommerce events as Non-interaction events. When you use cloud-mode or server-side, Segment marks the Order Refunded, Promotion Viewed, Promotion Clicked, Product List Viewed, and Product List Filtered enhanced ecommerce events as Non-interaction events. All other enhanced ecommerce events do not include a non-interaction flag.

Enabling E-Commerce tracking

Segment supports Google Universal Analytics basic e-commerce tracking across all libraries. Follow the E-commerce tracking spec and Segment records the appropriate data to Google Universal Analytics.

Before you begin, enable Ecommerce tracking for the view you want to track transactions to. You can do this in Google Universal Analytics by navigating to Admin > View Settings and switching the Ecommerce Settings switch to ON.

Transactions do not appear in your reports until you enable this setting.

All Ecommerce spec events are recommended, but not required. The only required event is Order Completed. For each order completed you must include an orderId, and for each product inside that order, you must include an id and name for each product. All other properties are optional.

Enabling Enhanced E-Commerce tracking

Segment supports Google Universal Analytics Enhanced E-Commerce tracking across both device-mode (Analytics.js, Analytics-android, Analytics-ios) and cloud-mode sources. Enhanced Ecommerce allows you to combine impression data, product data, promotion data, and action data. This is required for product-scoped custom dimensions.

To get started, enable enhanced ecommerce in Google Universal Analytics and use the standard Ecommerce tracking spec, and Segment records the data to Google Universal Analytics formatted using their enhanced ecommerce API.

Before you begin, enable Ecommerce tracking for the view you want to track transactions in. You can do this in Google Universal Analytics by navigating to Admin > View Settings and switching the Ecommerce Settings switch to ON.

Next, go to your Google Universal Analytics destination settings in the Segment App, and enable Enhanced Ecommerce.

Similar to regular e-commerce, the only required event is Order Completed. This call also must include an orderId and an array of products, each containing an id or name.

For all events that include product details, you must pass either name or product_id. For product_id Segment defaults to properties.product_id and fallback to properties.sku.

All other properties are optional. The Refunded Order event also requires an orderId.

Note: Segment’s Android SDK v2.0.0 does not support properties.sku since no mapping to this property is available in Google’s latest SDK. Instead, pass this as a product_id.

Measuring Checkout Steps

To take get the most out of the Enhanced E-commerce features, you should implement some specific events. The biggest difference between “e-commerce” and “enhanced e-commerce” is support for checkout steps. To track your checkout funnel and measure metrics like cart abandonment, etc, you must first configure your checkout funnel in the Google Universal Analytics admin interface to give each checkout step an easily readable label.:

enhanced ecommerce checkout funnel

Next, add Viewed Checkout Step and Completed Checkout Step events to your checkout flow for each step of the funnel you set up in Google Universal Analytics. Make sure you pass the step number and step-specific options as a property of those events, as in the examples below.

The example below shows two Track calls: one for when the user first arrives at the first checkout step, and one for when they complete it. These correspond to the “Review Cart” funnel step in the example image above.

//upon arrival at first checkout step ('Review Cart' per the screenshot example above)
analytics.track('Viewed Checkout Step', {
  step: 1
});

//upon completion of first checkout step ('Review Cart')
analytics.track('Completed Checkout Step', {
  step: 1
});

Next, are two Track calls for entering and exiting the second step of the funnel, “Collect Payment Info”.

//upon arrival at second checkout step ('Collect Payment Info' per the screenshot example above)
analytics.track('Viewed Checkout Step', {
  step: 2
});

//upon completion of this checkout step ('Collect Payment Info')
analytics.track('Completed Checkout Step', {
  step: 2,
//if this is the shipping step
  shippingMethod: 'FedEx',
//if this is the payment step
  paymentMethod: 'Visa'
});

The next four examples are similar, for the additional two steps in the checkout flow. By instrumenting these, you can tell where a user leaves the checkout process.

//upon arrival at third checkout step ('Confirm Purchase Details' per the screenshot example above)
analytics.track('Viewed Checkout Step', {
  step: 3
});

//upon completion of third checkout step ('Confirm Purchase Details')
analytics.track('Completed Checkout Step', {
  step: 3,
//you will need to provide either an empty shippingMethod or paymentMethod for the event to send.
  shippingMethod: '' // or paymentMethod: ''
});

//upon arrival at fourth checkout step ('Receipt' per the screenshot example above)
analytics.track('Viewed Checkout Step', {
  step: 4
});

//upon completion of fourth checkout step ('Receipt')
analytics.track('Completed Checkout Step', {
  step: 4,
//you will need to provide either an empty shippingMethod or paymentMethod for the event to send.
  shippingMethod: '' // or paymentMethod: ''
});

Note: Both shippingMethod and paymentMethod are semantic properties and part of the Ecommerce spec. Use the exact spelling if you want to send these properties.

The four steps above are only an example, and you can create as many steps in your funnel as you need. You still must track the Order Completed event per the standard Ecommerce tracking spec after you’ve tracked the checkout steps.

For client-side integrations we use Google Universal Analytics’ ProductAction class to track Checkout Steps and Options. You can read the Google Universal Analytics developer docs for information on specific methods:

Measuring Promotions

Enhanced Ecommerce allows you to measure the internal and external marketing efforts that support your sales. To use Enhanced Ecommerce’s promotion reports, collect data about promotion impressions and promotion clicks with Analytics.js, like in the following examples:

analytics.track('Viewed Promotion', {
  id: <id>,
  name: <name>,
  creative: <creative>, // optional
  position: <position> // optional
});
analytics.track('Clicked Promotion', {
  id: <id>,
  name: <name>,
  creative: <creative>, // optional
  position: <position> // optional
});

For client-side integrations, we use Google Universal Analytics’ Promotions class to measure promotions. You can read their developer docs for information on specific methods:

Coupons

To send coupon data to your Order Completed event when using Enhanced E-commerce, you can add the coupon property on the order level, or the product level, or both. In the example below, the Segment Google Universal Analytics Ecommerce destination accepts total or revenue, but not both. We recommend that you use revenue for compatibility with several other destinations that also use the term revenue.

For better flexibility and total control over tracking, Segment lets you decide how to calculate how coupons and discounts are applied. For example:

analytics.track({
  userId: '019mr8mf4r',
  event: 'Order Completed',
  properties: {
    orderId: '50314b8e9bcf000000000000',
    total: 27.5,
    shipping: 3,
    tax: 2,
    discount: 2.5,
    coupon: 'hasbros',
    currency: 'USD',
    repeat: true,
    products: [
      {
        id: '507f1f77bcf86cd799439011',
        sku: '45790-32',
        name: 'Monopoly: 3rd Edition',
        price: 19,
        quantity: 1,
        category: 'Games',
        coupon: '15%OFF'
      },
      {
        id: '505bd76785ebb509fc183733',
        sku: '46493-32',
        name: 'Uno Card Game',
        price: 3,
        quantity: 2,
        category: 'Games',
        coupon: '20%OFF'
      }
    ]
  }
});

Measuring Product Impressions

Enhanced Ecommerce also allows you to collect impression information from users who have viewed or filtered through lists containing products. This allows you to collect information about which products have been viewed in a list, which filters or sorts they applied to a list of results, and the positions of each product within that list.

Product impressions are mapped to the ‘Product List Viewed’ and ‘Product List Filtered’ Analytics.js events. You can find more information about the parameters and requirements here in the Ecommerce tracking spec.

Analytics.js allows you to easily collect and send this data, like in the examples below:

analytics.track('Product List Viewed', {
  category: 'cat 1',
  list_id: '1234',
  products: [
    {
      product_id: '507f1f77bcf86cd799439011',
      sku: '45790-32',
      name: 'Monopoly: 3rd Edition',
      price: 19,
      category: 'Games'
    }
  ]
});
analytics.track('Product List Filtered', {
  category: 'cat 1',
  list_id: '1234',
  filters: [
    {
      type: 'department',
      value: 'beauty'
    },
    {
      type: 'price',
      value: 'under'
    }],
  sorts:[ {
    type: 'price',
    value: 'desc'
  }],
  products: [
    {
      product_id: '507f1f77bcf86cd799439011',
      sku: '45790-32',
      name: 'Monopoly: 3rd Edition',
      price: 19,
      category: 'Games'
    }
  ]
});

Tip: To tie product clicks and views to the same Product List Name in Google Universal Analytics, include a list property in your ‘Product Viewed’ and ‘Product Clicked’ events. The value in the list property should match the value in the list_id property for the corresponding ‘Product List Viewed’ and ‘Product List Filtered’ events.

Refunds

To view refund in Google Universal Analytics, you must have enhanced e-commerce enabled.

For full refunds, you can send this event when an order or transaction is refunded:

analytics.track('Order Refunded', {
    order_id: '50314b8e9bcf000000000000',
  });

For partial refunds, you must include the order_id as well as the productId and quantity for the items refunded:

analytics.track('Order Refunded', {
    order_id: '50314b8e9bcf000000000000',
    products: [
      {
      product_id: '123abc',
      quantity: 200
      }
    ]
  });

Server Side

When you track an event or pageview with one of the server-side libraries or HTTP API Segment sends it to the Google Universal Analytics REST API.

You must include a server-side tracking ID in your Google Universal Analytics destination settings or else Segment cannot pass server-side events to Google Universal Analytics. The tracking ID can be the same UA code as your regular property ID, or you can choose to send the server-side events to a separate Google Universal Analytics property.

Combining Server-side and Client-side Events

Google Universal Analytics uses cookies to keep track of visitors and their sessions while visiting your website. The cookie data is stored in the visitor’s browser, and is sent along to Google Universal Analytics every time a new pageview or event occurs. This allows Google Universal Analytics to show a single unique visitor between multiple page reloads.

Your servers also have access to this cookie, so they can re-use it when you send server-side events to Segment. If you don’t use the existing cookie Segment has to create a new one to make the server-side request to Google Universal Analytics. When we create a new cookie the client-side and server-side events from the same user will look like two distinct visitors in Google Universal Analytics.

To use server-side Google Universal Analytics, there are three options with Segment:

  1. Pass your Google Universal Analytics cookies to Segment (preferred).
  2. Use two Google Universal Analytics profiles: one for client-side data and one for server-side data.
  3. Ignore the additional visitors generated by not passing the cookie.

Passing Cookies from Universal Analytics

When you add Google Universal Analytics to the integrations object, the Google Universal Analytics event appears in the Segment debugger as Google Analytics.

Universal Analytics (analytics.js) uses the clientId to keep track of unique visitors.

A Google Analytics Universal cookie will look like this:

_ga=GA1.2.1033501218.1368477899;

The clientId is this part: 1033501218.1368477899

You can double check that it’s your clientId by running this script in your JavaScript console:

ga(function (tracker) {
    var clientId = tracker.get('clientId');
    console.log('My GA universal client ID is: ' + clientId);
});

If you want the server-side destination to use your user’s clientId, pass it to us in the integrations['Google Universal Analytics'].clientId object. You must pass this value manually on every call as we do not store this value for you.

Here’s a Ruby example:

Analytics.track(
  user_id: '019mr8mf4r',
  event: 'Clicked a Link',
  properties: {
    linkText     : 'Next'
  },
  integrations: {
    'Google Universal Analytics' => {
      clientId: '1033501218.1368477899'
    }
  }
)

If you do not pass integrations['Google Universal Analytics'].clientId, we look for the userId or anonymousId value and set the hashed value of either userId or anonymousId as the cid. By default, we prioritize userId over anonymousId which may have implications for reports that tie anonymous-to-known user behavior. In those cases, you can choose to prioritize anonymousId by enabling the Prefer Anonymous ID for Client ID - Server Side Only setting.

User Agent

By default, we won’t set the user-agent header. If you have your user’s user-agent server-side, you can send it to us using the context object. The context object is an optional argument supported by all server-side sources.

Here’s a Ruby example:

Analytics.track(
  user_id: '019mr8mf4r',
  event: 'Loaded a Page',
  properties: {
    url: 'http://example.com/pricing'
  },
  context: {
    user_agent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17'
  }
)

Visitor Geo-Location

Google Universal Analytics uses the IP address of the HTTP request to determine the location of the visitor. This happens automatically for client-side tracking, but takes a little more work for server-side calls.

For geo-location to work from a server-side call you’ll need to include the visitor’s ip in your .track() call.

Here’s a Ruby example:

Analytics.track(
    user_id: '019mr8mf4r',
    event: 'Purchased Item',
    properties: { revenue: 39.95 }
    context: { ip: '11.1.11.11' })

UTM Parameters

If you want to send UTM parameters to Google Universal Analytics using one of the Segment server-side sources they need to be passed manually. The client-side Javascript library (Analytics.js) is highly recommended for collecting this data since it all happens automatically.

Your UTM params need to be passed in the context object in context.campaign. For Google Universal Analytics campaign.name, campaign.source and campaign.medium all need to be sent together for things to show up in reports. The campaign.content param is optional, but will be forwarded to GA if you send it to Segment.

Measurement Protocol Parameters

Google Universal Analytics uses a reserved set of Measurement Protocol Parameters which are automatically collected by the device-mode Google Universal Analytics tracker.

To include Measurement Protocol Parameters when sending server-side events to Google Universal Analytics:

  1. Collect the value of the parameter as a Segment trait or property
  2. Configure the Segment Google Universal Analytics destination to map the trait or property to a specific Measurement Protocol Parameter key

Segment supports the plt, pdt, gclid, dt, and cid Measurement Protocol Parameters.

Features

Segment supports the following Google Universal Analytics features.

In general, Segment’s Google Universal Analytics destination supports Google Analytics Universal features, and does not support the deprecated Google Analytics Classic features.

Client-Side Library Methods

Because Segment’s client-side snippet wraps Google Universal Analytics’s Javascript, all GA library methods that don’t map to Segment methods are available client side. Although invoking a native library method won’t send data to Segment or other Segment-enabled destinations, the method will send data to Google Universal Analytics.

To access Google Universal Analytics methods while using Segment, write these methods inside an analytics.ready() function, for example:

analytics.ready(function(){
  // GA library methods here
})

Anonymize IP Address

Check the box in the Advanced Options for Google Universal Analytics inside of Segment.

Remarketing

Google’s remarketing (The remarketing tag formerly known as Doubleclick) is used to tag visitors for remarketing campaigns. It is also used to identify demographic and interest data on visitors that is displayed in Demographic & Interest reports inside of Google Universal Analytics.

Turn this feature on by checking the box in your Google Universal Analytics destination settings.

Since remarketing is loaded through Segment Google Universal Analytics will not be able to validate that the code is present on the page. Just click Skip validation and your data will start showing up within a few hours.

Across Sub-domains

This works automatically if you’re using the Universal tracking method. To track across sub-domains we recommend upgrading to universal if you haven’t already.

If you need to set a specific domain name keep reading :)

Multiple Trackers

Although Segment does not support loading multiple trackers through the destinations settings page (you will probably run into Google Universal Analytics’s rate limits), you can load a 2nd tracker on the page manually.

Here’s how you’d initialize the second tracker and send a pageview to the second tracker Google Universal Analytics property:

analytics.ready(function(){
  ga('create', 'UA-XXXXX-Y', 'auto', {'name': 'secondTracker'});
  ga('secondTracker.send', 'pageview');
})

Note: Make sure this script is placed after your Segment snippet, ideally at the end of the head tag.

After you create the second tracker, you probably want to use the .on() emitter to automatically send data to this separate Google Universal Analytics instance based on when you make other Segment calls.

The below code would trigger an event to Google Universal Analytics when you make a Segment track call.

analytics.on('track', function(event, properties, options){
   // custom logic based on event properties
  ga('secondTracker.send', {
    hitType: 'event',
    eventCategory: properties.category || 'All',
    eventAction: event,
    eventLabel: properties.label || 'All'
  })
});

Important: Keep in mind you will need to do all the data translation/properties mapping inside this .on() function before you send the event to Google Universal Analytics like you see in the destination code.

To do this server side, you can create a separate source in Segment, and within this source enter your GA credentials for the second tracker.

This source can be your server-side source. From there, its easy to send data to multiple projects server-side, as you can see in this Node example you can initialize multiple instances of the library.

Segment does not support Google’s Consent Mode feature. Consent Mode enables you to adjust how Google’s tags load on your site, based on whether users consent to your use of cookies. This feature requires Google’s gtag.js library, and does not work when you use Segment’s Google Universal Analytics destination, because it loads Google’s analytics.js library instead of the gtag.js library.

The Google Universal Analytics Cookie Domain Name setting allows you to specify the domain that the _ga cookie will be set on. By default the cookie is placed on the top level domain: domain.com.

We default the Cookie Domain Name to auto, which automatically sets the cookie at the root domain level, which allows you to track across multiple sub-domains, but does not work on localhost. You can find this setting in your Google Universal Analytics destination settings.

If you need to test on localhost, but don’t need to track between multiple sub-domains, then you can set the domain to none.

If you only want the cookie to persist on a single sub-domain, enter that sub-domain in the Cookie Domain Name field, like this: swingline.example.com. In this case visitors to conclusions.example.com or example.com will not be tracked.

For more information on Google Universal Analytics cookies and domains name see Google’s docs on the subject.

Cross-Domain Tracking

Segment supports Google Universal Analytics tracking across multiple top level domains, but it requires a bit of work from you. There are two ways to track visitors across domains.

Tracking Visitors with User-ID

If you’re identifying your users with a User-ID cross-domain tracking becomes simple. All you have to do is make sure you identify your users on each domain and Google will merge those users together as one.

The only problem with this approach is that it only works for identified users, anonymous visitor sessions will not be maintained across domains.

Tracking Anonymous Visitors

When a visitor comes to your website, domain1.com, Google Universal Analytics sets a first-party cookie that represents that user. That cookie looks like 182119591.1441315536, and is tied to domain1.com (making it a first party cookie).

When your visitor clicks a link to go another domain, let’s say domain2.com, you’ll need to tell the new site about the domain1.com cookie. This is done by rewriting your domain2.com links to include this domain1.com cookie, like so:

http://company2.com?_ga=1.182119591.1441315536.1362115890410

Luckily, Google Universal Analytics provides an auto-linking plugin to make this easier. To access the ga methods while using Segment they must be inside an analytics.ready() function, which should appear after your basic Segment snippet, like this:

analytics.ready(function () {
    ga('require', 'linker');
    ga('linker:autoLink', ['company2.com']);
});

To make things easy Segment enables allowLinker by default so all you need to do is run these two functions with any domains you want to track across to in the second call above.

You’ll have to send the clientId as described in the Google Universal Analytics Domain Guide to get this setup.

In order to populate the Site Search report in Google Universal Analytics there are a few you need to do…

  1. When someone searches on your site, the search term they used must be added to the URL query, like this: domain.com?s=coconuts. The key (“s” in this case) can be any letter or string of letters.

  2. In your Segment source destinations catalog open the Google Universal Analytics settings, click to the Advanced Options tab, scroll down and make sure the box is checked for Include the Querystring in Page Views.

  3. Inside Google Universal Analytics, go to the Admin section, then click View Settings for the view you want to add Site Search to. Turn on Site search Tracking and enter the string from #1 into the Query parameter field. In this example it’d look like this:

Google Universal Analytics site search form

Webmaster Tools

When you use Segment to load Google Universal Analytics, the script loads the Google Universal Analytics script. If you use Google Universal Analytics as the verification option in Google Webmaster Tools, you’ll need to switch to the Meta tags verification option instead. This will require you to find the <meta name=google-site-verification" ..> tag in Webmaster Tools and place it in your master HTML template.

Cannonical Urls

Segment tracks the canonical URL and automatically sends it to Google Universal Analytics for you. As long as there is a <meta rel="canonical"> tag on your page, we’ll make sure Google Universal Analytics gets the right canonical URL from it.

Optimize

You can only use this feature in device-mode.

To integrate with the Google Universal Analytics Optimize plugin, insert your Optimize Container ID in your destination settings. Segment adds the plugin when Analytics.js next initializes the Google Universal Analytics snippet.

Make sure your Container ID is spelled correctly and that your Optimize container is ENABLED in Google. If you don’t enable this, your Google Universal Analytics destination silently errors out every time you make a call.

Google recommends that you deploy page hiding to prevent the page from flashing or flickering when an A/B test loads. You must add this code manually, since it needs to load synchronously. Note that you must include the Optimize container ID in the page hiding snippet too.

User Deletion

You can use Segment’s in-app Privacy Tool to send deletion requests using userIds. This deletes a user from your connected raw Data Destinations and forwards a deletion request to Google Universal Analytics. See the Privacy Tools documentation to learn more.

To enable user deletion for Google Universal Analytics:

  1. Navigate to the the User Deletion setting in your Segment Google Universal Analytics destination settings
  2. Authenticate your Google Universal Analytics account using OAuth.

NOTE: Segment supports user deletion for Google Universal Analytics in Universal Analytics and not Classic Analytics. You can send user deletion requests using a userId through the Privacy Tool. This means you must have the User-Id feature enabled in your Google Universal Analytics Property within your Google Universal Analytics dashboard and have Segment sending your Property userIds by enabling the setting Send User-ID to GA.

Troubleshooting

Metrics vs. Dimensions

They both allow you to track custom data properties in Google Universal Analytics. However, Metrics are for event properties with a numeric data type and Dimensions are for event properties with a string data type.

Real-Time Reports

Google Universal Analytics doesn’t process their data in real-time in most of their reports. The easiest way to see if the data is streaming in is to check the Real-Time reports inside Google Universal Analytics.

If you see events in your real-time reports, but they never show up in other reports that is usually due to a filter you have applied. You can see your active filters inside Google Universal Analytics by clicking on Admin then under your View on the right click on Filters.

Self Referrals

This article does a great job of explaining GA self referrals and how to fix them: https://threeventures.com/how-to-fix-self-referrals-in-google-analytics/

Time Frame

Google Universal Analytics’s default reporting time frame is a month ago to yesterday. You’ll need to adjust it from a month ago to today’s date to see today’s already processed events.

HTTPS

If your site uses https://, go to your Google Universal Analytics property settings page and change your Site URL to use the https:// protocol.

Bounce Rates

Using Segment won’t affect your bounce rates in Google Universal Analytics.

If you see your bounce rates drop after installing Segment make sure you don’t have multiple copies of the snippet on your page. Also be sure you’re not calling page more than once when the page loads.

If you call track on page load make sure to set nonInteraction to 1. You can also set all events to be non-interactive by default in Advanced Options. Read more in the non-interaction events docs.

Traffic from Boardman or Segmentio Browser

If you are seeing traffic from Boardman or see Segment as the browser, this is most likely because you are sending calls to Google Universal Analytics from the server side (our AWS servers reside in Boardman, Oregon). In order to prevent the Boardman issue, you would have to manually pass the IP information in the context object from the server.

Here is an example:

Analytics.track(
    user_id: '507f191e810c19729de860ea',
    event: 'Visited Agency Profile',
    properties: { name: 'Ram Estate Agent', favorite_color: 'blue' },
    context: { ip: '127.0.0.1' }
)

To prevent the Segment as the browser issue, you want to manually pass in the user_agent:

Analytics.track(
    user_id: '507f191e810c19729de860ea',
    event: 'Visited Agency Profile',
    properties: { name: 'Ram Estate Agent', favorite_color: 'blue' },
    context: { user_agent: 'some user-agent' }
)

Engage

You can send computed traits and audiences generated using Engage to this destination as a user property. To learn more about Engage, schedule a demo.

For user-property destinations, an identify call is sent to the destination for each user being added and removed. The property name is the snake_cased version of the audience name, with a true/false value to indicate membership. For example, when a user first completes an order in the last 30 days, Engage sends an Identify call with the property order_completed_last_30days: true. When the user no longer satisfies this condition (for example, it’s been more than 30 days since their last order), Engage sets that value to false.

When you first create an audience, Engage sends an Identify call for every user in that audience. Later audience syncs only send updates for users whose membership has changed since the last sync.

Real-time to batch destination sync frequency

Real-time audience syncs to Google Universal Analytics may take six or more hours for the initial sync to complete. Upon completion, a sync frequency of two to three hours is expected.

Settings

Segment lets you change these destination settings from the Segment app without having to touch any code.

Setting Description
Anonymize IP Addresses boolean, defaults to FALSE .

For client side libraries. Read more about anonymizing IP addresses from the Google support documentation.
Use Classic Analytics on Your Site boolean, defaults to FALSE .

Important: When creating your Google Analytics profile, you can choose between Classic and Universal Analytics. After March 2013, new profiles default to Universal, while earlier ones are Classic. An easy test: if you see _gaq.push in your code you’re using Classic, so enable this.
Content Groupings map, defaults to {}.

Enter a property name on the left. Choose the Google Analytics content grouping you want on the right. Google Analytics only accepts numbered content groupings (e.g. contentGrouping3). When you use analytics.page(name, properties) with custom properties, we’ll use the value of the property you designate as the value of the specified content grouping.
Custom Dimensions map, defaults to {}.

Because Google Analytics cannot accept arbitrary data about users or events, when you use analytics.identify(userId, traits) with custom traits or analytics.track('event', properties) with custom properties, you need to map those traits and properties to Google Analytics custom dimensions if you want them to be sent to GA. Enter a trait or property name on the left. Choose the Google Analytics dimension you want on the right. Google Analytics only accepts numbered dimensions (e.g. dimension3). We suggest using user-scoped dimensions for trait mappings and hit-scoped dimensions for properties Contact us if you need help!
string. Only data sent from visitors on this domain will be recorded. By default Google Analytics automatically resolves the domain name, so you should leave this blank unless you know you want otherwise! This option is useful if you need to ignore data from other domains, or explicitly set the domain of your Google Analytics cookie. This is known as Override Domain Name in GA Classic. If you are testing locally, you can set the domain to none. Read more about this setting in our docs.
Remarketing, Display Ads and Demographic Reports. boolean, defaults to FALSE .

Works with both Universal and Classic tracking methods.
Enable Server Side Identify boolean, defaults to FALSE .

If you are sending .identify() calls from your server side libraries or have Segment Cloud Apps that send back .identify() calls with enriched user traits, you can send that data to your GA account via custom dimensions and metrics. Unlike the client side integration which has the luxury of browsers and the global window ga tracker, for server side we will check your traits and your settings for custom dimension/metric mappings and send it with an explicit event.
Enable Enhanced Ecommerce boolean, defaults to FALSE .

If you want more detailed reports on ecommerce, you might want to enable this feature. Read more about it here.
boolean, defaults to FALSE .

Provides more detailed reports on the links clicked on your site. Read more about it in the Google support documentation.
Server Side Identify Event Category string. If you have Enabled Server Side Identify, you can specify the trait you want to look up for setting the event category will be since all custom metrics/dimensions for server side .identify() calls will be sent via an event hit to GA. The default value will be 'All'. For example, if you are sending traits.category, you can put ‘category’ in the setting above and we will send the value of this trait as the event category.
Server Side Identify Event Action string. If you have Enabled Server Side Identify, you can specify what the event action will be since all custom metrics/dimensions for server side .identify() calls will be sent via an event hit to GA. The default value will be 'User Enriched'
Ignored Referrers strings, defaults to .

Add any domains you want to ignore, separated by line breaks. You might use this if you want Google Analytics to ignore certain referral domains (e.g. to prevent your subdomains from showing up as referrers in your analytics). Note: this only works for Classic profiles. Universal profiles can edit their ignored referrers directly inside Google Analytics.
Include the Querystring in Page Views boolean, defaults to FALSE .

The querystring doesn’t usually affect the content of the page in a significant way (like sorting), so we disable this by default.
Custom Metrics map, defaults to {}.

Because Google Analytics cannot accept arbitrary data about users or events, when you use analytics.identify(userId, traits) with custom numerical traits or analytics.track('event', properties) with custom numerical properties, you need to map those traits and properties to Google Analytics custom metrics if you want them to be sent to GA. Enter a trait or property name on the left. Choose the Google Analytics metric you want on the right. Google Analytics only accepts numbered metrics (e.g. metric3). We suggest using user-scoped metrics for trait mappings and hit-scoped metrics for properties. Contact us if you need help!
Mobile Tracking ID string. Google Analytics tracks mobile apps separately, so you’ll want to create a separate Google Analytics mobile app property. Remember to only add a mobile tracking ID if you’re tracking from a mobile library. If you’re tracking from a hybrid app, fill in your website tracking ID instead. Leave it blank if you don’t have a mobile app property.
Name Tracker boolean, defaults to FALSE .

Name the tracker ‘segmentGATracker’. Enable this if you’re working with additional Google Analytics trackers and want to ensure that your Segment tracker has a distinct name. If this is enabled you must prepend this tracker name to any native Google Analytics (except for create) that you call, e.g. ‘segmentGATracker.require(….)’
Add the non-interaction flag to all events boolean, defaults to FALSE .

Adds a nonInteraction: true flag to every non-enhanced ecommerce event tracked to Google Analytics. If you’re seeing unusually low bounce rates this will solve that issue.
Optimize Container ID string. Integrate with Google Analytics Optimize plugin. Please enter your Optimize Container ID
Prefer Anonymous ID for Client ID - Server Side Only boolean, defaults to FALSE .

Enable this setting if you want clientId to always be set as a hash of anonymousId. If no anonymousId is present we will fallback to set the clientId to userId. This setting only applies to server side connections.
Map Traits or Properties to Measurement Protocol Params map, defaults to {}.

If you are using the server side GA integration, you can map your custom traits or properties to known measurement protocol params.
Send Uncaught Exceptions to GA (Mobile) boolean, defaults to FALSE .

This lets you study errors and exceptions in your iOS and Android apps in Google Analytics.
Reset dimensions on Page calls array, defaults to .

If you have an SPA website, and need to reset custom dimensions between page calls, add to this setting all the properties (already mapped as custom dimensions) that need to be reset for each page call.
Sample Rate number, defaults to 100.

Specifies what percentage of users should be tracked. This defaults to 100 (no users are sampled out) but large sites may need to use a lower sample rate to stay within Google Analytics processing limits as seen here. Currently only available in the browser - mobile coming soon.
Send User-ID to GA boolean, defaults to FALSE .

User-ID enables the analysis of groups of sessions across devices, using a unique and persistent ID. This only works with Google Analytics Universal. IMPORTANT: Sending email or other personally identifiable information (PII) violates Google Analytics Terms of Service.
Use Classic Analytics for Your Serverside Tracking boolean, defaults to FALSE .

Important: When creating your Google Analytics profile, you can choose between Classic and Universal Analytics. After March 2013, new profiles default to Universal, while earlier profiles are Classic. An easy test: if you see _gaq.push in your code you’re using Classic, so enable this.
Serverside Tracking ID string. Your Serverside Tracking ID is the UA code for the Google Analytics property you want to send server-side calls to. Leave it blank if you don’t have a server-side client library that you want to send data from. Remember that data tracked from mobile integrations that are not bundled in your app send data to Google Analytics server side, since Segment sends data to them via our own servers.
Set Custom Dimensions & Metrics to the Page boolean, defaults to TRUE .

Google Analytics allows users to either pass custom dimensions / metrics as properties of specific events or as properties for all events on a given page (or the lifetime of the global tracker object). The default Segment behavior is the latter. Any metrics / dimensions that are mapped to a given property will be set to the page and sent as properties of all subsequent events on that page. You can disable this functionality with this setting. If disabled, Segment will only pass custom dimensions / metrics as part of the payload of the event with which they are explicitly associated. Please reference the Google Analytics documentation for more info.
Site Speed Sample Rate number, defaults to 1.

Defines the sample size for Site Speed data collection. If you have a small number of visitors you might want to adjust the sampling to a larger rate for your site speed stats.
Enable Mappings from Top-Level or Context Fields - Server Side Only boolean, defaults to FALSE .

By default, Segment allows mappings from custom traits and properties to Google Analytics custom dimensions and metrics. If you enable this setting, Segment will also send top-level and context object fields mapped in the Custom Dimensions and Custom Metrics settings. When evaluating mappings, Segment will prioritize properties and traits before top-level and context fields. This setting only applies to server side connections.
Track Categorized Pages boolean, defaults to TRUE .

Tracks events to Google Analytics for page method calls that have a category associated with them. E.g. page('Docs', 'Index') translates to Viewed Docs Page.
Website Tracking ID string. Your website’s Tracking ID is in the Tracking Info tab on the Admin Page of Google Analytics. Leave it blank if you don’t have a website property.
Track Named Pages boolean, defaults to TRUE .

Tracks events to Google Analytics for page method calls that have a name associated with them. E.g. page('Signup') translates to Viewed Signup Page.
Send Segment "Product List" Events to GA as "Event" Hits boolean, defaults to FALSE .

By default, Segment sends “Product List Viewed” and “Product List Filtered” ecommerce events to GA as “pageview” hit types. Enable this setting to instead map these two specced Segment track events to GA as “event” hit types.
Use Google AMP Client ID boolean, defaults to FALSE .

Google’s AMP Client ID API lets you uniquely identify users who engage with your content on AMP and non-AMP pages. If you opt-in, Google Analytics will use the user’s AMP Client ID to determine that multiple site events belong to the same user when those users visit AMP pages via a Google viewer. Associating events and users provides features like user counts and session-based metrics. Enabling this feature will affect your reporting. Please carefully reference Google’s documentation for more info before you enable it.
User Deletion string. Sign in to Google Analytics oAuth to enable User Deletion.

This page was last modified: 15 Mar 2024



Get started with Segment

Segment is the easiest way to integrate your websites & mobile apps data to over 300 analytics and growth tools.
or
Create free account