A NuxtJS module thats injects TikTok Pixel code with custom tracking functionality
Inspired by https://github.com/GuillaumeFerron/nuxt-tiktok-pixel-module#readme
- npm or yarn
- NuxtJS
- NodeJS
$ npm install --save nuxt-tiktok-pixel-module
// or
$ yarn add nuxt-tiktok-pixel-module
Add nuxt-tiktok-pixel-module
to modules
section of nuxt.config.js
.
{
modules: [
// Simple usage
'nuxt-tiktok-pixel-module',
// With options
['nuxt-tiktok-pixel-module', {
/* module options */
pixel: 'TIKTOK_PIXEL_ID',
disabled: false
}],
]
}
or even
{
modules: [
'nuxt-tiktok-pixel-module',
],
tiktok: {
/* module options */
pixel: 'TIKTOK_PIXEL_ID',
disabled: false
},
}
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: [
'nuxt-tiktok-pixel-module',
],
tiktok: {
...
disabled: true
},
}
Now, in your component, you can call the following in order to start the pixel and track the current page.
this.$tiktok.enable()
For Custom Tracking, you can call the following:
this.$tiktok.track("AddToCart")
or
this.$tiktok.track("AddToCart",{value:1})
List of possible options in the module:
Option | Default | Required | Description |
---|---|---|---|
pixel | null | true | The pixel identifier provided by TikTok business. |
disabled | false | false | Disable the pixel by default when initialized. Can be enabled later through $tiktok.enable() . |
The tracking pixel instance is available on all vue component instances as $tiktok. It has the following methods:
Method | Purpose | Equivalent to |
---|---|---|
enable() | If you had previously set disabled: true in config, enables the pixel and tracks the current page view |
$tiktok.init() |
[MIT License]