This document provides an overview of segments in Google Analytics.
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.](https://developers.google.cn/static/analytics/images/platform/segments/ga-user-model.png?authuser=4)
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 hierarchy
based on whether the node is excluded from a segment, included in a
segment, matches a condition, or matches a step in a sequence.](https://developers.google.cn/static/analytics/images/platform/segments/segments-legend.png?authuser=4)
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.](https://developers.google.cn/static/analytics/images/platform/segments/3-users.png?authuser=4)
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.](https://developers.google.cn/static/analytics/images/platform/segments/4-sessions.png?authuser=4)
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.](https://developers.google.cn/static/analytics/images/platform/segments/5-users-perhit.png?authuser=4)
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.](https://developers.google.cn/static/analytics/images/platform/segments/6-users-persession.png?authuser=4)
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.](https://developers.google.cn/static/analytics/images/platform/segments/7-users-peruser.png?authuser=4)
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.](https://developers.google.cn/static/analytics/images/platform/segments/8-sessions-perhit.png?authuser=4)
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.](https://developers.google.cn/static/analytics/images/platform/segments/9-sessions-persession.png?authuser=4)
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 condition.](https://developers.google.cn/static/analytics/images/platform/segments/exclude-sessions.png?authuser=4)
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.](https://developers.google.cn/static/analytics/images/platform/segments/10-combine-and.png?authuser=4)
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 multiple 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.](https://developers.google.cn/static/analytics/images/platform/segments/11-combine-or.png?authuser=4)
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.](https://developers.google.cn/static/analytics/images/platform/segments/12-immediate-sequence.png?authuser=4)
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.](https://developers.google.cn/static/analytics/images/platform/segments/13-followed-sequence.png?authuser=4)
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.