Brian
Brian

Reputation: 14836

How to get recency from google analytics

I track the visitor of my web app through google analytics and I'm interested in the "Recency" (found under "Behaviour"). If I log-in to Google Analytics it's easy to download a CSV file with the recency data for a given period of time, but I was wondering if there's a way to get the recency through the Google Analytics API so I can automate the process of generating the reports.

Upvotes: 1

Views: 136

Answers (1)

Matt
Matt

Reputation: 5168

First a suggestion: try out your query in the query explorer to get a sense of what the API is capable of. Currently it uses the V3 API but I would recommend starting a new project with Analytics Reporting API V4.

Answer: Query the API for the dimension ga:sessionCount.

The Analytics Reporting API V4 makes it easy to request ga:sessionCount in the desired buckets. for example I want to see users who have been to the site between 1, 10, 100, 200:

POST https://analyticsreporting.googleapis.com/v4/reports:batchGet
{
  "reportRequests":
  [
    {
      "viewId": "XXXX",
      "metrics": [
        {"expression": "ga:sessions"},
        {"expression": "ga:pageviews"}
      ],
      "dimensions": [
        {
          "name": "ga:sessionCount",
          "histogramBuckets": ["1","10","100","200","400"]
        }
      ],
      "orderBys": [
        {
          "fieldName": "ga:sessionCount",
          "orderType": "HISTOGRAM_BUCKET"
        }
      ]
    }
  ]
}

Gettings started with the API

Look at the Samples page of the documentation to get an understanding how how the various client libraries frame their requests, and take a stab at one of the quick start guides. Come back here if you get stuck or have a question.

Upvotes: 0

Related Questions