0.1.1 • Published 2 years ago

nuxt-tiktok-pixel-tracking-module v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

nuxt-tiktok-pixel-module

npm versionnpm js-standard-style

A NuxtJS module thats injects TikTok Pixel code with custom tracking functionality

Inspired by https://github.com/GuillaumeFerron/nuxt-tiktok-pixel-module#readme

Table of Contents

Requirements

  • npm or yarn
  • NuxtJS
  • NodeJS

Install

$ npm install --save nuxt-tiktok-pixel-module
// or
$ yarn add nuxt-tiktok-pixel-module

Getting Started

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
  },
}

Disabling the pixel (for GDPR)

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})

Module options

List of possible options in the module:

OptionDefaultRequiredDescription
pixelnulltrueThe pixel identifier provided by TikTok business.
disabledfalsefalseDisable the pixel by default when initialized. Can be enabled later through $tiktok.enable().

TikTok pixel instance

The tracking pixel instance is available on all vue component instances as $tiktok. It has the following methods:

MethodPurposeEquivalent to
enable()If you had previously set disabled: true in config, enables the pixel and tracks the current page view$tiktok.init()

License

MIT License