From c468c120c10a90a704146be80957f2c11a13b176 Mon Sep 17 00:00:00 2001 From: Marcin Wolniewicz Date: Wed, 27 May 2015 16:51:22 +0100 Subject: [PATCH 1/2] Added getUtmParams method --- src/angular-google-analytics.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/angular-google-analytics.js b/src/angular-google-analytics.js index e3e3a0b..879e428 100644 --- a/src/angular-google-analytics.js +++ b/src/angular-google-analytics.js @@ -126,6 +126,23 @@ 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) { + object[utmToCampaignVar[key]] = value; + }); + + return object; + }; + /** * Private Methods */ @@ -338,6 +355,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); } From 983fc0e82629a8ffdfeaab72ca0ce0a7499a49fc Mon Sep 17 00:00:00 2001 From: Marcin Wolniewicz Date: Wed, 27 May 2015 17:18:11 +0100 Subject: [PATCH 2/2] Added check to allow only specified utm vars --- src/angular-google-analytics.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/angular-google-analytics.js b/src/angular-google-analytics.js index 879e428..9ccd7fc 100644 --- a/src/angular-google-analytics.js +++ b/src/angular-google-analytics.js @@ -137,7 +137,12 @@ angular.module('angular-google-analytics', []) var object = {}; angular.forEach($location.search(), function (value, key) { - object[utmToCampaignVar[key]] = value; + var campaignVar = utmToCampaignVar[key]; + + if (angular.isDefined(campaignVar)) { + object[campaignVar] = value; + } + }); return object;