File tree Expand file tree Collapse file tree 2 files changed +64
-1
lines changed Expand file tree Collapse file tree 2 files changed +64
-1
lines changed Original file line number Diff line number Diff line change 77
88var object = require ( './object' ) ;
99var collection = require ( './collection' ) ;
10+ var type = require ( './type' ) ;
11+
12+ /**
13+ * Send hostname on DOMContentLoaded.
14+ * To prevent hostname set tui.usageStatistics to false.
15+ * @param {string } applicationId - application id to send
16+ * @ignore
17+ */
18+ function sendHostname ( applicationId ) {
19+ var url = 'https://www.google-analytics.com/collect' ;
20+ var hostname = location . hostname ;
21+ var hitType = 'event' ;
22+ var trackingId = 'UA-115377265-9' ;
23+
24+ // skip only if the flag is defined and is set to false explicitly
25+ if ( ! type . isUndefined ( window . tui ) && window . tui . usageStatistics === false ) {
26+ return ;
27+ }
28+
29+ setTimeout ( function ( ) {
30+ if ( document . readyState === 'interactive' || document . readyState === 'complete' ) {
31+ imagePing ( url , {
32+ v : 1 ,
33+ t : hitType ,
34+ tid : trackingId ,
35+ cid : hostname ,
36+ dp : hostname ,
37+ dh : applicationId
38+ } ) ;
39+ }
40+ } , 1000 ) ;
41+ }
1042
1143/**
1244 * Request image ping.
@@ -47,5 +79,6 @@ function imagePing(url, trackingInfo) {
4779}
4880
4981module . exports = {
50- imagePing : imagePing
82+ imagePing : imagePing ,
83+ sendHostname : sendHostname
5184} ;
Original file line number Diff line number Diff line change @@ -21,4 +21,34 @@ describe('module:request', function() {
2121 expect ( trackingElement . src ) . toBe ( 'https://www.google-analytics.com/collect?v=1&t=event&tid=tracnkingid&cid=cid&dp=dp&dh=dh' ) ;
2222 } ) ;
2323 } ) ;
24+
25+ describe ( 'sendHostname' , function ( ) {
26+ beforeEach ( function ( ) {
27+ window . tui = window . tui || { } ;
28+
29+ // can not spy on imagePing. spy on appendChild instead.
30+ spyOn ( document . body , 'appendChild' ) ;
31+ spyOn ( document . body , 'removeChild' ) ;
32+ } ) ;
33+
34+ it ( 'should call appendChild' , function ( done ) {
35+ request . sendHostname ( 'editor' ) ;
36+
37+ setTimeout ( function ( ) {
38+ expect ( document . body . appendChild ) . toHaveBeenCalled ( ) ;
39+ done ( ) ;
40+ } , 1500 ) ;
41+ } ) ;
42+
43+ it ( 'should not call appendChild' , function ( done ) {
44+ window . tui . usageStatistics = false ;
45+
46+ request . sendHostname ( 'editor' ) ;
47+
48+ setTimeout ( function ( ) {
49+ expect ( document . body . appendChild ) . not . toHaveBeenCalled ( ) ;
50+ done ( ) ;
51+ } , 1500 ) ;
52+ } ) ;
53+ } ) ;
2454} ) ;
You can’t perform that action at this time.
0 commit comments