0

analytics.js seems to post all the collected data to https://www.google-analytics.com/collect?v=1 url. Is there any way to change the url and make it post (except the tracking Id) to an url located on my server?

I need this because I want to hide the tracking Id and manually send the collected data through Measurement Protocol server-side. Of course I could write my own JS to do that but that means I have to replicate all the functionality from analytics.js. Tried to find the source code of analytics.js and just tweak it accordingly to my needs but no luck so far.

Viorel
  • 1,420
  • 1
  • 17
  • 27
  • Related (I think): https://stackoverflow.com/questions/29119361/google-analytics-proxy/29130925#29130925 – Eike Pierstorff Jul 03 '17 at 06:34
  • @EikePierstorff related maybe but not enough to be a duplicate. Good find though. – Linda Lawton - DaImTo Jul 03 '17 at 06:39
  • @EikePierstorff I believe that's what I need but I have to try it myself and see if it works. It explains how to overwrite the end point and that's exactly what I'm looking for. – Viorel Jul 03 '17 at 06:43
  • Why do you want to hide the tracking id? – faridghar Jul 04 '17 at 05:23
  • Well some people think it's not secure to expose the tracking id. Since some online companies drive their marketing campaigns based on the stats gathered with GA, they might be right in some respects. I found out about the Measurement Protocol recently and quite surprised that all you need is a tracking id and you can start pushing data :) – Viorel Jul 05 '17 at 06:07

1 Answers1

0

Analytics.js is designed to write to the Google analytics collection endpoint it does not contain the ability to change that end point.

Your best bet will be to copy analytics js and change the end point yourself. Removing the tracking id however will be a bigger change.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449