Socket
Socket
Sign inDemoInstall

@dansmaculotte/nuxt-segment

Package Overview
Dependencies
1
Maintainers
3
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @dansmaculotte/nuxt-segment

Nuxt.js module for Segment Analytics.js


Version published
Maintainers
3
Install size
16.3 kB
Created

Changelog

Source

0.2.13 (2022-03-11)

Bug Fixes

  • shouldUseRouter() always return true (0f27f61)
  • typo (26bcb88)

Readme

Source

nuxt-segment

npm version npm downloads Dependencies Standard JS

Nuxt.js module for Segment Analytics

This module uses vue-segment to add Segment Analytics to a Nuxt.js app.

📖 Release Notes

Setup

  • Add @dansmaculotte/nuxt-segment dependency using yarn or npm to your project
  • Add @dansmaculotte/nuxt-segment to modules section of nuxt.config.js
  1. Configure it:
{
  modules: [
    // Simple usage
    '@dansmaculotte/nuxt-segment',

    // With options
    [
      '@dansmaculotte/nuxt-segment',
      { /* module options */ }
    ],
  ],

  // Or with global options
  segment: {
    writeKey: '',
    disabled: false,
    useRouter: true
  }

  // Or with publicRuntimeConfig

  publicRuntimeConfig: {
    SEGMENT_WRITE_KEY: process.env.SEGMENT_WRITE_KEY_FROM_SERVER || '',
    SEGMENT_DISABLED: process.env.SEGMENT_DISBLED_FROM_SERVER || false,
    SEGMENT_USE_ROUTER: process.env.SEGMENT_USE_ROUTER_FROM_SERVER || true,
  }
}

Options

writeKey

  • Type: String
    • Default: process.env.SEGMENT_WRITE_KEY || publicRuntimeConfig.SEGMENT_WRITE_KEY

disabled

  • Type: Boolean
    • Default: process.env.SEGMENT_DISABLED || publicRuntimeConfig.SEGMENT_DISABLED || false

useRouter

  • Type: Boolean
    • Default: process.env.SEGMENT_USE_ROUTER || publicRuntimeConfig.SEGMENT_USE_ROUTER || true

Usage

Inside a Vue component, the Segment analytics object is available as this.$segment:

export default {
  mounted () {
    this.$segment.identify('f4ca124298', {
      name: 'Michael Bolton',
      email: 'mbolton@initech.com'
    });
    this.$segment.track('Signed Up', { plan: 'Enterprise' });
    this.$segment.page('Pricing');
  }
}

$segment is also injected into the Nuxt context so you can access it within your Vuex stores:

export default {
  LOGOUT({ dispatch }) {
    return this.$auth.logout()
      .then(() => {
        this.$segment.reset();
        return dispatch('AFTER_LOGOUT');
      })
  }
}

Development

  • Clone this repository
  • Install dependencies using yarn install
  • Start development server using npm run dev

License

MIT License

FAQs

Last updated on 11 Mar 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc