1/** 2 * This was abstracted from wp-calypso's analytics lib: https://github.com/Automattic/wp-calypso/blob/master/client/lib/analytics/README.md 3 * Some stuff was removed like GA tracking and other things not necessary for Jetpack tracking. 4 * 5 * This library should only be used and loaded if the Jetpack site is connected. 6 */ 7 8// Load tracking scripts 9window._tkq = window._tkq || []; 10 11var _user; 12var debug = console.error; // eslint-disable-line no-console 13 14function buildQuerystring( group, name ) { 15 var uriComponent = ''; 16 17 if ( 'object' === typeof group ) { 18 for ( var key in group ) { 19 uriComponent += '&x_' + encodeURIComponent( key ) + '=' + encodeURIComponent( group[ key ] ); 20 } 21 } else { 22 uriComponent = '&x_' + encodeURIComponent( group ) + '=' + encodeURIComponent( name ); 23 } 24 25 return uriComponent; 26} 27 28var analytics = { 29 initialize: function ( userId, username ) { 30 analytics.setUser( userId, username ); 31 analytics.identifyUser(); 32 }, 33 34 mc: { 35 bumpStat: function ( group, name ) { 36 var uriComponent = buildQuerystring( group, name ); // prints debug info 37 new Image().src = 38 document.location.protocol + 39 '//pixel.wp.com/g.gif?v=wpcom-no-pv' + 40 uriComponent + 41 '&t=' + 42 Math.random(); 43 }, 44 }, 45 46 tracks: { 47 recordEvent: function ( eventName, eventProperties ) { 48 eventProperties = eventProperties || {}; 49 50 if ( eventName.indexOf( 'jetpack_' ) !== 0 ) { 51 debug( '- Event name must be prefixed by "jetpack_"' ); 52 return; 53 } 54 55 window._tkq.push( [ 'recordEvent', eventName, eventProperties ] ); 56 }, 57 58 recordPageView: function ( urlPath ) { 59 analytics.tracks.recordEvent( 'jetpack_page_view', { 60 path: urlPath, 61 } ); 62 }, 63 }, 64 65 setUser: function ( userId, username ) { 66 _user = { ID: userId, username: username }; 67 }, 68 69 identifyUser: function () { 70 // Don't identify the user if we don't have one 71 if ( _user ) { 72 window._tkq.push( [ 'identifyUser', _user.ID, _user.username ] ); 73 } 74 }, 75 76 clearedIdentity: function () { 77 window._tkq.push( [ 'clearIdentity' ] ); 78 }, 79};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.