How to delay execution of the Tracking Code

If you have not installed your Tracking Code yet, please follow the instructions here, or view our Tracking Code video walkthrough here

To delay running the Tracking Code, add the following script to the Tracking Code page:

var ctmAlreadyRun = false;

window.CTMSourceEvent = function(event) {
if (ctmAlreadyRun) { return; }
if (event.state != 'before') { return; }
setTimeout(function() {
__ctm.main.runNow()
ctmAlreadyRun = true;
},1000);
// console.log(event);
}

You can also add the following if you need the Tracking Code to run after some interaction with the page, such as clicking a button to show a number:

__ctm.main.runNow(changedElement)

Changed element is the button click or object that needs to be interacted with to fire the code again.

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Article is closed for comments.