Tuesday 6 June 2017

node.js request multi line

Google analytics measurement protocol says to use multiple lines for their /batch endpoint:

https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#batch

POST /batch HTTP/1.1
Host: www.google-analytics.com

v=1&tid=UA-XXXXX-Y&cid=555&t=pageview&dp=%2Fhome
v=1&tid=UA-XXXXX-Y&cid=555&t=pageview&dp=%2Fabout
v=1&tid=UA-XXXXX-Y&cid=555&t=pageview&dp=%2Fcontact

How would I do something like that with node.js and request? Here's my current code for /collect

request.post(
      'http://www.google-analytics.com/batch',
      { form: { v:1,tid:'UA-xxxxx-1',cid:event.queryStringParameters.cid,t:'event',ec:'xxx',ea:"xxx", el:"xxx", ev:"xxx", dr:'xxx'} },
      function (error, response, body) {
        done(null,'Check for GA event');
      }
  );



via steve76

No comments:

Post a Comment