Skip to main content

Segment

Segment collects analytics data and allows you to send it to more than 250 apps.

Credential configuration

To configure this credential you only need the write key of the configured Segment source. You can take a look here if you need to find it.

Optionally you can set any of the extra config params you can see here.

Here you have an example of a filled credential configuration form in YepCode:

Segment snippets available in editor

note

The title is the triggering text for YepCode to autocomplete the script

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'
});