Google Analytics tracking using only node.js

Viewed 340

I couldn't find the right answer in google analytics documentation or even here so I suppose my situation is rare. I would like to have a microservice in node.js that will gather information from the website and send it to google analytics. The thing is I don't want to add/import anything related with google analytics on the frontend service because I have multiple clients using that application. Some of them wants that solution (GA) but some of them don't.

Is there any way to send events from frontend to node.js microservice and then push it up to Google Analytics account without frontend knowing about Google Analytics?

Kind regards, Matt

2 Answers

Simplest option would be to have the backend control whether or not to include the GA snippet depending on who the client is, we do this for various third party frontend includes such as GA.

I assume you've got some kind of multi-tenant app so you can have config for the tenant drive whether or not you include the GA snippet and code, you could if you want have a different code as well to segregate the GA data.

You should look into the Measurement protocol The google analytics snippet that normally goes on website sends all its requests to google analytics though this. You could send all your hits this way as well.

POST /collect HTTP/1.1
Host: www.google-analytics.com
v=1&tid=UA-XXXXX-Y&cid=555&t=pageview&dp=%2Fhome
Related