Vitaliy Hayda
Vitaliy Hayda

Reputation: 113

Filter "session duration" in Google Analytics

Some software monitors my website every 2 min 24x7. Their IP is dynamic and comes from all over the world, but session duration is always less than 5 second.

How to add

 filters="ga:timeOnPage > 5" 

 or

 filters="ga:sessionDuration > 5" 

to

  <ga-chart
    title="Sessions (by country)"
    type="GEO"
    metrics="ga:sessions"
    dimensions="ga:country"
    filters="ga:country==Australia">   //this one works just fine
  </ga-chart>

Upvotes: 2

Views: 7626

Answers (1)

Philip Walton
Philip Walton

Reputation: 30431

First of all, I would not recommend using a session duration filter to exclude this traffic. There are a couple reasons why this is a bad idea:

  1. You'll lose any "real" sessions that are less than 5 seconds, which will happen more than you probably realize (see point 2).
  2. Session duration is the delta between the first and last interaction, so when a user comes to your site and leaves without going to any another pages (or interacting with it in some way), the session duration is always 0, even if they were there for several minutes.

Note: check out this article for more details on how time is calculated in Google Analytics

Anyway, I would recommend finding another way to filter out that traffic. Does this service allow you to add query params to the URL or set a custom HTTP header or anything like that?


To actually answer your question though, if you really wanted to filter by session duration you'd have to use the dimension ga:sessionDurationBucket.

Here's what a sample query might look like that excludes sessions whose duration is less than 5 seconds:

{
  "ids": "ga:XXXX",
  "metrics": "ga:sessions",
  "dimensions": "ga:sessionDurationBucket",
  "filters": "ga:sessionDurationBucket!~^[0-4]$"
}

Note: I'm using a regular expression filter here to only include values that aren't 0, 1, 2, 3, or 4.

Upvotes: 8

Related Questions