0.2.12 • Published 5 years ago
@leahcimic/nuxt-segment v0.2.12
nuxt-segment
Nuxt.js module for Segment Analytics
This module uses vue-segment to add Segment Analytics to a Nuxt.js app.
Setup
- Add
@dansmaculotte/nuxt-segmentdependency using yarn or npm to your project - Add
@dansmaculotte/nuxt-segmenttomodulessection ofnuxt.config.js
- 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
}
}Options
writeKey
- Type:
String- Default:
process.env.SEGMENT_WRITE_KEY || ''
- Default:
disabled
- Type:
Boolean- Default:
process.env.SEGMENT_DISABLED || false
- Default:
useRouter
- Type:
Boolean- Default:
process.env.SEGMENT_USE_ROUTER || true
- Default:
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
0.2.12
5 years ago