snippets_js
Integration
New integration from credential
const segment = yepcode.integration.segment('credential-slug')
New integration from plain authentication data
const Analytics = require('analytics-node');
const segmentAnalytics = new Analytics('SEGMENT_YOUR_WRITE_KEY', {
flushAt: 20,
flushInterval: 10000,
enable: false
});
Identify Requests
Anonymous identify
segmentAnalytics.identify({
anonymousId: '48d213bb-95c3-4f8d-af97-86b2b404dcfe',
traits: {
friends: 42
}
});
Identify for an identified user
segmentAnalytics.identify({
userId: '019mr8mf4r',
traits: {
name: 'Michael Bolton',
email: 'mbolton@example.com',
plan: 'Enterprise',
friends: 42
}
});
Track Requests
Anonymous track
segmentAnalytics.track({
anonymousId: '48d213bb-95c3-4f8d-af97-86b2b404dcfe',
event: 'Item Purchased',
properties: {
revenue: 39.95,
shippingMethod: '2-day'
}
});
Track for an identified user
segmentAnalytics.track({
userId: '019mr8mf4r',
event: 'Item Purchased',
properties: {
revenue: 39.95,
shippingMethod: '2-day'
}
});
Page Requests
Page call
segmentAnalytics.page({
userId: '019mr8mf4r',
category: 'Docs',
name: 'Node.js Library',
properties: {
url: 'https://segment.com/docs/connections/sources/catalog/librariesnode',
path: '/docs/connections/sources/catalog/librariesnode/',
title: 'Node.js Library - Segment',
referrer: 'https://github.com/segmentio/analytics-node'
}
});
Group Requests
Group call
segmentAnalytics.group({
userId: '019mr8mf4r',
groupId: '56',
traits: {
name: 'Initech',
description: 'Accounting Software'
}
});
Alias Requests
Alias call
segmentAnalytics.alias({
previousId: 'old_id',
userId: 'new_id'
});