Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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:

...

Example Request Body:

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

Custom javascript code:

Code Block
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;
    });