Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding lazy loading #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

adding lazy loading #10

wants to merge 1 commit into from

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