question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AnalyticsReporting v4: Difference between real usage and documentation

See original GitHub issue

Hi, I started to use the analyticsreporting module v4 to batch the data. I write this issue to notify you the difference between real usage and documentation. Following the sample in your documentation to do a batchGet doesn’t work.

analyticsreporting.reports.batchGet( {
  "reportRequests":[
  {
    "viewId":"XXXX",
    "dateRanges":[
      {
        "startDate":"2015-06-15",
        "endDate":"2015-06-30"
      }],
    "metrics":[
      {
        "expression":"ga:sessions"
      }],
    "dimensions": [
      {
        "name":"ga:browser"
      }]
  }]
} ).execute(handleReportingResults)

When I do the call, I have this response message : “Error: Invalid JSON payload received. Unknown name “reportRequests”: Cannot bind query parameter. 'reportRequests' is a message type. Parameters can only be bound to primitive types.” I was investigating and I discover that the object of the request has an empty json property. I put some debugger on v4.js module and I discover that in the batchGet method.

batchGet: function(params, callback) {
    var parameters = {
      options: {
         url: 'https://analyticsreporting.googleapis.com/v4/reports:batchGet',
         method: 'POST'
      },
      params: params,
      requiredParams: [],
      pathParams: [],
      context: self
    };

   return createAPIRequest(parameters, callback);
}

there is no reference related to “resource” (At line 82 of apirequest.js) property which is assign to options.json property (At line 164 of apirequest.js). I have changed the params object of my module without edit v4.js and apirequest.js and it works. This following snippet shows what I changed.

analytics.reports.batchGet({
     "headers": {
          "Content-Type": "application/json"
      },
      "auth": options.auth,
      "resource": {
          "reportRequests": req // req is an array of objects (like in documentation)
      },
}, callback);

Does it make sense ? Is there another way to face this issue ? Any concers let me know.

Thanks! Have fun coding 😃

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:22
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
derappeltcommented, Nov 16, 2017

Simply putting a {resource: YourRequestObj } will do the trick:

{
resource:{
  "reportRequests":[
  {
    "viewId":"XXXX",
    "dateRanges":[
      {
        "startDate":"2015-06-15",
        "endDate":"2015-06-30"
      }],
    "metrics":[
      {
        "expression":"ga:sessions"
      }],
    "dimensions": [
      {
        "name":"ga:browser"
      }]
  }]
}
} )
9reactions
CVariscocommented, Apr 22, 2016

Sorry but I thought that the usage was the same of the browser-based. Anyway, I thought that was good write this issue to notify other devs how to use the batchGet with this version. Thanks man 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Overview | Analytics Reporting API v4 - Google Developers
This document describes the Google Analytics Reporting API v4. For a detailed reference of the API, see the Reference Guide.
Read more >
[UA→GA4] Comparing metrics: Google Analytics 4 vs ...
This article explains the extent to which you can and cannot compare metrics between Universal Analytics and Google Analytics 4. In this article:...
Read more >
Google Analytics Reporting API v4 in R Examples
Calculated metrics on the fly; Much more powerful segments; Quota system for GA360; Caching. Check out more examples on using the API in...
Read more >
Analyticsreporting - googleapis documentation
File. src/apis/analyticsreporting/v4.ts. Description. Analytics Reporting API. Accesses Analytics report data. Example.
Read more >
Google Analytics Reporting API v4 using Python [2021 update]
1. Setup Python 2. Create a New Project and Service Account 3. Install Google API Client in Python
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found