Reputation: 117
I understand that i should use hitCallback or eventCallback before redirecting to an external websites to make sure that the tags got fired before redirecting, but im wondering if i should use them too before redirecting to other page within the same website in the same tab?
also i would appreciate if you can confirm if my below code is correct and will gurantee to send that event before redirecting
var review_url = 'https://google.com'
setTimeout(redirect_url, 2000);
var url_redirected = false;
function redirect_url() {
if (!url_redirected) {
url_redirected = true;
if (review_url !== '') {
document.location = review_url;
}
}
}
dataLayer.push({
'marketplace' : marketplaceUpper,
'review-source' : review_source,
'event' : 'CreateReviewClick',
'eventCallback' : function() {
redirect_url();
}
});
Upvotes: 2
Views: 2224
Reputation: 14197
This is the right syntax:
var targetUrl = "https://www.google.com";
window.dataLayer.push({
'marketplace' : marketplaceUpper,
'review-source' : review_source,
'event' : 'CreateReviewClick',
'eventCallback' : function() {
window.location = targetUrl
},
'eventTimeout' : 2000
});
Upvotes: 2