0

I have a script from a third party, that I need implemented on my Nuxt site in the Header. What would be the best way to insert a script such as this?

<script id="sleeknoteScript" type="text/javascript">
(function (){
    var sleeknoteScriptTag=document.createElement("script");
    sleeknoteScriptTag.type="text/javascript";
    sleeknoteScriptTag.charset="utf-8";
    sleeknoteScriptTag.src=("//sleeknotecustomerscripts.sleeknote.com/00000.js");
    var s=document.getElementById("sleeknoteScript");
    s.parentNode.insertBefore(sleeknoteScriptTag, s);
})(); </script>
<!-- End of Sleeknote signup and lead generation tool - www.sleeknote.com -->

Usually I would put scripts in Nuxt.config like this.

    script: [
      { src: 'https://unpkg.com/@lottiefiles/[email protected]/dist/lottie-player.js' },
  ]

But this one I don't know.

1 Answer 1

4

You can do it in the same way, just place the script into a javascript file and use the path to that file as a script's src property value in the nuxt.config.js:

script: [
  { src: '/scripts/myScript.js' },
]

The myScript.js would be placed in static/scripts/myScript.js in this case

Sign up to request clarification or add additional context in comments.

1 Comment

thanks. I saw that the script is loaded only if I access the website at / and the find my way to /page where /page is where I need the script. Though if I access /page directly the script is not loaded. Did you experience this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.