This article describes how to integrate the OWOX BI Pipeline tracking code into your website using the customTask method. The alternative to this method is to set up tracking with a Custom HTML tag. Both methods are acceptable, however, we recommend using the customTask method described below.

A customTask will be executed each time a hit is sent to Google Analytics. By default, this Task does nothing and can be overwritten for tracking purposes.

How to setup tracking with customTask

  1. In Google Tag Manager, create a user-defined JavaScript variable using the code below. The name of the variable should be set to customTask:

__________105.png

 

function() {
return function(tracker){
tracker.set("dimensionXX", tracker.get("clientId")+"_"+Date.now());

if("undefined"===typeof tracker.get("OWOXBIStreaming")){var f=tracker.get("sendHitTask"),h=function(){function d(c){var a=!1;try{document.createElement("img").src=e(!0)+"?"+c,a=!0}catch(k){}return a}function e(c){var a="https://google-analytics.bi.owox.com/collect";c||(a+="?tid="+encodeURIComponent(tracker.get("trackingId")));return a}return{send:function(c){var a;if(!(a=2036>=c.length&&d(c))){a=!1;try{a=navigator.sendBeacon&&navigator.sendBeacon(e(),
c)}catch(g){}}if(!a){a=!1;var b;try{window.XMLHttpRequest&&"withCredentials"in(b=new XMLHttpRequest)&&(b.open("POST",e(),!0),b.setRequestHeader("Content-Type","text/plain"),b.send(c),a=!0)}catch(g){}}return a||d(c)}}}();tracker.set("sendHitTask",function(d){f(d);h.send(d.get("hitPayload"));tracker.set("OWOXBIStreaming",!0)})}}
}

Please note: Replace the XX in the code with the index of the custom dimension used to send the sessionId.

  1. Add the customTask variable to the Fields to Set block in each Universal Analytics tag for which you want to send the data to Google BigQuery:

__________109.png

 

Using OWOX BI Pipeline to collect hit data only

If your pipeline is configured to collect hit data only, use the following code in the customTask variable:

function() {
    return function(tracker){

    if("undefined"===typeof tracker.get("OWOXBIStreaming")){var f=tracker.get("sendHitTask"),h=function(){function d(c){var a=!1;try{document.createElement("img").src=e(!0)+"?"+c,a=!0}catch(k){}return a}function e(c){var a="https://google-analytics.bi.owox.com/collect";c||(a+="?tid="+encodeURIComponent(tracker.get("trackingId")));return a}return{send:function(c){var a;if(!(a=2036>=c.length&&d(c))){a=!1;try{a=navigator.sendBeacon&&navigator.sendBeacon(e(),
c)}catch(g){}}if(!a){a=!1;var b;try{window.XMLHttpRequest&&"withCredentials"in(b=new XMLHttpRequest)&&(b.open("POST",e(),!0),b.setRequestHeader("Content-Type","text/plain"),b.send(c),a=!0)}catch(g){}}return a||d(c)}}}();tracker.set("sendHitTask",function(d){f(d);h.send(d.get("hitPayload"));tracker.set("OWOXBIStreaming",!0)})}}
} 

Please note:
If you see any discrepancies in Google Analytics after setting up and starting the data collection, please read about the possible discrepancy reasons in this article. 

Sending data to OWOX BI only

In the tags where you need to send data to OWOX BI only, skipping Google Analytics, create a customTask variable using the following code, replacing the "XX" in "dimensionXX" with the index of the custom dimension for collecting sessionid:


 function() {
return function(tracker){
tracker.set("dimensionXX", tracker.get("clientId")+"_"+Date.now());

if("undefined"===typeof tracker.get("OWOXBIStreaming")){var f=tracker.get("sendHitTask"),h=function(){function d(c){var a=!1;try{document.createElement("img").src=e(!0)+"?"+c,a=!0}catch(k){}return a}function e(c){var a="https://google-analytics.bi.owox.com/collect";c||(a+="?tid="+encodeURIComponent(tracker.get("trackingId")));return a}return{send:function(c){var a;if(!(a=2036>=c.length&&d(c))){a=!1;try{a=navigator.sendBeacon&&navigator.sendBeacon(e(),
c)}catch(g){}}if(!a){a=!1;var b;try{window.XMLHttpRequest&&"withCredentials"in(b=new XMLHttpRequest)&&(b.open("POST",e(),!0),b.setRequestHeader("Content-Type","text/plain"),b.send(c),a=!0)}catch(g){}}return a||d(c)}}}();tracker.set("sendHitTask",function(d){h.send(d.get("hitPayload"));tracker.set("OWOXBIStreaming",!0)})}}
}

By setting different customTask variables for different tags, you can regulate the data sources for each event's tag.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.