0

Trying to collect stats using the GAMP for nodejs. When I test the debug for issues I constantly get: A value is required for parameter 'v'. Why does this not work?

async function gaCollect(){
  var url = 'https://www.google-analytics.com/debug/collect'
  var body = {v: "1", tid: "UA*******", cid: "***", t: "event", ec: "ws", ea: "get", el: "test", ev: "1"}
  var res = await fetch(url,{method:'POST',body:JSON.stringify(body),headers: {'Content-Type': 'application/json'}});
  var data = await res.json();
  console.log(data.hitParsingResult[0])
}
deadpickle
  • 115
  • 2
  • 15

1 Answers1

0

Your sending the body as Json its not json. The body should be sent in the form of a HTTP query paramaters string.

v=1&tid=UA-XXXXX-Y&cid=555&t=pageview&dp=%2Fhome
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449