Skip to content

Commit

Permalink
Merge pull request #6452 from Automattic/add-utm-param-tracking
Browse files Browse the repository at this point in the history
Analytics: Add utm URL params to page view event
  • Loading branch information
mattm authored Jul 1, 2016
2 parents dd332f2 + c25c24c commit 6b8f603
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions client/lib/analytics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ var debug = require( 'debug' )( 'calypso:analytics' ),
assign = require( 'lodash/assign' ),
times = require( 'lodash/times' ),
omit = require( 'lodash/omit' ),
pickBy = require( 'lodash/pickBy' ),
startsWith = require( 'lodash/startsWith' ),
isUndefined = require( 'lodash/isUndefined' );
isUndefined = require( 'lodash/isUndefined' ),
url = require( 'url' ),
qs = require( 'qs' );

/**
* Internal dependencies
Expand Down Expand Up @@ -147,9 +150,23 @@ var analytics = {
},

recordPageView: function( urlPath ) {
analytics.tracks.recordEvent( 'calypso_page_view', {
'path': urlPath
} );
let eventProperties = {
path: urlPath
};

// Record all `utm` marketing parameters as event properties on the page view event
// so we can analyze their performance with our analytics tools
if ( window.location ) {
const parsedUrl = url.parse( window.location.href );
const urlParams = qs.parse( parsedUrl.query );
const utmParams = pickBy( urlParams, function( value, key ) {
return startsWith( key, 'utm_' );
} );

eventProperties = assign( eventProperties, utmParams );
}

analytics.tracks.recordEvent( 'calypso_page_view', eventProperties );
},

createRandomId: function() {
Expand Down

0 comments on commit 6b8f603

Please sign in to comment.