Skip to content
This repository was archived by the owner on Aug 20, 2019. It is now read-only.

Commit cabbdf8

Browse files
authored
Merge pull request #32 from segment-integrations/add/setting_source_name
Add/setting source name
2 parents 23d5d07 + f9213b5 commit cabbdf8

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

circle.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ machine:
44
environment:
55
NPM_CONFIG_PROGRESS: false
66
NPM_CONFIG_SPIN: false
7-
SAUCE_ACCESS_KEY: 80dcffc2-c9a2-45e2-9fb7-87b29a6cd986
8-
SAUCE_USERNAME: segment-oss
97
TEST_REPORTS_DIR: $CIRCLE_TEST_REPORTS
108

119
dependencies:

lib/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ var Mixpanel = module.exports = integration('Mixpanel')
3737
.option('trackAllPages', false)
3838
.option('trackNamedPages', false)
3939
.option('trackCategorizedPages', false)
40+
.option('sourceName', '')
4041
.tag('<script src="//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js">');
4142

4243
/**
@@ -184,7 +185,7 @@ Mixpanel.prototype.identify = function(identify) {
184185
var trait = traits[key];
185186
if (Array.isArray(trait) && trait.length > 0) {
186187
traitsToUnion[key] = trait;
187-
// since mixpanel doesn't offer a union method for super properties we have to do it manually by retrieving the existing list super property
188+
// since mixpanel doesn't offer a union method for super properties we have to do it manually by retrieving the existing list super property
188189
// from mixpanel and manually unioning to it ourselves
189190
var existingTrait = window.mixpanel.get_property(key);
190191
if (existingTrait && Array.isArray(existingTrait)) {
@@ -235,6 +236,9 @@ Mixpanel.prototype.track = function(track) {
235236
var revenue = track.revenue();
236237
// Don't map traits, clients should use identify instead.
237238
var superProps = pick(this.options.superProperties, props);
239+
var sourceName = this.options.sourceName;
240+
241+
if (sourceName) props.segment_source_name = sourceName;
238242

239243
// delete mixpanel's reserved properties, so they don't conflict
240244
delete props.distinct_id;
@@ -382,7 +386,7 @@ function extendTraits(arr) {
382386
*
383387
* @api private
384388
* @param {Object} props
385-
* @example
389+
* @example
386390
* input: {products: [{sku: 32, revenue: 99}, {sku:2, revenue: 103}]}
387391
* output: {products_skus: [32, 2], products_revenues: [99, 103]}
388392
*/
@@ -421,7 +425,7 @@ function invertObjectArray(propName, arr) {
421425
continue;
422426
}
423427
var attrKey = propName+'_'+key+'s'; // e.g. products_skus
424-
428+
425429
// append to list if it exists or create new one if not
426430
if (attrKey in invertedArrays) {
427431
invertedArrays[attrKey].push(elem[key]);
@@ -464,4 +468,4 @@ function unionArrays(x, y) {
464468
obj[y[i]] = y[i];
465469
}
466470
return Object.keys(obj);
467-
}
471+
}

test/index.test.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ describe('Mixpanel', function() {
5050
.option('trackNamedPages', false)
5151
.option('consolidatedPageCalls', true)
5252
.option('setAllTraitsByDefault', true)
53-
.option('trackCategorizedPages', false));
53+
.option('trackCategorizedPages', false)
54+
.option('sourceName', ''));
5455
});
5556

5657
describe('before loading', function() {
@@ -492,6 +493,16 @@ describe('Mixpanel', function() {
492493
});
493494
analytics.called(window.mixpanel.people.increment, 'videos_watched', 3);
494495
});
496+
497+
it('should send sourceName if specified', function() {
498+
mixpanel.options.sourceName = 'ios_prod';
499+
analytics.track('event', {
500+
segment_source_name: 'ios_prod'
501+
});
502+
analytics.called(window.mixpanel.track, 'event', {
503+
segment_source_name: 'ios_prod'
504+
});
505+
});
495506
});
496507

497508
describe('#alias', function() {

0 commit comments

Comments
 (0)