How Sessions are calculated in Analytics

This information in this article only applies to web tracking. The calculations don’t apply if you’re collecting data using a Google Analytics SDK for any mobile OS. Also note that the images illustrating the examples only refer to Classic Analytics methods, and not to Universal Analytics.

The concept of a session in Google Analytics is important to understand because many features, reports, and metrics depend on how Analytics calculates sessions.

A session is a group of interactions that take place on your website within a given time frame. For example a single session can contain multiple pageviews, events, social interactions, custom variables, and ecommerce transactions. Learn more about the different request types in Google Analytics.

You can think of a session as the container for the actions a user takes on your site.

Many interactions can happen within one visit.

A single user can open multiple sessions. Those sessions can occur on the same day, or over several days, weeks, or months. As soon as one session ends, there is then an opportunity to start a new session. There are two methods by which a session ends:

  • Time-based expiry (including end of day):
    • After 30 minutes of inactivity
    • At midnight
  • Campaign change:
    • If a user arrives via one campaign, leaves, and then comes back via a different campaign.

How long does a session last?

By default, a session lasts 30 minutes, but you can adjust this length so a session lasts a few seconds or several hours. A session can be as short as a few seconds or as long as several hours. But by default, session last 30 minutes. See how Google Analytics defines bounce rate and session length.

When a user, say Bob, arrives on your site, Analytics starts counting from that moment. If 30 minutes pass without any kind of interaction from Bob, the session ends. However, every time Bob interacts with an element (like an event, social interaction, or opens a new page), Google Analytics resets the expiration time by adding on an additional 30 minutes from the time of that interaction.

Example

Assume Bob interacts with your website at the following intervals:

A series of standard interactions and the visit expiry.

After event 2, the session expiry is set to 14:34

When Bob first arrives on your site, the session is set to expire at 14:31. As Bob continues through your site, viewing pages and triggering events, each of these additional requests moves the expiry ahead 30 minutes.

What happens if during a session to my site, Bob leaves open a page while he takes a 31-minute lunch break, then returns to continue browsing the site?

In this scenario, the first session that was opened when Bob arrived on the site ends 30 minutes into his lunch break. When he returns from lunch and continues browsing the website, then Analytics sets a new 30-minute expiry, and a new session begins.

A new visit starts if a user doesn

Bob was half way through a product purchase when he left your site and went for lunch. He later returned to complete the transaction. The landing page of the new session is the add-to-cart page.

What happens if Bob leaves open a page on my site, but only takes a 29-minute lunch break before he continues browsing?

When Bob returns, the session that was open continues from the last page he was viewing on your site (provided he doesn’t return via another campaign source -- a bit more about this below). As far as Analytics is concerned, he never left your website.

If a user continuous interacts with content and only pauses within the specified time limit, the visit keeps going.

Bob was half way through a product purchase when he left your site and went for lunch. The difference this time is that because he returned in under 30 minutes, the old session remains open. It’s worth noting that his time on page for pageview 2 (product) is 29 minutes, since time on page is calculated as the difference between the initiation of successive pageviews: pageview 3 - pageview 2 (14:31-14:02 = 00:29).

End of day expiry

Bob opens your website at 11:50 PM on the 14th of August and leaves your website at 12:10 AM on the 15th of August.

The first session ends at 11:59:59 PM on the 14th of August, and the second session begins at 12:00 AM on the 15th of August.

End of day is determined by your view timezone settings.

Campaign change expiry

Every time a user's campaign source changes, Google Analytics opens a new session. It’s important to point out that even if an existing session is still open (that is, less than 30 mins have elapsed), if the campaign source changes mid-session the first session is closed and a new session is opened.

Let’s say Bob opens your website in the following order:

Two separate visits, with two unrelated interactions.

Analytics stores campaign source information. Each time the value of the campaign is updated, Analytics opens a new session. In the example above, Bob first arrives at your website via the Google organic keyword Red Widgets, then later returns via the Google paid keyword Blue Widgets.

