nuxt / scripts

Third-Party Scripts Meets Nuxt Developer Experience.
https://scripts.nuxt.com
MIT License
292 stars 41 forks source link

Script load ever and do not respect a condition for a trigger manual #307

Open Met96 opened 2 hours ago

Met96 commented 2 hours ago

📚 What are you trying to do?

I make the follow code for run the script only in a specific countries, but it will be loaded ever without respect the condition The follow code is inside a composable called in the app.vue of nuxt project.

Can you help me ?

🔍 What have you tried?

const notLoadCookieBanner = ['en-us'] 
const countryLocale = ref('es-es')
const {
    onLoaded,
    load: loadCookie,
  } = useScript<OneTrust>(
    {
      src: 'https://cdn.cookielaw.org/scripttemplates/otSDKStub.js',
      'data-domain-script': '....',
      defer: true,
    },
    {
      trigger: 'manual',
      use() {
        return window.OneTrust
      },
    }
  )

  if (
    countryLocale.value &&
    notLoadCookieBanner.findIndex(
      countryLocaleBanner => countryLocaleBanner === countryLocale.value
    ) === -1
  ) {
    loadCookie()
  }

ℹī¸ Additional context

No response

harlan-zw commented 2 hours ago

Hi, can you please make a minimal reproduction?

You can use the starter here: https://stackblitz.com/edit/nuxt-starter-pkwfkx?file=pages%2Findex.vue

Met96 commented 2 hours ago

I tried it with stackblitz but it's running correctly, so i think it was a problem with Netlify or cache system

harlan-zw commented 1 hour ago

I need a way to replicate it to fix it unfortunately

Met96 commented 1 hour ago

Yeah i know, so next days i'll send you more updates to test it