1+ var _gaBeacon = {
2+ uaAcct : '359178.17' ,
3+ self : this ,
4+
5+ /**
6+ * Build a GA domain hash.
7+ */
8+ domainHash : function ( domain ) {
9+ var hash = 0 ;
10+ var c = 0 ;
11+
12+ for ( var pos = domain . length - 1 ; pos >= 0 ; pos -- ) {
13+ var ord = domain . charCodeAt ( pos ) ;
14+ hash = ( hash << 6 & 0xfffffff ) + ord + ( ord << 14 ) ;
15+ c = hash & 0xfe00000 ;
16+ hash = ( c != 0 ) ? ( hash ^ c >> 21 ) : hash ;
17+ }
18+
19+ return hash ;
20+ } ,
21+
22+ /**
23+ * Get a random number.
24+ */
25+ rand : function ( ) {
26+ return Math . floor ( Math . random ( ) * 0x80000000 ) ;
27+ } ,
28+
29+ /**
30+ * Build a new utma cookie.
31+ */
32+ buildUtma : function ( ) {
33+ var utma = [ ] ;
34+
35+ utma . push ( this . domainHash ( document . location . hostname ) ) ;
36+ utma . push ( this . rand ( ) ) ;
37+ utma . push ( Math . floor ( ( new Date ( ) . getTime ( ) ) / 1000 ) ) ;
38+ utma . push ( utma [ 2 ] ) ;
39+ utma . push ( utma [ 2 ] ) ;
40+ utma . push ( 1 ) ;
41+
42+ return utma . join ( '.' ) ;
43+ } ,
44+
45+ /**
46+ * Renew a utma cookie (potentially).
47+ */
48+ renewUtma : function ( utma , force ) {
49+ var utmc = this . getCookie ( 'utmc' ) ;
50+
51+ if ( ( force === true ) || ( ! utmc ) ) {
52+ utma = utma . split ( '.' ) ;
53+ utma [ 5 ] ++ ;
54+ utma [ 3 ] = utma [ 4 ] ;
55+ utma [ 4 ] = Math . floor ( ( new Date ( ) . getTime ( ) ) / 1000 ) ;
56+ utma = utma . join ( '.' ) ;
57+ }
58+
59+ return utma ;
60+ } ,
61+
62+ /**
63+ * Build custom vars "X10" code.
64+ */
65+ buildCustomVars : function ( standard , errors , warnings , notices ) {
66+ var keys = [ 'Standard' , 'Errors' , 'Warnings' , 'Notices' ] ;
67+ var values = [ standard , errors , warnings , notices ] ;
68+ var x10 = '' ;
69+
70+ x10 += '8(' + keys . join ( '*' ) + ')' ;
71+ x10 += '9(' + values . join ( '*' ) + ')' ;
72+
73+ return x10 ;
74+ } ,
75+
76+ /**
77+ * Build a URL.
78+ */
79+ url : function ( standard , errors , warnings , notices , force ) {
80+ var url = 'http://www.google-analytics.com/__utm.gif?' ;
81+ if ( location . protocol === 'https:' ) {
82+ url = 'https://ssl.google-analytics.com/__utm.gif?' ;
83+ }
84+
85+ var utma = this . getCookie ( 'utma' ) ;
86+ if ( ! utma ) {
87+ utma = this . buildUtma ( ) ;
88+ } else {
89+ utma = this . renewUtma ( utma , force ) ;
90+ }
91+
92+ var expires = new Date ( ) ;
93+ expires . setFullYear ( expires . getFullYear ( ) + 2 ) ;
94+
95+ this . setCookie ( 'utma' , utma , expires ) ;
96+ this . setCookie ( 'utmc' , this . domainHash ( document . location . hostname ) ) ;
97+
98+ var getVars = {
99+ utmwv : '0.0' ,
100+ utmn : this . rand ( ) ,
101+ utmhn : document . location . hostname ,
102+ utmp : document . location . pathname ,
103+ utmac : 'UA-' + this . uaAcct . split ( '.' ) . join ( '-' ) ,
104+ utme : this . buildCustomVars ( standard , errors , warnings , notices ) ,
105+ utmcc : '__utma=' + utma + ';'
106+ }
107+
108+ for ( varName in getVars ) {
109+ url += escape ( varName ) + '=' + escape ( getVars [ varName ] ) + '&' ;
110+ }
111+
112+ return url ;
113+ } ,
114+
115+ /**
116+ * Set cookie.
117+ */
118+ setCookie : function ( cookieName , value , expires ) {
119+ cookieName = '__htmlcs.' + cookieName ;
120+
121+ var cookieStr = cookieName + '=' + value ;
122+ cookieStr += ';path=/' ;
123+
124+ if ( expires ) {
125+ cookieStr += ';expires=' + escape ( expires . toString ( ) ) ;
126+ }
127+
128+ document . cookie = cookieStr ;
129+ } ,
130+
131+ /**
132+ * Check whether cookie exists.
133+ * (Based on Mozilla Developer Network page example on "document.cookie").
134+ */
135+ cookieExists : function ( cookieName ) {
136+ cookieName = '__htmlcs.' + cookieName ;
137+ return ( new RegExp ( "(?:^|;\\s*)" + escape ( cookieName ) . replace ( / [ \- \. \+ \* ] / g, "\\$&" ) + "\\s*\\=" ) ) . test ( document . cookie ) ;
138+ } ,
139+
140+ /**
141+ * Get cookie.
142+ * (Based on Mozilla Developer Network page example on "document.cookie").
143+ */
144+ getCookie : function ( cookieName ) {
145+ if ( this . cookieExists ( cookieName ) === false ) {
146+ return null ;
147+ }
148+
149+ cookieName = '__htmlcs.' + cookieName ;
150+ return unescape ( document . cookie . replace ( new RegExp ( "(?:^|.*;\\s*)" + escape ( cookieName ) . replace ( / [ \- \. \+ \* ] / g, "\\$&" ) + "\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*" ) , "$1" ) ) ;
151+ }
152+ } ;
153+
154+ var counts = self . countIssues ( _messages ) ;
155+ var gaImg = _doc . createElement ( 'img' ) ;
156+ gaImg . src = _gaBeacon . url ( standard , counts . error , counts . warning , counts . notice , newlyOpen ) ;
157+ gaImg . style . display = 'none' ;
0 commit comments