Each search term updates the campaign, so each keyword corresponds to a new session.

What causes updates to the campaign?

Generally speaking, the campaign updates anytime the user arrives at your site via a search engine, referring website, or campaign tagged URL. Direct traffic, however, never updates or replaces an existing campaign source such as a search engine, referring site, or campaign-tagged information.

AdWords autotagging

In the case of AdWords autotagging, each click generates a unique campaign value (a gclid value). Because each click has its own gclid value, each click is treated as a separate campaign and creates a new session.

Campaign Tags

We generally don’t recommend manually tagging your AdWords campaigns (see benefits of autotagging), but let’s assume that you manually tagged your AdWords campaigns with a destination URL like this:

http://www.example.com/?utm_source=google&utm_medium=cpc&utm_campaign=camp1&utm_term=keyword&utm_content=content

Bob clicks your ad, which registers a new session for the first click. However, unlike autotagging, where multiple clicks on the ad can generate multiple corresponding sessions, manually tagged campaign parameter values remain the same for every click so the campaign isn’t updated for each click. This makes it possible to have multiple ad clicks and only one session.

If you advertise on third-party ad networks and use manual campaign tags, you should be aware that each click from a single user on those networks might not generate a corresponding session (if additional clicks happen within the 30-minute time frame). This is a common cause of data discrepancies between Google Analytics and other product reporting.

Referring sources -- a slight exception

Each new campaign source should generate a corresponding new session, but referrals are treated differently from search engine traffic (organic, cpc), and campaign-tagged traffic. A session from a referring source within the 30-minute session window doesn't update the campaign.

Let’s assume Bob goes to your site via the following sequence:

Sometimes one visit can have multiple entrances.

If Bob returns to your site via a referring source, Analytics does NOT update the campaign or open a new session.

Why is this campaign source treated uniquely?

There are a few reasons why referrals are treated differently:

Reason 1

Let’s say your website has a 3rd party payment gateway:

Your site can include a visit to a 3rd party site that doesn

Assume the third-party payment gateway (paymentdomain.com) doesn’t allow cross-domain tracking. To prevent Analytics from losing your original campaign information (organic keyword Red Widgets) and overriding it with referral information from the third-party payment gateway (paymentdomain.com), Analytics ignores referral sources when a session is still open.

The caveat is that if users spend longer than 30 mins on the payment gateway pages, Analytics updates the campaign with referral information from paymentdomain.com when the user returns to the thank-you page on yourwebsite.com

Reason 2

On some occasions despite your best efforts it’s possible that you miss tagging a page, or the Google Analytics tracking code doesn’t function on a subset of pages. In these instances where some pages are tagged and some are not and without the special treatment of referral traffic Google Analytics would override existing campaign information “Red Widgets” with self referral information from yourwebsite.com.

Broken tracking code can lead to self-referrals.

Because Google Analytics does not update the campaign when the existing session is still open, your original campaign data Red Widgets is preserved up until the thank-you page, and your conversions can be traced back to this keyword.

Direct traffic

Finally, a quick word about direct traffic in Analytics. Direct as a campaign source never overrides an existing known campaign source like a search engine, referral, or campaign source would.

Direct traffic that interacts with your content within the 30-minute session window have the same effect as leaving your website for less than 30 minutes. The existing session opens and continues from where it left off.

Note that the Multi-Channel Funnel reports handle direct traffic differently than other Google Analytics reports.

Terms

Bounce rate: Can be defined as a single interaction with your website followed by an exit. Some types of interactions, like Events, allow you to specify if the request should be excluded from the bounce rate calculation. Refer to the Developer Guides for Events in Universal Analytics (analytics.js) and Classic Analytics (ga.js) to see how to implement this.

Session length: The default session length is 30 minutes, but you can change this by adjusting the session or campaign timeout handling if you're using Universal Analytics (analytics.js). If you're using Classic Analytics (ga.js) refer to our Developer Guide on how to reduce or extende the timeout length method in ga.js.