export default function ( ) { let analytics = window . analytics = window . analytics || [ ] ; if ( analytics . initialize ) { return ; } if ( analytics . invoked ) { if ( window . console && console . error ) { console . error ( 'Segment snippet included twice.' ) ; } return ; } analytics . invoked = true ; analytics . methods = [ 'trackSubmit' , 'trackClick' , 'trackLink' , 'trackForm' , 'pageview' , 'identify' , 'reset' , 'group' , 'ready' , 'alias' , 'page' , 'once' , 'off' , 'on' , ] ; analytics . track = function ( event , properties , options , fn ) { const isFn = ( value ) => typeof value === 'function' ; if ( isFn ( options ) ) { fn = options , options = null ; } if ( isFn ( properties ) ) { fn = properties , options = null , properties = null ; } if ( fn ) { fn ( ) ; } return this ; } ; analytics . factory = function ( method ) { return function ( ) { let args = Array . prototype . slice . call ( arguments ) ; args . unshift ( method ) ; analytics . push ( args ) ; return analytics ; } ; } ; for ( let i = 0 ; i < analytics . methods . length ; i ++ ) { const key = analytics . methods [ i ] ; analytics [ key ] = analytics . factory ( key ) ; } analytics . load = function ( key ) { const script = document . createElement ( 'script' ) ; script . type = 'text/javascript' ; script . async = true ; script . src = 'https://cdn.segment.com/analytics.js/v1/' + key + '/analytics.min.js' ; const first = document . getElementsByTagName ( 'script' ) [ 0 ] ; first . parentNode ! . insertBefore ( script , first ) ; } ; analytics . SNIPPET_VERSION = '3.1.0' ; if ( __ENABLE_SEGMENT__ ) { analytics . load ( __SEGMENT_TOKEN__ ) ; } }