1

I need to add a script to my nuxt/vue website that runs on everypage. It is using an external service, tradedoubler, but can't seem to get it to work. Wondering if anyone can push me in the right direction on how to apply a function like the one below that would be amazing:

<script language="JavaScript">
(function(i,s,o,g,r,a,m){i['TDConversionObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script', 'https://svht.tradedoubler.com/tr_sdk.js', 'tdconv');
</script>
<!-- End TradeDoubler tag-->

All I have is that the following script should be placed after the opening body tag on all landing pages:

<!-- Start TradeDoubler Landing Page Tag Insert on all landing pages to handle first party cookie-->
<script language="JavaScript"> (function(i,s,o,g,r,a,m){i['TDConversionObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script', 'https://svht.tradedoubler.com/tr_sdk.js', 'tdconv'); </script>
<!-- End TradeDoubler tag-->
kissu
  • 40,416
  • 14
  • 65
  • 133
blue4euro4
  • 43
  • 4
  • 1
    Does this answer your question? [How to add a 3rd party script code into Nuxt?](https://stackoverflow.com/questions/67534304/how-to-add-a-3rd-party-script-code-into-nuxt) – kissu Oct 15 '21 at 12:14
  • I can get it to recognise the function using the link you provided but this part of the code `window,document,'script', 'https://svht.tradedoubler.com/tr_sdk.js', 'tdconv'` Doesnt seem to get run. It exists when I view the page elements but not in the page source so no cookies are getting run – blue4euro4 Oct 15 '21 at 15:32
  • You mean it is not available during SSR? You don't have `window` during SSR. And on top of this, a tracking script is to be run on the front-end only AFAIK. Is your script compatible with an SPA? How do you know it is not working? – kissu Oct 15 '21 at 17:32
  • I have it setup like: `{ src: "/js/tradedoubler.js", ssr: false }` with this as a script under the head section in the nuxt.config.js file. The function above is in the tradedoubler.js function. I can call tdcov in the console and it responds as if the function runs and I can see it is present when I inspect the page but no cookies are loaded on the webpage as they should be for some reason. – blue4euro4 Oct 16 '21 at 11:49
  • 1
    The issue is probably coming from the script at this point. Also, what kind of cookies should it generate? Do you have some documentation about this? – kissu Oct 16 '21 at 15:09

0 Answers0