Skip to content

Commit

Permalink
Merge pull request #70 from incuna/parse-utm-get-params
Browse files Browse the repository at this point in the history
Added getUtmParams method
  • Loading branch information
Julien Bouquillon committed May 27, 2015
2 parents d4e812b + 983fc0e commit 532579b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/angular-google-analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,28 @@ angular.module('angular-google-analytics', [])
return removeRegExp ? url.replace(removeRegExp, '') : url;
};

var getUtmParams = function () {
var utmToCampaignVar = {
utm_source: 'campaignSource',
utm_medium: 'campaignMedium',
utm_term: 'campaignTerm',
utm_content: 'campaignContent',
utm_campaign: 'campaignName'
};
var object = {};

angular.forEach($location.search(), function (value, key) {
var campaignVar = utmToCampaignVar[key];

if (angular.isDefined(campaignVar)) {
object[campaignVar] = value;
}

});

return object;
};

/**
* Private Methods
*/
Expand Down Expand Up @@ -338,6 +360,7 @@ angular.module('angular-google-analytics', [])
'page': trackPrefix + url,
'title': title
};
angular.extend(opt_fieldObject, getUtmParams());
if (angular.isObject(custom)) {
angular.extend(opt_fieldObject, custom);
}
Expand Down

0 comments on commit 532579b

Please sign in to comment.