Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Documentation page from Google about migrating to “Google Analytics Data API v1” can be found here: https://developers.google.com/analytics/devguides/migration/api/reporting-ua-to-ga4#reporting-api-v4

A REST API application definition example can be found here:

After importing the definition adjust Property ID in the URL, Request body and Client ID and Client secret and the import should be working.

Application screenshots, example Request body and necessary Custom javascript code can be found below:

Screenshot 2023-12-28 at 15.15.42.pngScreenshot 2023-12-28 at 15.16.15.png

Example Request Body:

{
  "dateRanges":[
  {
    "startDate":"2015-08-14",
    "endDate":"today"
  }],
  "dimensions":[
  {
    "name":"date"
  },
  {
    "name":"eventName"
  }],
  "metrics":[
    {
      "name":"sessions"
    },
    {
      "name":"screenPageViews"
    }
  ],
  "offset": "{{offset}}",
  "limit": "{{limit}}"
}

Custom javascript code:

function formatDate(s) {
    return s.substr(0,4)+'-'+s.substr(4,2)+'-'+s.substr(6,2);
    }
     
    return _.map(doc.rows, function(row) {
    var rowdoc = {};
    for (var i = 0; i < doc.dimensionHeaders.length; i++) {
    var name = doc.dimensionHeaders[i].name;
    rowdoc[name] = name == 'date' ? formatDate(row.dimensionValues[i].value) : row.dimensionValues[i].value;
    }
    
    for (var i = 0; i < doc.metricHeaders.length; i++) {
        var metric_name = doc.metricHeaders[i].name;
        rowdoc[metric_name] =  row.metricValues[i].value;
        }
    
    return rowdoc;
    });
  • No labels