Search code examples
javagoogle-analyticsgoogle-analytics-api

Google Analytics API comparitive period pervious year


The Google Anlaytics Web Interface has a checkbox where you can compare your data to the previous year. I am running queries in java with the API and was wondering if anyone has noticed the same functionality built into the API?

right now I am running queries like this:

GaData gaData = analytics.data().ga().get(tableID, startDate, endDate, metrics).setDimensions(dimensions).execute();

is there a way to include the previous year automatically or do i have to query that by hand?


Solution

  • Unfortunately, the API doesn't allow any period-over-period comparison. You will have to do this manually.

    Smart way to do this is to get data on daily basis and then simply group them (pivot tables) on any level required: weeks/moths/quarters/years.