Skip to content

Comments

adding lazy loading#10

Open
s00d wants to merge 1 commit intozadigetvoltaire:mainfrom
s00d:patch-1
Open

adding lazy loading#10
s00d wants to merge 1 commit intozadigetvoltaire:mainfrom
s00d:patch-1

Conversation

@s00d
Copy link

@s00d s00d commented Jul 11, 2023

adding lazy loading, after add you can use custom gtm plugin, example to change the tag after loading the module

// pugins/gtm.ts
import {defineNuxtPlugin, useRouter} from 'nuxt/app'
import { createGtm, type VueGtmUseOptions } from '@gtm-support/vue-gtm'

export default defineNuxtPlugin((nuxt) => {
  if (process.client) {
    const options = nuxt.$config.public.gtm

    const router = useRouter()

    const pluginOptions: VueGtmUseOptions = {
      ...options,
      vueRouter: options.enableRouterSync && router ? router as VueGtmUseOptions['vueRouter'] : undefined,
      id: 'GTM-YYYYYY'
    }

    nuxt.vueApp.use(createGtm(pluginOptions))
  }
})

adding lazy loading, after add you can use custom gtm plugin, example

```ts
import {defineNuxtPlugin, useRouter} from 'nuxt/app'
import { createGtm, type VueGtmUseOptions } from '@gtm-support/vue-gtm'

export default defineNuxtPlugin((nuxt) => {
  if (process.client) {
    const options = nuxt.$config.public.gtm

    const router = useRouter()

    const pluginOptions: VueGtmUseOptions = {
      ...options,
      vueRouter: options.enableRouterSync && router ? router as VueGtmUseOptions['vueRouter'] : undefined,
      id: 'GTM-YYYYYY'
    }

    nuxt.vueApp.use(createGtm(pluginOptions))
  }
})

```
@s00d s00d changed the title Update plugin.ts adding lazy loading Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant