11'use strict' ;
22
33var integration = require ( '@segment/analytics.js-integration' ) ;
4- var useHttps = require ( 'use-https' ) ;
54var is = require ( 'is' ) ;
65var each = require ( '@ndhoule/each' ) ;
76
@@ -13,8 +12,9 @@ var each = require('@ndhoule/each');
1312var Hindsight = ( module . exports = integration ( 'Hindsight' )
1413 . global ( 'RB' )
1514 . option ( 'pixel_code' , '' )
16- . tag ( 'http' , '<script src="http://getrockerbox.com/assets/xyz.js">' )
17- . tag ( 'https' , '<script src="https://getrockerbox.com/assets/xyz.js">' ) ) ;
15+ . option ( 'customTrackingDomain' , '' )
16+ . option ( 'enableCookieSync' , true )
17+ . tag ( '<script src="https://{{ host }}/assets/{{ lib }}.js">' ) ) ;
1818
1919/**
2020 * Initialize
@@ -31,9 +31,18 @@ Hindsight.prototype.initialize = function() {
3131 } ;
3232 window . RB . source = this . options . pixel_code ;
3333
34- var protocol = useHttps ( ) ? 'https' : 'http' ;
35-
36- this . load ( protocol , this . ready ) ;
34+ var hasCustomDomain = ! ! this . options . customTrackingDomain ;
35+ var enableCookieSync = this . options . enableCookieSync ;
36+ var scriptHost = hasCustomDomain
37+ ? this . options . customTrackingDomain
38+ : 'getrockerbox.com' ;
39+ var scriptLib = hasCustomDomain && enableCookieSync ? 'wxyz.rb' : 'wxyz.v2' ;
40+ var tagParams = {
41+ host : scriptHost ,
42+ lib : scriptLib
43+ } ;
44+
45+ this . load ( tagParams , this . ready ) ;
3746} ;
3847
3948/**
@@ -77,7 +86,8 @@ Hindsight.prototype.identify = function(identify) {
7786function format ( props ) {
7887 var ret = { } ;
7988 each ( function ( value , key ) {
80- return ( ret [ key ] = is . object ( value ) ? window . JSON . stringify ( value ) : value ) ;
89+ ret [ key ] = is . object ( value ) ? window . JSON . stringify ( value ) : value ;
90+ return ret [ key ] ;
8191 } , props ) ;
8292
8393 return ret ;
0 commit comments