Skip to content

Commit 01f0038

Browse files
committed
added utmMapper and utmHandling
1 parent 22e9ee2 commit 01f0038

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

src/Breinify.js

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,38 @@
179179
return unixTimestamp + "-" + paraLocalDateTime + "-" + paraTimezone;
180180
},
181181

182+
handleUtmParameters: function() {
183+
184+
// get the mapper to be used
185+
var mapper = _config.get(ATTR_CONFIG.UTM_MAPPER);
186+
if (typeof mapper !== 'function') {
187+
return;
188+
}
189+
190+
// see https://en.wikipedia.org/wiki/UTM_parameters
191+
var params = BreinifyUtil.loc.params();
192+
193+
var utmSource = Breinify.UTL.isEmpty(params['utm_source']) ? null : params['utm_source'];
194+
var utmMedium = Breinify.UTL.isEmpty(params['utm_medium']) ? null : params['utm_medium'];
195+
var utmCampaign = Breinify.UTL.isEmpty(params['utm_campaign']) ? null : params['utm_campaign'];
196+
var utmTerm = Breinify.UTL.isEmpty(params['utmTerm']) ? null : params['utm_term'];
197+
var utmContent = Breinify.UTL.isEmpty(params['utmContent']) ? null : params['utm_content'];
198+
199+
// create the data
200+
var values = mapper({
201+
'utmSource': utmSource,
202+
'utmMedium': utmMedium,
203+
'utmCampaign': utmCampaign,
204+
'utmTerm': utmTerm,
205+
'utmContent': utmContent
206+
}, user);
207+
208+
// make sure we have a result and send the activity
209+
if ($.isPlainObject(values) && $.isPlainObject(values.user) && $.isPlainObject(values.utmData)) {
210+
Breinify.activity(values.user, 'utmData', null, null, values.utmData, null);
211+
}
212+
},
213+
182214
handleGetParameters: function () {
183215
var knownParams = {
184216
'brec': {
@@ -208,7 +240,7 @@
208240
}
209241
},
210242

211-
handleGetParameter: function(name, value, overrides) {
243+
handleGetParameter: function (name, value, overrides) {
212244

213245
// parse it and make sure it was parseable
214246
var parsedValue = _privates.parseGetParameter(name, value);
@@ -244,7 +276,7 @@
244276
*/
245277
var user = combinedValue.user;
246278
var activity = combinedValue.activity;
247-
Breinify.activity(user, activity.type, activity.category, activity.description, activity.tags, null, function() {
279+
Breinify.activity(user, activity.type, activity.category, activity.description, activity.tags, null, function () {
248280

249281
// mark it as successfully sent
250282
BreinifyUtil.cookie.set(hashId, true);
@@ -287,6 +319,10 @@
287319
if (_config.get(ATTR_CONFIG.HANDLE_PARAMETERS) === true) {
288320
_privates.handleGetParameters();
289321
}
322+
323+
if (_config.get(ATTR_CONFIG.HANDLE_UTM) === true) {
324+
_privates.handleUtmParameters();
325+
}
290326
};
291327

292328
/**

src/BreinifyConfig.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,25 @@
9191
return value === true || value === false;
9292
}
9393
});
94+
attributes.add('HANDLE_UTM', {
95+
name: 'handleUtm',
96+
defaultValue: false,
97+
validate: function (value) {
98+
return value === true || value === false;
99+
}
100+
});
101+
attributes.add('UTM_MAPPER', {
102+
name: 'utmMapper',
103+
defaultValue: function(utmData, user) {
104+
return {
105+
'utmData': utmData,
106+
'user': user
107+
};
108+
},
109+
validate: function (value) {
110+
return value === null || typeof(value) === 'function';
111+
}
112+
});
94113
attributes.add('AJAX_TIMEOUT', {
95114
name: 'timeout',
96115
defaultValue: 4000,

0 commit comments

Comments
 (0)