Scripts

Snapchat Pixel

Snapchat Pixel lets you measure the crossdevice impact for your Snapchat ad campaigns.

Nuxt Scripts provides a registry script composable useScriptSnapchatPixel() to easily integrate Snapchat Pixel in your Nuxt app.

Snapchat Pixel

View source

Nuxt Config Setup

The simplest way to load Snapchat Pixel globally in your Nuxt App is to use Nuxt config. Alternatively you can directly use the useScriptSnapchatPixel composable.

export default defineNuxtConfig({
  scripts: {
    registry: {
      snapchatPixel: {
        id: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
      }
    }
  }
})

useScriptSnapchatPixel()

The useScriptSnapchatPixel composable lets you have fine-grain control over when and how Snapchat Pixel is loaded on your site.

const { proxy } = useScriptSnapchatPixel()

proxy.snaptr('track', 'PURCHASE', { price: 1, currency: 'USD' })

Please follow the Registry Scripts guide to learn more about advanced usage.

First-Party Mode

This script supports First-Party Mode which is auto-enabled, routing all traffic through your domain for improved privacy and ad blocker bypass.

export default defineNuxtConfig({
  scripts: {
    registry: {
      snapchatPixel: {
        id: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
      }
    }
  }
})

Example

Using Snapchat Pixel only in production while using the proxy to send events.

<script setup lang="ts">
const { proxy } = useScriptSnapchatPixel()

// noop in development, ssr
// just works in production, client
function handleAction() {
  proxy.snaptr('track', 'PURCHASE', { price: 1, currency: 'USD' })
}
</script>

<template>
  <div>
    <button @click="handleAction">
      Send Event
    </button>
  </div>
</template>
InitObjectPropertiesSchema
12 fields const
user_emailstring

The user's email address (for matching).

ip_addressstring

The user's IP address.

user_phone_numberstring

The user's phone number (for matching).

user_hashed_emailstring

SHA-256 hashed email address.

user_hashed_phone_numberstring

SHA-256 hashed phone number.

firstnamestring

The user's first name.

lastnamestring

The user's last name.

geo_citystring

The user's city.

geo_regionstring

The user's region/state.

geo_postal_codestring

The user's postal/zip code.

geo_countrystring

The user's country code.

agestring

The user's age.

SnapTrPixelOptions
2 fields const
idstring required

Your Snapchat Pixel ID.

trackPageViewboolean

Whether to automatically track a `PAGE_VIEW` event on initialization.