How to send http request to Google Analytics properly?

Hi,
I'm trying to sent data to Google Analytics via http request. I need to send this type of request using POST:

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

v=1&tid=UA-XXXXX-Y&cid=555&t=event&ec=sensor_name&ea=sensor_state&ev=sensor_value

What type of node should I use? How do I trigger this each time the value changes? Thanks!

Hi @Traste

The HTTP Request node is the one you want to use to send http requests.

You can configure the type of the request (POST) in the node's edit dialog.

If the only part of the url that changes is v=1, then you could then configure the URL field of the node to be:

https://www.google-analytics.com/batch?v={{payload}}&tid=UA-XXXXX-Y&cid=555&t=event&ec=sensor_name&ea=sensor_state&ev=sensor_value

Note how I have replaced the 1 in your example with {{payload}}. That means the node will insert the value of msg.payload into the url before sending the request.

So whenever your value changes, set msg.payload to the value and pass it to the HTTP Request node.

Great answer! It does work flawlessly. Actually, I made a mistake and this is the right URL I had to use:

https://www.google-analytics.com/collect?v=1&t=event&tid=UA-XXXXXXXX-9&cid=f900c728-abf1-446e-bebd-91d3cec91fed&ec=sensor&ea=state&el=entity-name&ev=24

Only thing... taking into account I have around 30 entities and several state changes per minute: could this affect stability and speed when running flows?

Thanks!