Segment
Segment collects analytics data and allows you to send it to more than 250 apps.
Official Websitehttps://segment.com/
TagsAnalytics
- JavaScript
- Python
Documentationhttps://segment.com/libraries/node
NodeJS packagehttps://www.npmjs.com/package/analytics-node
Version6.2.0
Source Codehttps://github.com/segmentio/analytics-node
Comming soon
We are releasing new Python features every week
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 parameters you can see here.
Here is 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.
- JavaScript
- Python
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'
});
Comming soon
We are releasing new Python features every week