Click here to see your recently viewed pages and most viewed pages.
Hide

Segments - Feature Reference

This document provides an overview of segments in Google Analytics.

  1. Overview
  2. User Model
  1. Segments Examples
  2. Conditions
    1. Dimensions
      1. Users
      2. Sessions
    2. Metrics
      1. Users
      2. Sessions
  3. Excluding Conditions
  4. Combining Conditions
    1. AND Operator
    2. OR Operator
  5. Sequences
  6. Combining Users and Sessions

  7. Next Steps
More

Overview

Segments allow you to select users and sessions to answer questions that are important to your business. For example, users that have completed at least 2 transactions with a lifetime revenue of over $1,000, or users who visited first on a mobile device followed by a desktop browser.

This document will familiarize you with the Google Analytics user model and the fundamentals of creating segments.

Google Analytics User Model

Reviewing the Google Analytics User Model first will help you conceptualize how segments work.

There are three major components to the Google Analytics user model:

  • Users — At the basic level you have users.
  • Sessions — A user arrives at and interacts with your property. All of these user interactions are grouped into what is referred to as a session.
  • Hit — During a session the user interacts with your property. Each interaction is referred to as a Hit. Example hits include pageviews, events, transactions, etc.

A single user can have multiple sessions, and each session can have multiple hits. Visually, this is represented below:

A hierarchy representing the Google Analytics user model. The parent
         node is a user, its child nodes represent sessions, and each session
         has one or more nodes representing hits.
Figure 1: Google Analytics user model

Once you understand how users are modeled in Google Analytics, the next step is to look at how to create segments.

Segments Examples

To create a segment you define the condition and the dimensions and metrics values you’re interested.

For each example below there is a segment description, the equivalent API Syntax for the segment parameter, and a user model representation.

The legend for the model representation is:

A legend that defines the style for each node in a user model hiearchy
         based on whether the node is excluded from a segment, included in a
         segment, matches a condition, or matches a step in a sequence.
Figure 2: Node definitions for example segments.

The examples below illustrate the following:

Conditions

Use conditions to select users or sessions based on dimensions and metrics values.

Dimensions

Select users or sessions based on dimension values.

Users

Select users who came from Canada.
users::condition::ga:country==Canada

Out of 3 users, the first user and all their sessions are included in
         the segment due to two matching session-level conditions. The sessions
         of the other 2 users are excluded.
Figure 3: A matching user condition.

Sessions

Select sessions that came from Canada.
sessions::condition::ga:country==Canada

Out of 3 users, the second user and all their sessions are included in
         the segment due to two matching session-level conditions. The sessions
         of the other 2 users are excluded.
Figure 4: A matching session condition.

Metrics

Select users or sessions based on single or totaled metric values.

Users

Select users whose total revenue in a single transaction was greater than $100.
users::condition::perHit::ga:transactionRevenue>100

Out of 3 users, the second user and all their sessions are included in
         the segment due to a single matching hit-level condition. The sessions
         of the other 2 users are excluded.
Figure 5: A matching per hit, user condition.

Select users whose total revenue across all transactions within a session was greater than $100.
users::condition::perSession::ga:transactionRevenue>100

Out of 3 users, the 1st and 2nd user and all their sessions are
         included in the segment due to a single matching hit-level condition.
         The sessions of the 3rd user are excluded.
Figure 6: A matching per session, user condition.

Select users whose total revenue across all transactions in the date range was greater than $100.
users::condition::perUser::ga:transactionRevenue>100

Out of 3 users, all 3 and their sessions are included in
         the segment due to a matching user-level condition.
Figure 7: A matching per user, user condition.

By default, when selecting users, metric values will be totaled at the user level. So you can simplify this to:
users::condition::ga:transactionRevenue>100

Sessions

Select sessions where total revenue in a single transaction was greater than $100.
sessions::condition::perHit::ga:transactionRevenue>100

Out of 3 users, only the 2nd user and a single session is
         included in the segment due to a single matching hit-level condition.
         The other 2 users and their sessions are excluded.
Figure 8: A matching per hit, session condition.

Select sessions where total revenue across all transactions in a session was greater than $100.
sessions::condition::perSession::ga:transactionRevenue>100

Out of 3 users, the 1st and 2nd user and a single session per each is
         included in the segment due to a single matching session-level
         condition. The 3rd user and its sessions are excluded.
Figure 9: A matching per session, session condition.

By default, when selecting sessions, metric values will be totaled at the session level. So you can simplify this to:
sessions::condition::ga:transactionRevenue>100

Excluding Conditions

NOT Operator

Use the ! character to negate a condition and exclude the sessions matching that condition.

Exclude sessions where the exit page exactly matches the root page path.
sessions::condition::!ga:exitPagePath==/

Out of three users, the first user and their sessions are included.
         The second user has one session included and one session excluded
         due to a matching session-level condition. The third user has one
         session excluded also due to a matching session-level condtion.
Session Exclusion: Excluding matching sessions.

Combining Conditions

AND Operator

Use the ; character to combine conditions using the AND operator.

Select users who came from Canada AND whose total revenue across all transactions in the date range was greater than $100. users::condition::ga:country==Canada;users::condition::perUser::ga:transactionRevenue>100

Out of 3 users, the 1st user and all their sessions are
         included in the segment due to a matching user and session-level
         condition. The other 2 users and their sessions are excluded.
Figure 10: Matching multiple conditions using the AND operator.

Since these are both user conditions, you can simplify this to:
users::condition::ga:country==Canada;ga:transactionRevenue>100

OR Operator

Use the , character to combine filters using the OR operator.

Select users who came from Canada OR who came from Mexico.
users::condition::ga:country==Canada,users::condition::ga:country==Mexico

Out of 3 users, the 1st and 2nd user and all their sessions are
         included in the segment due to multple matching session-level
         conditions for the 1st user and for a single matching session-level
         condition for the 2nd user. The remaining  user and their sessions are
         excluded.
Figure 11: Matching multiple conditions using the OR operator.

Since these are both user conditions, you can simplify to:
users::condition::ga:country==Canada,ga:country==Mexico

Since the condition dimensions are the same, you can use a regular expression to simplify to:
users::condition::ga:country=~Canada|Mexico

Sequences

Use sequences to select users or sessions based on sequential conditions.

Select users who visited on mobile immediately followed by a visit on desktop.
users::sequence::ga:deviceCategory==mobile;–>ga:deviceCategory==desktop

Out of 3 users, the 2nd user and all their sessions are included in the
         segment due to a matching session-level sequence where the steps
         immediately followed each other across sessions. The remaining user and
         their sessions are excluded.
Figure 12: A matching sequence where steps are immediately followed by each other.

Select users who visited on mobile followed by a visit on desktop.
users::sequence::ga:deviceCategory==mobile;–>>ga:deviceCategory==desktop

Out of 3 users, the 1st and 2nd user and all their sessions are
         included in the segment due to matching session-level sequences. The
         remaining user and their sessions are excluded.
Figure 13: A matching sequence where steps are followed by each other.

Combining Users and Sessions

You can select users and sessions to create a segment. Users will be selected first and sessions will be selected from the subset of users.

Select sessions where total revenue in a single transaction was greater than $100 from users who visited on mobile followed by a visit on desktop.
users::sequence::ga:deviceCategory==mobile;->>ga:deviceCategory==desktop;sessions::condition::perHit::ga:transactionRevenue>100

Next Steps

Review the Segments Dev Guide for complete details on the segments syntax and how to query segments in the Core Reporting API.