Mobile app version of vmapp.org
Login or Join
Barnes591

: In Universal analytics.js: how do you enable local remote server mode than sends data to your own server as well as to Google's? I'm trying migrate website tracking from old Google Analytics

@Barnes591

Posted in: #GoogleAnalytics #Tracking #UniversalAnalytics

I'm trying migrate website tracking from old Google Analytics script ga.js to new analytics.js.

Currently I have enabled "local remote server mode" to send tracing requests to my server as well. Following code was used to enable this mode on ga.js:

_gaq.push(['_setLocalRemoteServerMode']); (more info).

But I can not find how to enable this feature on new analytics.js. Has anybody solved this already?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Barnes591

1 Comments

Sorted by latest first Latest Oldest Best

 

@Rivera981

There doesn't seem to be an easy function built into analytics.js that I have found, however, there is this code for sending the same data via an XHR request to your server.

ga('create', 'UA-XXXXX-Y', 'auto');

ga(function(tracker) {

// Grab a reference to the default sendHitTask function.
var originalSendHitTask = tracker.get('sendHitTask');

// Modifies sendHitTask to send a copy of the request to a local server after
// sending the normal request to google-analytics.com/collect. tracker.set('sendHitTask', function(model) {
originalSendHitTask(model);
var xhr = new XMLHttpRequest();
xhr.open('POST', '/localhits', true);
xhr.send(model.get('hitPayload'));
});
});

ga('send', 'pageview');

developers.google.com/analytics/devguides/collection/analyticsjs/tasks

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme