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

Commit 65a685b

Browse files
author
ladannasserian
committed
Adds mapping to setting.sourceName
1 parent 23d5d07 commit 65a685b

File tree

3 files changed

+8251
-5
lines changed

3 files changed

+8251
-5
lines changed

lib/index.js

Lines changed: 10 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,11 @@ 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) {
242+
props.segment_source_name = sourceName;
243+
}
238244

239245
// delete mixpanel's reserved properties, so they don't conflict
240246
delete props.distinct_id;
@@ -382,7 +388,7 @@ function extendTraits(arr) {
382388
*
383389
* @api private
384390
* @param {Object} props
385-
* @example
391+
* @example
386392
* input: {products: [{sku: 32, revenue: 99}, {sku:2, revenue: 103}]}
387393
* output: {products_skus: [32, 2], products_revenues: [99, 103]}
388394
*/
@@ -421,7 +427,7 @@ function invertObjectArray(propName, arr) {
421427
continue;
422428
}
423429
var attrKey = propName+'_'+key+'s'; // e.g. products_skus
424-
430+
425431
// append to list if it exists or create new one if not
426432
if (attrKey in invertedArrays) {
427433
invertedArrays[attrKey].push(elem[key]);
@@ -464,4 +470,4 @@ function unionArrays(x, y) {
464470
obj[y[i]] = y[i];
465471
}
466472
return Object.keys(obj);
467-
}
473+
}

0 commit comments

Comments
 (0)