Search code examples
javascriptturbolinkscriteo

criteo tags on ajax site


I have an issue with integrating criteo tags into my ajax website. Everything works perfectly when I send my first event.

<script type="text/javascript" src="//static.criteo.net/js/ld/ld.js" async="true"></script>
<script type="text/javascript">
window.criteo_q = window.criteo_q || [];
window.criteo_q.push(event_data);
</script>

But when I try to send another event into criteo without page reload it does not work. Event does not appear in criteo.

<script>
window.criteo_q.push(event_data);
</script>

Any ideas what is wrong?

Demo example: of https://jsfiddle.net/36jq9dLu/156/


Solution

  • You should programmatically reimport the loader every time you want to fire a new event. This won't cause any latency as the loader is cached by the browser, but is necessary as it contains some code useful to reinitialize the criteo_q object. You can add the following lines before every event fire:

    window.criteo_q = undefined;
    script = document.createElement('script');
    script.src = '//static.criteo.net/js/ld/ld.js';
    script.async = 'true'
    document.head.appendChild(script);
    window.criteo_q = window.criteo_q || [];
    

    https://jsfiddle.net/36jq9dLu/199/