1

Google Analytics API documentation shows that, for fetching the lifetime values, the date ranges should not be specified. But when I make such a request (without date range), it returns empty dimension and metrics result. But when I use date range, it returns dimension and metrics values for that date range.

The following is an excerpt from the API documentation :

Date ranges should not be specified for cohorts or Lifetime value requests.

For example, if I make the request without date range, as follows:

{
 "reportRequests": [
  {
   "viewId": "XXXXXXXXX",
   "dimensions": [
    {
     "name": "ga:date"
    },
    {
     "name": "ga:eventLabel"
    }
   ],
   "metrics": [
    {
     "expression": "ga:totalEvents"
    }
   ]
  }
 ]
}

I get the following response:

{
 "reports": [
  {
   "columnHeader": {
    "dimensions": [
     "ga:date",
     "ga:eventLabel"
    ],
    "metricHeader": {
     "metricHeaderEntries": [
      {
       "name": "ga:totalEvents",
       "type": "INTEGER"
      }
     ]
    }
   },
   "data": {
    "totals": [
     {
      "values": [
       "0"
      ]
     }
    ]
   }
  }
 ]
}

However, if I include the date range,

{
 "reportRequests": [
  {
   "viewId": "XXXXXXXX",
   "dimensions": [
    {
     "name": "ga:date"
    },
    {
     "name": "ga:eventLabel"
    }
   ],
   "metrics": [
    {
     "expression": "ga:totalEvents"
    }
   ],
   "dateRanges": [
    {
     "startDate": "2016-01-01",
     "endDate": "2016-04-30"
    }
   ]
  }
 ]
}

I get the following response:

{
 "reports": [
  {
   "columnHeader": {
    "dimensions": [
     "ga:date",
     "ga:eventLabel"
    ],
    "metricHeader": {
     "metricHeaderEntries": [
      {
       "name": "ga:totalEvents",
       "type": "INTEGER"
      }
     ]
    }
   },
   "data": {
    "rows": [
     {
      "dimensions": [
       "20160412",
       "http://mytestblog.com/"
      ],
      "metrics": [
       {
        "values": [
         "1"
        ]
       }
      ]
     },
     {
      "dimensions": [
       "20160412",
       "http://mytestblog.com/2016/04/first-post.html"
      ],
      "metrics": [
       {
        "values": [
         "3"
        ]
       }
      ]
     },
     {
      "dimensions": [
       "20160419",
       "http://mytestblog.com/"
      ],
      "metrics": [
       {
        "values": [
         "4"
        ]
       }
      ]
     },
     {
      "dimensions": [
       "20160419",
       "http://mytestblog.com/2016/04/fourth.html"
      ],
      "metrics": [
       {
        "values": [
         "13"
        ]
       }
      ]
     }
    ],
    "totals": [
     {
      "values": [
       "21"
      ]
     }
    ],
    "rowCount": 4,
    "minimums": [
     {
      "values": [
       "1"
      ]
     }
    ],
    "maximums": [
     {
      "values": [
       "13"
      ]
     }
    ]
   }
  }
 ]
}

Why is it that, even though specified in the documentation, I have to specify date range in the ReportRequest to get the values? Am I misunderstanding the meaning of Lifetime values here?

Kenpachi
  • 511
  • 8
  • 20

1 Answers1

0

The reportRequest object should have either a value for dateRanges or a definition value for cohortGroup. When you omit both the requests assumes the default values for a startDate of 7daysAgo and an endDate of yesterday.

The correct interpretation of the docs is that the reportRequest should not have a dateRange defined for cohort and LTV requests. But in order to make a cohort or lifetime value request you must add a cohort definition. For Lifetime value requests the cohort definition should have a specific dateRange in addition to the lifetimeValue field set to true:

POST https://analyticsreporting.googleapis.com/v4/reports:batchGet
{
    "reportRequests": [
    {
        "viewId": "XXXX",
        "dimensions": [
            {"name": "ga:cohort" },
            {"name": "ga:cohortNthWeek" }],
        "metrics": [
            {"expression": "ga:cohortTotalUsersWithLifetimeCriteria"},
            {"expression": "ga:cohortRevenuePerUser"}
        ],
        "cohortGroup": {
            "cohorts": [{
                "name": "cohort 1",
                "type": "FIRST_VISIT_DATE",
                "dateRange": {
                    "startDate": "2015-08-01",
                    "endDate": "2015-09-01"
                }
            },
            {
                "name": "cohort 2",
                "type": "FIRST_VISIT_DATE",
                "dateRange": {
                    "startDate": "2015-07-01",
                    "end_date": "2015-08-01"
                }
            }],
           "lifetimeValue": True
        }
    }]
  }
Matt
  • 4,507
  • 2
  • 23
  • 46
  • 1
    Thanks for the comment @Matt. It seems there is [Lifetime Value Report](https://support.google.com/analytics/answer/6182550) separate from CohortGroup. This Report is only available for [App Views](https://support.google.com/analytics/answer/2649553#WebVersusAppViews). Also, by default, without specifying the date range, it seems the data is fetched for the current month (atleast for the webview) – Kenpachi May 03 '16 at 19:39
  • To clarify, in order to make a life time value request you must define a `cohortGroup` and set the `lifetimeValue` field to **True**. – Matt May 03 '16 at 22:42