Adding tracking codes via Javascript / Jquery

Viewed 24

So I often find myself adding things like google, facebook, and linkedin tracking codes to websites. The way I usually do it is something like this

$('body').on('click','.CLASS’, function (e){
    window.lintrk('track', { conversion_id: ###### });
    // ^ this is what likendin ones usually look like when they get to me

    return true;
});

Now today I got a tracking code that didnt look like the above window.lintrk that I'm used too, instead it came more like this <script async src='https://tag.simpli.fi/sifitag/#####-#####-#####'></script> so my question is can I just slap that into my click function as usual and will it work?

$('body').on('click','.CLASS’, function (e){
    <script async src='https://tag.simpli.fi/sifitag/#####-#####-#####'></script>

    return true;
});
1 Answers

I think that something like this should work, I will remove this answer if I'm not getting tracked results during the week!

$('body').on('click','.CLASS’, function (e){
    $.getScript("https://tag.simpli.fi/sifitag/#####-#####-#####");

    return true;
});

and I hope I'm using the .getScript function correctly here

Related