: 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
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?
More posts by @Barnes591
1 Comments
Sorted by latest first Latest Oldest Best
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
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.