@@ -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+ }
0 commit comments