Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Adding segment group functionality to analytics npm package. See the docs
import Analytics from 'analytics'
import segmentPlugin from '@analytics/segment'
const originalSegmentInstance = segmentPlugin({
writeKey: '123-xyz'
// Extend originalSegmentInstance with custom methods
const enchancedSegmentInstance = Object.assign({}, originalSegmentInstance, {
methods: {
// add method
group(groupId, traits = {}, options = {}, callback) {
const analyticsInstance = this.instance
// If no segment, return early
if (typeof === 'undefined') {
// Make group call to segment, traits, options, callback)
// Initialize analytics instance with plugins
const analytics = Analytics({
app: 'your-app-name',
plugins: [
// Usage:
// Now you can call in your app like so'one', 'two', 'three')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment