A Nuxt 3 module thats injects Tiktok Pixel (tiktok Pixel)
- npm or yarn
- NuxtJS
- NodeJS
$ npm install --save nuxt3-tiktok-pixel
// or
$ yarn add nuxt3-tiktok-pixelAdd nuxt3-tiktok-pixel to modules section of nuxt.config.js.
{
modules: [
'nuxt3-tiktok-pixel',
],
tiktok: {
pixelId: 'PIXEL_KEY',
track: "ViewContent",
autoViewContent: true,
debug: true,
}
}By default, the module won't trigger any tracking event on route change. To enable this behaviour, you must specify the autoPageView option and set to true in the Nuxt module options.
{
modules: [
'nuxt3-tiktok-pixel',
],
tiktok: {
/* module options */
pixelId: 'PIXEL_KEY',
autoPageView: true
},
}If you'd like to install the pixel disabled, and enable it later after the user has consented to its use, you can do so by setting disabled: true in the pixel configuration:
{
modules: [
'nuxt3-tiktok-pixel',
],
tiktok: {
...
disabled: true
},
}Now, in your component, you can call the following in order to start the pixel and track the current page.
this.$tt.enable()The pixel can be disabled again later on by using the .disable() method.