@@ -135,7 +135,8 @@ var DEFAULT_OPTIONS = {
135135 domain : undefined ,
136136 sessionTimeout : 30 * 60 * 1000 ,
137137 platform : 'Web' ,
138- language : language . language
138+ language : language . language ,
139+ includeUtm : false
139140} ;
140141var LocalStorageKeys = {
141142 LAST_EVENT_ID : 'amplitude_lastEventId' ,
@@ -165,8 +166,7 @@ Amplitude.prototype._newSession = false;
165166 * opt_userId An identifier for this user
166167 * opt_config Configuration options
167168 * - 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.
170170 */
171171Amplitude . prototype . init = function ( apiKey , opt_userId , opt_config ) {
172172 try {
@@ -178,6 +178,9 @@ Amplitude.prototype.init = function(apiKey, opt_userId, opt_config) {
178178 if ( opt_config . domain !== undefined ) {
179179 this . options . domain = opt_config . domain ;
180180 }
181+ if ( opt_config . includeUtm !== undefined ) {
182+ this . options . includeUtm = ! ! opt_config . includeUtm ;
183+ }
181184 this . options . platform = opt_config . platform || this . options . platform ;
182185 this . options . language = opt_config . language || this . options . language ;
183186 this . options . sessionTimeout = opt_config . sessionTimeout || this . options . sessionTimeout ;
@@ -214,9 +217,9 @@ Amplitude.prototype.init = function(apiKey, opt_userId, opt_config) {
214217 this . sendEvents ( ) ;
215218 }
216219
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+ }
220223
221224 this . _lastEventTime = parseInt ( localStorage . getItem ( LocalStorageKeys . LAST_EVENT_TIME ) ) || null ;
222225 this . _sessionId = parseInt ( localStorage . getItem ( LocalStorageKeys . SESSION_ID ) ) || null ;
@@ -291,6 +294,15 @@ Amplitude._getUtmData = function(rawCookie, query) {
291294 } ;
292295} ;
293296
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+
294306Amplitude . prototype . saveEvents = function ( ) {
295307 try {
296308 localStorage . setItem ( this . options . unsentKey , JSON . stringify ( this . _unsentEvents ) ) ;
@@ -375,7 +387,7 @@ Amplitude.prototype.logEvent = function(eventType, eventProperties) {
375387
376388 // Add the utm properties, if any, onto the user properties.
377389 var userProperties = { } ;
378- object . merge ( userProperties , this . options . userProperties || { } , this . _utmProperties ) ;
390+ object . merge ( userProperties , this . options . userProperties || { } ) ;
379391 object . merge ( userProperties , this . _utmProperties ) ;
380392
381393 eventProperties = eventProperties || { } ;
@@ -2489,7 +2501,7 @@ exports.isEmpty = function(obj){
24892501} ;
24902502} , { } ] ,
2491250314 : [ function ( require , module , exports ) {
2492- module . exports = '2.0.3 ' ;
2504+ module . exports = '2.0.4 ' ;
24932505
24942506} , { } ] } , { } , { "1" :"" } )
24952507) ;
0 commit comments