Follow

Using the SPM v1 js with async and without require.js

If you'd like to use the SPM v1 js with async but do not load require.js on your site, you may require some additional code to load the SPM v1 js successfully.

Most notably, you may see an `Uncaught ReferenceError: Sailthru is not defined` using the standard implementation.

Below is some example code that has shown to work in some circumstances.

Note that this code is only an example and should be thoroughly tested before implemented in any production environments.

 

<!-- Begin Sailthru Tag -->
<script type="text/javascript">
    (function () {
        function loadSailthru() {
            var s = document.createElement('script');
            s.type = 'text/javascript';
            s.async = true;
            s.src = 'https://ak.sail-horizon.com/spm/spm.v1.min.js';
            var x = document.getElementsByTagName('script')[0];
            x.parentNode.insertBefore(s, x);
        }
        loadSailthru();
        var oldOnLoad = window.onload;
        window.onload = function () {
            if (typeof oldOnLoad === 'function') {
                oldOnLoad();
            }
            Sailthru.init({
                customerId: '<INSERT_CUTOMER_ID>',
            });
        };
    })();
</script>
<!-- End Sailthru Tag -->
Top