Deduping Google Analytics Transaction Hits - customTask
function () {
return function (model) {
var proxyDomain = "https://<yourdomain.com>/collect";
var proxySendHitTask = function () {
function pixel(hitPayload) {
var result = false;
try {
document.createElement("img").src = proxyDomain + "?" + hitPayload, result = true
} catch (e) {}
return result
}
return {
send: function (hitPayload) {
var result;
if (!(result = 2036 >= hitPayload.length && pixel(hitPayload))) {
result = false;
try {
result = navigator.sendBeacon && navigator.sendBeacon(proxyDomain,hitPayload)
} catch (e) {}
}
if (!result) {
var xhr;
try {
window.XMLHttpRequest && "withCredentials" in (xhr = new XMLHttpRequest) && (xhr.open("GET", proxyDomain, true), xhr.setRequestHeader("Content-Type", "text/plain"), xhr.send(hitPayload), result = true)
} catch (e) {}
}
return result || pixel(hitPayload)
}
}
}();
tracker.set("sendHitTask", function (model) {
proxySendHitTask.send(model.get("hitPayload"));
}, true)
}
}