1+ < html >
2+
3+ < head >
4+ < style >
5+ body {
6+ font-family : monospace;
7+ }
8+
9+ # event {
10+ margin : 2em 0 ;
11+ min-height : 200px ;
12+ min-width : 700px ;
13+ }
14+ </ style >
15+
16+ < form method ="get ">
17+ < input type ="text " name ="writeKey " placeholder ="Writekey " />
18+ < button > Load</ button >
19+ </ form >
20+ </ script >
21+ < script >
22+ const { searchParams } = new URL ( document . location ) ;
23+ const writeKey = searchParams . get ( "writeKey" ) ;
24+ document . querySelector ( "input" ) . value = writeKey ;
25+
26+ if ( writeKey ) {
27+ console . profile ( 'snippet' )
28+ console . time ( 'snippet' )
29+ ! function ( ) {
30+ var i = "analytics" , analytics = window [ i ] = window [ i ] || [ ] ; if ( ! analytics . initialize ) if ( analytics . invoked ) window . console && console . error && console . error ( "Segment snippet included twice." ) ; else {
31+ analytics . invoked = ! 0 ; analytics . methods = [ "trackSubmit" , "trackClick" , "trackLink" , "trackForm" , "pageview" , "identify" , "reset" , "group" , "track" , "ready" , "alias" , "debug" , "page" , "screen" , "once" , "off" , "on" , "addSourceMiddleware" , "addIntegrationMiddleware" , "setAnonymousId" , "addDestinationMiddleware" , "register" ] ; analytics . factory = function ( e ) { return function ( ) { if ( window [ i ] . initialized ) return window [ i ] [ e ] . apply ( window [ i ] , arguments ) ; var n = Array . prototype . slice . call ( arguments ) ; if ( [ "track" , "screen" , "alias" , "group" , "page" , "identify" ] . indexOf ( e ) > - 1 ) { var c = document . querySelector ( "link[rel='canonical']" ) ; n . push ( { __t : "bpc" , c : c && c . getAttribute ( "href" ) || void 0 , p : location . pathname , u : location . href , s : location . search , t : document . title , r : document . referrer } ) } n . unshift ( e ) ; analytics . push ( n ) ; return analytics } } ; for ( var n = 0 ; n < analytics . methods . length ; n ++ ) { var key = analytics . methods [ n ] ; analytics [ key ] = analytics . factory ( key ) } analytics . load = function ( key , n ) { var t = document . createElement ( "script" ) ; t . type = "text/javascript" ; t . async = ! 0 ; t . setAttribute ( "data-global-segment-analytics-key" , i ) ; t . src = "https://cdn.segment.com/analytics.js/v1/" + key + "/analytics.min.js" ; var r = document . getElementsByTagName ( "script" ) [ 0 ] ; r . parentNode . insertBefore ( t , r ) ; analytics . _loadOptions = n } ; analytics . _writeKey = writeKey ; ; analytics . SNIPPET_VERSION = "5.2.0" ;
32+ analytics . page ( ) ;
33+ }
34+ } ( ) ;
35+ }
36+ </ script >
37+ < script src ="/node_modules/@segment/analytics-signals/dist/umd/analytics-signals.umd.js "> </ script >
38+ < script >
39+ var signalsPlugin = new SignalsPlugin ( )
40+ analytics . register ( signalsPlugin )
41+ analytics . load ( analytics . _writeKey )
42+ </ script >
43+
44+ < body >
45+ < form >
46+ < textarea name ="event " id ="event ">
47+ {
48+ "name": "hi",
49+ "properties": { },
50+ "traits": { },
51+ "options": { }
52+ }
53+ </ textarea >
54+ < div >
55+ < button id ="track "> Track</ button >
56+ < button id ="identify "> Identify</ button >
57+ </ div >
58+ </ form >
59+
60+ < pre id ="ready-logs "> </ pre >
61+ < pre id ="logs "> </ pre >
62+
63+ < script type ="text/javascript ">
64+ if ( window . analytics ) {
65+ window . analytics . ready ( function onReady ( ) {
66+ console . profileEnd ( 'snippet' )
67+ console . timeEnd ( 'snippet' )
68+ document . querySelector ( '#ready-logs' ) . textContent = 'ready!'
69+ } )
70+
71+ document . querySelector ( '#track' ) . addEventListener ( 'click' , function ( e ) {
72+ e . preventDefault ( )
73+ var contents = document . querySelector ( '#event' ) . value
74+ var evt = JSON . parse ( contents )
75+ console . profile ( 'track' )
76+ console . time ( 'track' )
77+ var promise = window . analytics . track (
78+ evt . name || '' ,
79+ evt . properties || { } ,
80+ evt . options || { }
81+ )
82+
83+ promise &&
84+ promise . then &&
85+ promise . then ( function ( ctx ) {
86+ console . timeEnd ( 'track' )
87+ console . profileEnd ( 'track' )
88+ ctx . flush ( )
89+ document . querySelector ( '#logs' ) . textContent = JSON . stringify (
90+ ctx . event ,
91+ null ,
92+ ' '
93+ )
94+ } )
95+ } )
96+
97+ document
98+ . querySelector ( '#identify' )
99+ . addEventListener ( 'click' , function ( e ) {
100+ e . preventDefault ( )
101+ var contents = document . querySelector ( '#event' ) . value
102+ var evt = JSON . parse ( contents )
103+ console . time ( 'identify' )
104+ var promise = window . analytics . identify (
105+ evt . name || '' ,
106+ evt . properties || { } ,
107+ evt . options || { }
108+ )
109+
110+ promise &&
111+ promise . then &&
112+ promise . then ( function ( ctx ) {
113+ console . timeEnd ( 'identify' )
114+ ctx . flush ( )
115+ document . querySelector ( '#logs' ) . textContent = JSON . stringify (
116+ ctx . event ,
117+ null ,
118+ ' '
119+ )
120+ } )
121+ } )
122+ }
123+ </ script >
124+ </ body >
125+
126+ </ html >
0 commit comments