# How to send http request to Google Analytics properly?

**URL:** <https://discourse.nodered.org/t/how-to-send-http-request-to-google-analytics-properly/7837>\
**Category:** General\
**Created:** [11 February 2019 16:47 UTC](https://discourse.nodered.org/t/how-to-send-http-request-to-google-analytics-properly/7837 "2019-02-11T16:47:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Traste](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/traste/32/5910_2.png) [@Traste](https://discourse.nodered.org/u/Traste)\
**Post date:** [11 February 2019 16:47 UTC](https://discourse.nodered.org/t/how-to-send-http-request-to-google-analytics-properly/7837/1 "2019-02-11T16:47:22Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [11 February 2019 16:55 UTC](https://discourse.nodered.org/t/how-to-send-http-request-to-google-analytics-properly/7837/2 "2019-02-11T16:55:37Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![Traste](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/traste/32/5910_2.png) [@Traste](https://discourse.nodered.org/u/Traste)\
**Post date:** [11 February 2019 18:15 UTC](https://discourse.nodered.org/t/how-to-send-http-request-to-google-analytics-properly/7837/3 "2019-02-11T18:15:36Z")

</div>

> [@knolleary](#):
>
> ```auto
> 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
> 
> ```

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!
