@@ -135,7 +135,8 @@ var DEFAULT_OPTIONS = {
135
135
domain : undefined ,
136
136
sessionTimeout : 30 * 60 * 1000 ,
137
137
platform : 'Web' ,
138
- language : language . language
138
+ language : language . language ,
139
+ includeUtm : false
139
140
} ;
140
141
var LocalStorageKeys = {
141
142
LAST_EVENT_ID : 'amplitude_lastEventId' ,
@@ -165,8 +166,7 @@ Amplitude.prototype._newSession = false;
165
166
* opt_userId An identifier for this user
166
167
* opt_config Configuration options
167
168
* - saveEvents (boolean) Whether to save events to local storage. Defaults to true.
168
- * - utmParams (string) Optional utm data in query string format.
169
- * Pulled from location.search otherwise.
169
+ * - includeUtm (boolean) Whether to send utm parameters with events. Defaults to false.
170
170
*/
171
171
Amplitude . prototype . init = function ( apiKey , opt_userId , opt_config ) {
172
172
try {
@@ -178,6 +178,9 @@ Amplitude.prototype.init = function(apiKey, opt_userId, opt_config) {
178
178
if ( opt_config . domain !== undefined ) {
179
179
this . options . domain = opt_config . domain ;
180
180
}
181
+ if ( opt_config . includeUtm !== undefined ) {
182
+ this . options . includeUtm = ! ! opt_config . includeUtm ;
183
+ }
181
184
this . options . platform = opt_config . platform || this . options . platform ;
182
185
this . options . language = opt_config . language || this . options . language ;
183
186
this . options . sessionTimeout = opt_config . sessionTimeout || this . options . sessionTimeout ;
@@ -214,9 +217,9 @@ Amplitude.prototype.init = function(apiKey, opt_userId, opt_config) {
214
217
this . sendEvents ( ) ;
215
218
}
216
219
217
- // Parse the utm properties out of cookies and query for adding to user properties.
218
- var utmParams = opt_config && opt_config . utmParams || location . search ;
219
- this . _utmProperties = Amplitude . _getUtmData ( Cookie . get ( '__utmz' ) , utmParams ) ;
220
+ if ( this . options . includeUtm ) {
221
+ this . _initUtmData ( ) ;
222
+ }
220
223
221
224
this . _lastEventTime = parseInt ( localStorage . getItem ( LocalStorageKeys . LAST_EVENT_TIME ) ) || null ;
222
225
this . _sessionId = parseInt ( localStorage . getItem ( LocalStorageKeys . SESSION_ID ) ) || null ;
@@ -291,6 +294,15 @@ Amplitude._getUtmData = function(rawCookie, query) {
291
294
} ;
292
295
} ;
293
296
297
+ /**
298
+ * Parse the utm properties out of cookies and query for adding to user properties.
299
+ */
300
+ Amplitude . prototype . _initUtmData = function ( queryParams , cookieParams ) {
301
+ queryParams = queryParams || location . search ;
302
+ cookieParams = cookieParams || Cookie . get ( '__utmz' ) ;
303
+ this . _utmProperties = Amplitude . _getUtmData ( cookieParams , queryParams ) ;
304
+ } ;
305
+
294
306
Amplitude . prototype . saveEvents = function ( ) {
295
307
try {
296
308
localStorage . setItem ( this . options . unsentKey , JSON . stringify ( this . _unsentEvents ) ) ;
@@ -375,7 +387,7 @@ Amplitude.prototype.logEvent = function(eventType, eventProperties) {
375
387
376
388
// Add the utm properties, if any, onto the user properties.
377
389
var userProperties = { } ;
378
- object . merge ( userProperties , this . options . userProperties || { } , this . _utmProperties ) ;
390
+ object . merge ( userProperties , this . options . userProperties || { } ) ;
379
391
object . merge ( userProperties , this . _utmProperties ) ;
380
392
381
393
eventProperties = eventProperties || { } ;
@@ -2489,7 +2501,7 @@ exports.isEmpty = function(obj){
2489
2501
} ;
2490
2502
} , { } ] ,
2491
2503
14 : [ function ( require , module , exports ) {
2492
- module . exports = '2.0.3 ' ;
2504
+ module . exports = '2.0.4 ' ;
2493
2505
2494
2506
} , { } ] } , { } , { "1" :"" } )
2495
2507
) ;
0 commit comments