Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AnalyticsReporting v4: Difference between real usage and documentation #561

Closed
CVarisco opened this issue Apr 22, 2016 · 12 comments
Closed
Assignees

Comments

@CVarisco
Copy link

CVarisco commented Apr 22, 2016

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 :)

@CVarisco
Copy link
Author

Also, the

.execute(handleReportingResults)

method is not defined.
Any concers let me know.

Thanks!
Have fun coding :)

@jmdobry
Copy link
Contributor

jmdobry commented Apr 22, 2016

The documentation you're looking at (with the "JavaScript" label on the tab) is for the browser-based JavaScript library. If there were an example for Node.js, then the tab would be labeled "Node.js". That page doesn't have a Node.js example.

@CVarisco
Copy link
Author

CVarisco commented 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 :)

@tmaslen
Copy link

tmaslen commented Feb 2, 2017

Is there a node example?

Documentation is hard to follow for normal developers. A few simple examples would really help.

Thanks,
/t

@thevinci
Copy link

Please fix. I've spent hours looking for this.

@derappelt
Copy link

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"
      }]
  }]
}
} )

@Adoroam
Copy link

Adoroam commented Nov 29, 2017

can someone please link to this on the analytics samples?

@coderaven
Copy link

Thanks @derappelt! I literally spent hours just to know that what was missing was the "resource" part of the request. The documentation is hard to follow.

@the0ffh
Copy link

the0ffh commented Jan 17, 2018

This might help you out:
(any help with formatting this comment highly appreciated ;) )
`
const theThing = () => {
const {client_email, private_key} = key;
const jwtClient = new google.auth.JWT(
client_email,
null,
private_key,
scopes,
null,
);

jwtClient.authorize((err, tokens) => {
if (err) {
console.log(err);
return;
}

const reportRequests = {
  reportRequests:
    [
      {
        viewId,
        dateRanges:
          [
            {
              endDate: '2018-01-17',
              startDate: '2017-01-17',
            },
          ],
        metrics:
          [
            {
              expression: 'ga:pageViews',
            },
          ],
        dimensions:
          [
            {
              name: 'ga:date',
            },
          ],
      },
    ],
};

analyticsreporting.reports.batchGet({
  auth: jwtClient,
  resource: reportRequests,
}, (error, response) => {
  error && console.log('https://www.soundcloud.com/ambient-occlusion');
  response && console.log(JSON.stringify(response));
});

});
};
`

@KempfCreative
Copy link

Adding my voice to this. I had to look at the source code in order to find this single line in v4.js of analyticsreporting:
* @param {analyticsreporting(v4).GetReportsRequest} params.resource Request body data
https://github.com/google/google-api-nodejs-client/blob/master/src/apis/analyticsreporting/v4.ts#L45

This is not well documented.

@ahscvz
Copy link

ahscvz commented Feb 16, 2018

I've had this problem and my problem is fixed. Thank you @the0ffh

@nicolasdaudin
Copy link

Thank you guys, I've been spending two hours on this and finally found the solution thanks to you, especially @derappelt 👍

yoshi-automation added a commit that referenced this issue May 21, 2020
fixes googleapis/synthtool#560

Source-Author: Jeffrey Rennie <rennie@google.com>
Source-Date: Fri May 15 14:08:01 2020 -0700
Source-Repo: googleapis/synthtool
Source-Sha: 2aa4a1ed43ab867793be8e8044f7e0210fd9dc92
Source-Link: googleapis/synthtool@2aa4a1e
yoshi-automation added a commit that referenced this issue May 22, 2020
fixes googleapis/synthtool#560

Source-Author: Jeffrey Rennie <rennie@google.com>
Source-Date: Fri May 15 14:08:01 2020 -0700
Source-Repo: googleapis/synthtool
Source-Sha: 2aa4a1ed43ab867793be8e8044f7e0210fd9dc92
Source-Link: googleapis/synthtool@2aa4a1e
yoshi-automation added a commit that referenced this issue May 23, 2020
fixes googleapis/synthtool#560

Source-Author: Jeffrey Rennie <rennie@google.com>
Source-Date: Fri May 15 14:08:01 2020 -0700
Source-Repo: googleapis/synthtool
Source-Sha: 2aa4a1ed43ab867793be8e8044f7e0210fd9dc92
Source-Link: googleapis/synthtool@2aa4a1e
yoshi-automation added a commit that referenced this issue May 24, 2020
fixes googleapis/synthtool#560

Source-Author: Jeffrey Rennie <rennie@google.com>
Source-Date: Fri May 15 14:08:01 2020 -0700
Source-Repo: googleapis/synthtool
Source-Sha: 2aa4a1ed43ab867793be8e8044f7e0210fd9dc92
Source-Link: googleapis/synthtool@2aa4a1e
yoshi-automation added a commit that referenced this issue May 24, 2020
fixes googleapis/synthtool#560

Source-Author: Jeffrey Rennie <rennie@google.com>
Source-Date: Fri May 15 14:08:01 2020 -0700
Source-Repo: googleapis/synthtool
Source-Sha: 2aa4a1ed43ab867793be8e8044f7e0210fd9dc92
Source-Link: googleapis/synthtool@2aa4a1e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests