Rich-text Reply

multiple custom events on one page

hexcoder 02-17-15
Accepted Solution

multiple custom events on one page

 

If I need to record multiple custom events on one page, do I need this code only once?

window['optimizely'] = window['optimizely'] || [];

 

And then call one of more custom events like:

window.optimizely.push(["trackEvent", "firstEvent"]);
window.optimizely.push(["trackEvent", "secondEvent"]);

 

Or do I need it each time like:

window['optimizely'] = window['optimizely'] || [];
window.optimizely.push(["trackEvent", "firstEvent"]);
window['optimizely'] = window['optimizely'] || [];
window.optimizely.push(["trackEvent", "secondEvent"]);

 

Thank you.

Level 1

JohnH 02-17-15
 

Re: multiple custom events on one page

window['optimizely'] = window['optimizely'] || []; just ensures that Optimizely is defined globally. You only need this line once and then you can trigger as many custom events as you want. So, your first example is correct (although both would technically work).
Level 2
hexcoder 02-17-15
 

Re: multiple custom events on one page

Thank you for the quick response.

Level 1