@mparticle/web-sdk 2.33.0 → 2.33.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mparticle.common.js +21 -10
- package/dist/mparticle.esm.js +21 -10
- package/dist/mparticle.js +89 -9
- package/package.json +1 -1
- package/src/foregroundTimeTracker.ts +1 -1
- package/src/integrationCapture.ts +82 -2
- package/src/serverModel.ts +6 -2
- package/src/utils.ts +9 -4
package/dist/mparticle.common.js
CHANGED
|
@@ -15,7 +15,7 @@ map:function map(a,b){var c,d,e;if(null===this)throw new TypeError(" this is nul
|
|
|
15
15
|
filter:function filter(a/*, thisArg*/){if(void 0===this||null===this)throw new TypeError;var b=Object(this),c=b.length>>>0;if("function"!=typeof a)throw new TypeError;for(var d=[],e=2<=arguments.length?arguments[1]:void 0,f=0;f<c;f++)if(f in b){var g=b[f];a.call(e,g,f,b)&&d.push(g);}return d},// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray
|
|
16
16
|
isArray:function isArray(a){return "[object Array]"===Object.prototype.toString.call(a)},Base64:Base64$1};
|
|
17
17
|
|
|
18
|
-
var version = "2.33.
|
|
18
|
+
var version = "2.33.1";
|
|
19
19
|
|
|
20
20
|
var Constants={sdkVersion:version,sdkVendor:"mparticle",platform:"web",Messages:{DeprecationMessages:{MethodIsDeprecatedPostfix:"is a deprecated method and will be removed in future releases",AlternativeMethodPrefix:"Please use the alternate method:"},ErrorMessages:{NoToken:"A token must be specified.",EventNameInvalidType:"Event name must be a valid string value.",EventDataInvalidType:"Event data must be a valid object hash.",LoggingDisabled:"Event logging is currently disabled.",CookieParseError:"Could not parse cookie",EventEmpty:"Event object is null or undefined, cancelling send",APIRequestEmpty:"APIRequest is null or undefined, cancelling send",NoEventType:"Event type must be specified.",TransactionIdRequired:"Transaction ID is required",TransactionRequired:"A transaction attributes object is required",PromotionIdRequired:"Promotion ID is required",BadAttribute:"Attribute value cannot be object or array",BadKey:"Key value cannot be object or array",BadLogPurchase:"Transaction attributes and a product are both required to log a purchase, https://docs.mparticle.com/?javascript#measuring-transactions",AudienceAPINotEnabled:"Your workspace is not enabled to retrieve user audiences."},InformationMessages:{CookieSearch:"Searching for cookie",CookieFound:"Cookie found, parsing values",CookieNotFound:"Cookies not found",CookieSet:"Setting cookie",CookieSync:"Performing cookie sync",SendBegin:"Starting to send event",SendIdentityBegin:"Starting to send event to identity server",SendWindowsPhone:"Sending event to Windows Phone container",SendIOS:"Calling iOS path: ",SendAndroid:"Calling Android JS interface method: ",SendHttp:"Sending event to mParticle HTTP service",SendAliasHttp:"Sending alias request to mParticle HTTP service",SendIdentityHttp:"Sending event to mParticle HTTP service",StartingNewSession:"Starting new Session",StartingLogEvent:"Starting to log event",StartingLogOptOut:"Starting to log user opt in/out",StartingEndSession:"Starting to end session",StartingInitialization:"Starting to initialize",StartingLogCommerceEvent:"Starting to log commerce event",StartingAliasRequest:"Starting to Alias MPIDs",LoadingConfig:"Loading configuration options",AbandonLogEvent:"Cannot log event, logging disabled or developer token not set",AbandonAliasUsers:"Cannot Alias Users, logging disabled or developer token not set",AbandonStartSession:"Cannot start session, logging disabled or developer token not set",AbandonEndSession:"Cannot end session, logging disabled or developer token not set",NoSessionToEnd:"Cannot end session, no active session found"},ValidationMessages:{ModifyIdentityRequestUserIdentitiesPresent:"identityRequests to modify require userIdentities to be present. Request not sent to server. Please fix and try again",IdentityRequesetInvalidKey:"There is an invalid key on your identityRequest object. It can only contain a `userIdentities` object and a `onUserAlias` function. Request not sent to server. Please fix and try again.",OnUserAliasType:"The onUserAlias value must be a function.",UserIdentities:"The userIdentities key must be an object with keys of identityTypes and values of strings. Request not sent to server. Please fix and try again.",UserIdentitiesInvalidKey:"There is an invalid identity key on your `userIdentities` object within the identityRequest. Request not sent to server. Please fix and try again.",UserIdentitiesInvalidValues:"All user identity values must be strings or null. Request not sent to server. Please fix and try again.",AliasMissingMpid:"Alias Request must contain both a destinationMpid and a sourceMpid",AliasNonUniqueMpid:"Alias Request's destinationMpid and sourceMpid must be unique",AliasMissingTime:"Alias Request must have both a startTime and an endTime",AliasStartBeforeEndTime:"Alias Request's endTime must be later than its startTime"}},NativeSdkPaths:{LogEvent:"logEvent",SetUserTag:"setUserTag",RemoveUserTag:"removeUserTag",SetUserAttribute:"setUserAttribute",RemoveUserAttribute:"removeUserAttribute",SetSessionAttribute:"setSessionAttribute",AddToCart:"addToCart",RemoveFromCart:"removeFromCart",ClearCart:"clearCart",LogOut:"logOut",SetUserAttributeList:"setUserAttributeList",RemoveAllUserAttributes:"removeAllUserAttributes",GetUserAttributesLists:"getUserAttributesLists",GetAllUserAttributes:"getAllUserAttributes",Identify:"identify",Logout:"logout",Login:"login",Modify:"modify",Alias:"aliasUsers",Upload:"upload"},StorageNames:{localStorageName:"mprtcl-api",localStorageNameV3:"mprtcl-v3",cookieName:"mprtcl-api",cookieNameV2:"mprtcl-v2",cookieNameV3:"mprtcl-v3",localStorageNameV4:"mprtcl-v4",localStorageProductsV4:"mprtcl-prodv4",cookieNameV4:"mprtcl-v4",currentStorageName:"mprtcl-v4",currentStorageProductsName:"mprtcl-prodv4"},DefaultConfig:{cookieDomain:null,cookieExpiration:365,logLevel:null,timeout:300,sessionTimeout:30,maxProducts:20,forwarderStatsTimeout:5e3,integrationDelayTimeout:5e3,maxCookieSize:3e3,aliasMaxWindow:90,uploadInterval:0// Maximum milliseconds in between batch uploads, below 500 will mean immediate upload. The server returns this as a string, but we are using it as a number internally
|
|
21
21
|
},DefaultBaseUrls:{v1SecureServiceUrl:"jssdks.mparticle.com/v1/JS/",v2SecureServiceUrl:"jssdks.mparticle.com/v2/JS/",v3SecureServiceUrl:"jssdks.mparticle.com/v3/JS/",configUrl:"jssdkcdns.mparticle.com/JS/v2/",identityUrl:"identity.mparticle.com/v1/",aliasUrl:"jssdks.mparticle.com/v1/identity/",userAudienceUrl:"nativesdks.mparticle.com/v1/"},Base64CookieKeys:{csm:1,sa:1,ss:1,ua:1,ui:1,csd:1,ia:1,con:1},// https://go.mparticle.com/work/SQDSDKS-6039
|
|
@@ -127,7 +127,7 @@ var Messages$9=Constants.Messages,createCookieString=function(a){return replaceC
|
|
|
127
127
|
"".concat(1e7,"-").concat(1e3,"-").concat(4e3,"-").concat(8e3,"-").concat(1e11).replace(/[018]/g,// zeroes, ones, and eights with
|
|
128
128
|
generateUniqueId// random hex digits
|
|
129
129
|
)},getRampNumber=function(a){if(!a)return 100;var b=generateHash(a);return Math.abs(b%100)+1},isObject=function(a){var b=Object.prototype.toString.call(a);return "[object Object]"===b||"[object Error]"===b},parseNumber=function(a){if(isNaN(a)||!isFinite(a))return 0;var b=parseFloat(a);return isNaN(b)?0:b},parseStringOrNumber=function(a){return isStringOrNumber(a)?a:null},replaceCommasWithPipes=function(a){return a.replace(/,/g,"|")},replacePipesWithCommas=function(a){return a.replace(/\|/g,",")},replaceApostrophesWithQuotes=function(a){return a.replace(/\'/g,"\"")},replaceQuotesWithApostrophes=function(a){return a.replace(/\"/g,"'")},replaceMPID=function(a,b){return a.replace("%%mpid%%",b)},replaceAmpWithAmpersand=function(a){return a.replace(/&/g,"&")},createCookieSyncUrl=function(a,b,c){var d=replaceAmpWithAmpersand(b),e=c?replaceAmpWithAmpersand(c):null,f=replaceMPID(d,a),g=e?replaceMPID(e,a):"";return f+encodeURIComponent(g)},returnConvertedBoolean=function(a){return "false"!==a&&"0"!==a&&!!a},decoded=function(a){return decodeURIComponent(a.replace(/\+/g," "))},converted=function(a){return 0===a.indexOf("\"")&&(a=a.slice(1,-1).replace(/\\"/g,"\"").replace(/\\\\/g,"\\")),a},isString=function(a){return "string"==typeof a},isNumber=function(a){return "number"==typeof a},isBoolean=function(a){return "boolean"==typeof a},isFunction=function(a){return "function"==typeof a},isValidCustomFlagProperty=function(a){return isNumber(a)||isString(a)||isBoolean(a)},toDataPlanSlug=function(a){// Make sure we are only acting on strings or numbers
|
|
130
|
-
return isStringOrNumber(a)?a.toString().toLowerCase().replace(/[^0-9a-zA-Z]+/g,"_"):""},isDataPlanSlug=function(a){return a===toDataPlanSlug(a)},isStringOrNumber=function(a){return isString(a)||isNumber(a)},isEmpty=function(a){return null==a||!(Object.keys(a)||a).length},moveElementToEnd=function(a,b){return a.slice(0,b).concat(a.slice(b+1),a[b])},queryStringParser=function(a,b){void 0===b&&(b=[]);var c,d={};if(!a)return d;if("undefined"!=typeof URL&&"undefined"!=typeof URLSearchParams){var e=new URL(a);c=new URLSearchParams(e.search);}else c=queryStringParserFallback(a);return isEmpty(b)?c.forEach(function(a,b){d[b]=a;}):b.forEach(function(a){var b=c.get(a);b&&(d[a]=b);}),d},queryStringParserFallback=function(a){var b={},c=a.split("?")[1]||"",d=c.split("&");return d.forEach(function(a){var c=a.split("="),d=c[0],e=c
|
|
130
|
+
return isStringOrNumber(a)?a.toString().toLowerCase().replace(/[^0-9a-zA-Z]+/g,"_"):""},isDataPlanSlug=function(a){return a===toDataPlanSlug(a)},isStringOrNumber=function(a){return isString(a)||isNumber(a)},isEmpty=function(a){return null==a||!(Object.keys(a)||a).length},moveElementToEnd=function(a,b){return a.slice(0,b).concat(a.slice(b+1),a[b])},queryStringParser=function(a,b){void 0===b&&(b=[]);var c,d={};if(!a)return d;if("undefined"!=typeof URL&&"undefined"!=typeof URLSearchParams){var e=new URL(a);c=new URLSearchParams(e.search);}else c=queryStringParserFallback(a);return isEmpty(b)?c.forEach(function(a,b){d[b]=a;}):b.forEach(function(a){var b=c.get(a);b&&(d[a]=b);}),d},queryStringParserFallback=function(a){var b={},c=a.split("?")[1]||"",d=c.split("&");return d.forEach(function(a){var c=a.split("="),d=c[0],e=c.slice(1),f=e.join("=");if(d&&void 0!==f)try{b[d]=decodeURIComponent(f||"");}catch(a){console.error("Failed to decode value for key ".concat(d,": ").concat(a));}}),{get:function get(a){return b[a]},forEach:function forEach(a){for(var c in b)b.hasOwnProperty(c)&&a(b[c],c);}}},getCookies=function(a){// Helper function to parse cookies from document.cookie
|
|
131
131
|
var b=function parseCookies(){return "undefined"==typeof window?[]:window.document.cookie.split(";").map(function(a){return a.trim()})}();// Helper function to filter cookies by keys
|
|
132
132
|
// Parse cookies from document.cookie
|
|
133
133
|
// Filter cookies by keys if provided
|
|
@@ -515,7 +515,7 @@ this.convertTransactionAttributesToProductAction=function(a,b){a.hasOwnProperty(
|
|
|
515
515
|
return (a.Logger.verbose(Messages$5.InformationMessages.StartingLogCommerceEvent),a._Helpers.canLog())?(d=a._ServerModel.createEventObject({messageType:Types.MessageType.Commerce,sourceMessageId:null===c||void 0===c?void 0:c.sourceMessageId}),d.EventName="eCommerce - ",d.CurrencyCode=a._Store.currencyCode,d.ShoppingCart=[],d.CustomFlags=e(d.CustomFlags,b),d):(a.Logger.verbose(Messages$5.InformationMessages.AbandonLogEvent),null)},this.sanitizeAmount=function(b,c){if(!a._Helpers.Validators.isStringOrNumber(b)){var d=[c,"must be of type number. A",_typeof$1(b),"was passed. Converting to 0"].join(" ");return a.Logger.warning(d),0}// if amount is a string, it will be parsed into a number if possible, or set to 0
|
|
516
516
|
return a._Helpers.parseNumber(b)};}
|
|
517
517
|
|
|
518
|
-
var ForegroundTimeTracker=/** @class */function(){function a(a){this.isTrackerActive=!1,this.localStorageName="",this.startTime=0,this.totalTime=0,this.localStorageName="
|
|
518
|
+
var ForegroundTimeTracker=/** @class */function(){function a(a){this.isTrackerActive=!1,this.localStorageName="",this.startTime=0,this.totalTime=0,this.localStorageName="mprtcl-tos-".concat(a),this.timerVault=new LocalStorageVault(this.localStorageName),this.loadTimeFromStorage(),this.addHandlers(),!1===document.hidden&&this.startTracking();}return a.prototype.addHandlers=function(){var a=this;// when user switches tabs or minimizes the window
|
|
519
519
|
document.addEventListener("visibilitychange",function(){return a.handleVisibilityChange()}),window.addEventListener("blur",function(){return a.handleWindowBlur()}),window.addEventListener("focus",function(){return a.handleWindowFocus()}),window.addEventListener("storage",function(b){return a.syncAcrossTabs(b)}),window.addEventListener("beforeunload",function(){return a.updateTimeInPersistence()});},a.prototype.handleVisibilityChange=function(){document.hidden?this.stopTracking():this.startTracking();},a.prototype.handleWindowBlur=function(){this.isTrackerActive&&this.stopTracking();},a.prototype.handleWindowFocus=function(){this.isTrackerActive||this.startTracking();},a.prototype.syncAcrossTabs=function(a){if(a.key===this.localStorageName&&null!==a.newValue){var b=parseFloat(a.newValue)||0;this.totalTime=b;}},a.prototype.updateTimeInPersistence=function(){this.isTrackerActive&&this.timerVault.store(Math.round(this.totalTime));},a.prototype.loadTimeFromStorage=function(){var a=this.timerVault.retrieve();isNumber(a)&&null!==a&&(this.totalTime=a);},a.prototype.startTracking=function(){document.hidden||(this.startTime=Math.floor(performance.now()),this.isTrackerActive=!0);},a.prototype.stopTracking=function(){this.isTrackerActive&&(this.setTotalTime(),this.updateTimeInPersistence(),this.isTrackerActive=!1);},a.prototype.setTotalTime=function(){if(this.isTrackerActive){var a=Math.floor(performance.now());this.totalTime+=a-this.startTime,this.startTime=a;}},a.prototype.getTimeInForeground=function(){return this.setTotalTime(),this.updateTimeInPersistence(),this.totalTime},a.prototype.resetTimer=function(){this.totalTime=0,this.updateTimeInPersistence();},a}();
|
|
520
520
|
|
|
521
521
|
function createSDKConfig(a){// TODO: Refactor to create a default config object
|
|
@@ -1046,12 +1046,12 @@ this.appendUserInfo=function(b,c){if(c){if(!b)return c.MPID=null,c.ConsentState=
|
|
|
1046
1046
|
// tracked. If this is an `optOut` Event, we set `optOut` to the inverse of the SDK's
|
|
1047
1047
|
// `isEnabled` boolean which is controlled via `MPInstanceManager.setOptOut`.
|
|
1048
1048
|
// TODO: Why is Webview Bridge Enabled or Opt Out necessary here?
|
|
1049
|
-
if(a._Store.sessionId||c.messageType===Types.MessageType.OptOut||a._Store.webviewBridgeEnabled){var i=__assign({},c.customFlags);// https://go.mparticle.com/work/SQDSDKS-5053
|
|
1050
|
-
if(a._Helpers.getFeatureFlag&&a._Helpers.getFeatureFlag(Constants.FeatureFlags.CaptureIntegrationSpecificIds)){a._IntegrationCapture.capture();var
|
|
1049
|
+
if(a._Store.sessionId||c.messageType===Types.MessageType.OptOut||a._Store.webviewBridgeEnabled){var i=__assign({},c.customFlags),j=a._Store.integrationAttributes;// https://go.mparticle.com/work/SQDSDKS-5053
|
|
1050
|
+
if(a._Helpers.getFeatureFlag&&a._Helpers.getFeatureFlag(Constants.FeatureFlags.CaptureIntegrationSpecificIds)){a._IntegrationCapture.capture();var k=a._IntegrationCapture.getClickIdsAsCustomFlags();i=__assign(__assign({},k),i);var l=a._IntegrationCapture.getClickIdsAsIntegrationAttributes();j=__assign(__assign({},l),j);}g=c.hasOwnProperty("toEventAPIObject")?c.toEventAPIObject():{// This is an artifact from v2 events where SessionStart/End and AST event
|
|
1051
1051
|
// names are numbers (1, 2, or 10), but going forward with v3, these lifecycle
|
|
1052
1052
|
// events do not have names, but are denoted by their `event_type`
|
|
1053
1053
|
EventName:c.name||c.messageType,EventCategory:c.eventType,EventAttributes:a._Helpers.sanitizeAttributes(c.data,c.name),ActiveTimeOnSite:null===(e=a._timeOnSiteTimer)||void 0===e?void 0:e.getTimeInForeground(),SourceMessageId:c.sourceMessageId||a._Helpers.generateUniqueId(),EventDataType:c.messageType,CustomFlags:i,UserAttributeChanges:c.userAttributeChanges,UserIdentityChanges:c.userIdentityChanges},c.messageType!==Types.MessageType.SessionEnd&&(a._Store.dateLastEventSent=new Date),f={// FIXME: Deprecate when we get rid of V2
|
|
1054
|
-
Store:a._Store.serverSettings,SDKVersion:Constants.sdkVersion,SessionId:a._Store.sessionId,SessionStartDate:a._Store.sessionStartDate?a._Store.sessionStartDate.getTime():0,Debug:a._Store.SDKConfig.isDevelopmentMode,Location:a._Store.currentPosition,OptOut:h,ExpandedEventCount:0,AppVersion:a.getAppVersion(),AppName:a.getAppName(),Package:a._Store.SDKConfig["package"],ClientGeneratedId:a._Store.clientId,DeviceId:a._Store.deviceId,IntegrationAttributes:
|
|
1054
|
+
Store:a._Store.serverSettings,SDKVersion:Constants.sdkVersion,SessionId:a._Store.sessionId,SessionStartDate:a._Store.sessionStartDate?a._Store.sessionStartDate.getTime():0,Debug:a._Store.SDKConfig.isDevelopmentMode,Location:a._Store.currentPosition,OptOut:h,ExpandedEventCount:0,AppVersion:a.getAppVersion(),AppName:a.getAppName(),Package:a._Store.SDKConfig["package"],ClientGeneratedId:a._Store.clientId,DeviceId:a._Store.deviceId,IntegrationAttributes:j,CurrencyCode:a._Store.currencyCode,DataPlan:a._Store.SDKConfig.dataPlan?a._Store.SDKConfig.dataPlan:{}},g.EventDataType===MessageType.AppStateTransition&&(g.IsFirstRun=a._Store.isFirstRun,g.LaunchReferral=window.location.href||null),g.CurrencyCode=a._Store.currencyCode;var m=d||a.Identity.getCurrentUser();return b.appendUserInfo(m,g),c.messageType===Types.MessageType.SessionEnd&&(g.SessionLength=a._Store.dateLastEventSent.getTime()-a._Store.sessionStartDate.getTime(),g.currentSessionMPIDs=a._Store.currentSessionMPIDs,g.EventAttributes=a._Store.sessionAttributes,a._Store.currentSessionMPIDs=[],a._Store.sessionStartDate=null),f.Timestamp=a._Store.dateLastEventSent.getTime(),a._Helpers.extend({},g,f)}return null},this.convertEventToV2DTO=function(c){var d={n:c.EventName,et:c.EventCategory,ua:c.UserAttributes,ui:c.UserIdentities,ia:c.IntegrationAttributes,str:c.Store,attrs:c.EventAttributes,sdk:c.SDKVersion,sid:c.SessionId,sl:c.SessionLength,ssd:c.SessionStartDate,dt:c.EventDataType,dbg:c.Debug,ct:c.Timestamp,lc:c.Location,o:c.OptOut,eec:c.ExpandedEventCount,av:c.AppVersion,cgid:c.ClientGeneratedId,das:c.DeviceId,mpid:c.MPID,smpids:c.currentSessionMPIDs};c.DataPlan&&c.DataPlan.PlanId&&(d.dp_id=c.DataPlan.PlanId,c.DataPlan.PlanVersion&&(d.dp_v=c.DataPlan.PlanVersion));var e=b.convertToConsentStateV2DTO(c.ConsentState);return e&&(d.con=e),c.EventDataType===MessageType.AppStateTransition&&(d.fr=c.IsFirstRun,d.iu=!1,d.at=ApplicationTransitionType.AppInit,d.lr=c.LaunchReferral,d.attrs=null),c.CustomFlags&&convertCustomFlags(c,d),c.EventDataType===MessageType.Commerce?(d.cu=c.CurrencyCode,c.ShoppingCart&&(d.sc={pl:convertProductListToV2DTO(c.ShoppingCart.ProductList)}),c.ProductAction?d.pd={an:c.ProductAction.ProductActionType,cs:a._Helpers.parseNumber(c.ProductAction.CheckoutStep),co:c.ProductAction.CheckoutOptions,pl:convertProductListToV2DTO(c.ProductAction.ProductList),ti:c.ProductAction.TransactionId,ta:c.ProductAction.Affiliation,tcc:c.ProductAction.CouponCode,tr:a._Helpers.parseNumber(c.ProductAction.TotalAmount),ts:a._Helpers.parseNumber(c.ProductAction.ShippingAmount),tt:a._Helpers.parseNumber(c.ProductAction.TaxAmount)}:c.PromotionAction?d.pm={an:c.PromotionAction.PromotionActionType,pl:c.PromotionAction.PromotionList.map(function(a){return {id:a.Id,nm:a.Name,cr:a.Creative,ps:a.Position?a.Position:0}})}:c.ProductImpressions&&(d.pi=c.ProductImpressions.map(function(a){return {pil:a.ProductImpressionList,pl:convertProductListToV2DTO(a.ProductList)}}))):c.EventDataType===MessageType.Profile&&(d.pet=c.ProfileMessageType),d};}
|
|
1055
1055
|
|
|
1056
1056
|
function forwardingStatsUploader(a){function b(){var b=a._Forwarders.getForwarderStatsQueue(),c=a._Persistence.forwardingStatsBatches.uploadsTable,d=Date.now();for(var e in b.length&&(c[d]={uploading:!1,data:b},a._Forwarders.setForwarderStatsQueue([])),c)(function(b){if(c.hasOwnProperty(b)&&!1===c[b].uploading){var d=function(){4===e.readyState&&(200===e.status||202===e.status?(a.Logger.verbose("Successfully sent "+e.statusText+" from server"),delete c[b]):"4"===e.status.toString()[0]?429!==e.status&&delete c[b]:c[b].uploading=!1);},e=a._Helpers.createXHR(d),f=c[b].data;c[b].uploading=!0,a._APIClient.sendBatchForwardingStatsToServer(f,e);}})(e);}this.startForwardingStatsTimer=function(){mParticle._forwardingStatsTimer=setInterval(function(){b();},a._Store.SDKConfig.forwarderStatsTimeout);};}
|
|
1057
1057
|
|
|
@@ -1378,12 +1378,23 @@ var facebookClickIdProcessor=function(a,b,c){if(!a||!b)return "";var d=null===b|
|
|
|
1378
1378
|
var h=c||Date.now();return "fb.".concat(g,".").concat(h,".").concat(a)};// Integration outputs are used to determine how click ids are used within the SDK
|
|
1379
1379
|
// CUSTOM_FLAGS are sent out when an Event is created via ServerModel.createEventObject
|
|
1380
1380
|
// PARTNER_IDENTITIES are sent out in a Batch when a group of events are converted to a Batch
|
|
1381
|
-
|
|
1381
|
+
// INTEGRATION_ATTRIBUTES are stored initially on the SDKEvent level but then is added to the Batch when the batch is created
|
|
1382
|
+
var IntegrationOutputs={CUSTOM_FLAGS:"custom_flags",PARTNER_IDENTITIES:"partner_identities",INTEGRATION_ATTRIBUTES:"integration_attributes"},integrationMapping={// Facebook / Meta
|
|
1382
1383
|
fbclid:{mappedKey:"Facebook.ClickId",processor:facebookClickIdProcessor,output:IntegrationOutputs.CUSTOM_FLAGS},_fbp:{mappedKey:"Facebook.BrowserId",output:IntegrationOutputs.CUSTOM_FLAGS},_fbc:{mappedKey:"Facebook.ClickId",output:IntegrationOutputs.CUSTOM_FLAGS},// Google
|
|
1383
|
-
gclid:{mappedKey:"GoogleEnhancedConversions.Gclid",output:IntegrationOutputs.CUSTOM_FLAGS},gbraid:{mappedKey:"GoogleEnhancedConversions.Gbraid",output:IntegrationOutputs.CUSTOM_FLAGS},wbraid:{mappedKey:"GoogleEnhancedConversions.Wbraid",output:IntegrationOutputs.CUSTOM_FLAGS},//
|
|
1384
|
-
|
|
1384
|
+
gclid:{mappedKey:"GoogleEnhancedConversions.Gclid",output:IntegrationOutputs.CUSTOM_FLAGS},gbraid:{mappedKey:"GoogleEnhancedConversions.Gbraid",output:IntegrationOutputs.CUSTOM_FLAGS},wbraid:{mappedKey:"GoogleEnhancedConversions.Wbraid",output:IntegrationOutputs.CUSTOM_FLAGS},// Rokt
|
|
1385
|
+
// https://docs.rokt.com/developers/integration-guides/web/advanced/rokt-id-tag/
|
|
1386
|
+
rtid:{mappedKey:"passbackconversiontrackingid",output:IntegrationOutputs.INTEGRATION_ATTRIBUTES,moduleId:1277},RoktTransactionId:{mappedKey:"passbackconversiontrackingid",output:IntegrationOutputs.INTEGRATION_ATTRIBUTES,moduleId:1277},// TIKTOK
|
|
1387
|
+
ttclid:{mappedKey:"TikTok.Callback",output:IntegrationOutputs.CUSTOM_FLAGS},_ttp:{mappedKey:"tiktok_cookie_id",output:IntegrationOutputs.PARTNER_IDENTITIES}},IntegrationCapture=/** @class */function(){function a(){this.initialTimestamp=Date.now(),this.filteredPartnerIdentityMappings=this.filterMappings(IntegrationOutputs.PARTNER_IDENTITIES),this.filteredCustomFlagMappings=this.filterMappings(IntegrationOutputs.CUSTOM_FLAGS),this.filteredIntegrationAttributeMappings=this.filterMappings(IntegrationOutputs.INTEGRATION_ATTRIBUTES);}/**
|
|
1385
1388
|
* Captures Integration Ids from cookies and query params and stores them in clickIds object
|
|
1386
|
-
*/return a.prototype.capture=function(){var a=this.captureQueryParams()||{},b=this.captureCookies()||{};a.fbclid&&b._fbc&&delete b._fbc,this.clickIds=__assign(__assign(__assign({},this.clickIds),a),b);},a.prototype.captureCookies=function(){var a=getCookies(Object.keys(integrationMapping));return this.applyProcessors(a)},a.prototype.captureQueryParams=function(){var a=this.getQueryParams();return this.applyProcessors(a,getHref(),this.initialTimestamp)},a.prototype.getQueryParams=function(){return queryStringParser(getHref(),Object.keys(integrationMapping))},a.prototype.getClickIdsAsCustomFlags=function(){return this.getClickIds(this.clickIds,this.filteredCustomFlagMappings)},a.prototype.getClickIdsAsPartnerIdentities=function(){return this.getClickIds(this.clickIds,this.filteredPartnerIdentityMappings)},a.prototype.
|
|
1389
|
+
*/return a.prototype.capture=function(){var a=this.captureQueryParams()||{},b=this.captureCookies()||{},c=this.captureLocalStorage()||{};a.fbclid&&b._fbc&&delete b._fbc,a.rtid&&c.RoktTransactionId&&b.RoktTransactionId?(delete c.RoktTransactionId,delete b.RoktTransactionId):a.rtid&&c.RoktTransactionId?delete c.RoktTransactionId:a.rtid&&b.RoktTransactionId?delete b.RoktTransactionId:c.RoktTransactionId&&b.RoktTransactionId&&delete b.RoktTransactionId,this.clickIds=__assign(__assign(__assign(__assign({},this.clickIds),a),c),b);},a.prototype.captureCookies=function(){var a=getCookies(Object.keys(integrationMapping));return this.applyProcessors(a,getHref(),this.initialTimestamp)},a.prototype.captureQueryParams=function(){var a=this.getQueryParams();return this.applyProcessors(a,getHref(),this.initialTimestamp)},a.prototype.captureLocalStorage=function(){var a={};for(var b in integrationMapping){var c=localStorage.getItem(b);c&&(a[b]=c);}return this.applyProcessors(a,getHref(),this.initialTimestamp)},a.prototype.getQueryParams=function(){return queryStringParser(getHref(),Object.keys(integrationMapping))},a.prototype.getClickIdsAsCustomFlags=function(){return this.getClickIds(this.clickIds,this.filteredCustomFlagMappings)},a.prototype.getClickIdsAsPartnerIdentities=function(){return this.getClickIds(this.clickIds,this.filteredPartnerIdentityMappings)},a.prototype.getClickIdsAsIntegrationAttributes=function(){var a,b,c,d={};// Integration IDs are stored in the following format:
|
|
1390
|
+
// {
|
|
1391
|
+
// "integration_attributes": {
|
|
1392
|
+
// "<moduleId>": {
|
|
1393
|
+
// "mappedKey": "clickIdValue"
|
|
1394
|
+
// }
|
|
1395
|
+
// }
|
|
1396
|
+
// }
|
|
1397
|
+
for(var e in this.clickIds)if(this.clickIds.hasOwnProperty(e)){var f=this.clickIds[e],g=null===(b=this.filteredIntegrationAttributeMappings[e])||void 0===b?void 0:b.mappedKey;if(!isEmpty(g)){var h=null===(c=this.filteredIntegrationAttributeMappings[e])||void 0===c?void 0:c.moduleId;h&&!d[h]&&(d[h]=(a={},a[g]=f,a));}}return d},a.prototype.getClickIds=function(a,b){var c,d={};if(!a)return d;for(var e in a)if(a.hasOwnProperty(e)){var f=a[e],g=null===(c=b[e])||void 0===c?void 0:c.mappedKey;isEmpty(g)||(d[g]=f);}return d},a.prototype.applyProcessors=function(a,b,c){var d,e={};for(var f in a)if(a.hasOwnProperty(f)){var g=a[f],h=null===(d=integrationMapping[f])||void 0===d?void 0:d.processor;e[f]=h?h(g,b,c):g;}return e},a.prototype.filterMappings=function(a){var b={};for(var c in integrationMapping)integrationMapping[c].output===a&&(b[c]=integrationMapping[c]);return b},a}();
|
|
1387
1398
|
|
|
1388
1399
|
var Messages=Constants.Messages,HTTPCodes=Constants.HTTPCodes,FeatureFlags=Constants.FeatureFlags,ReportBatching=FeatureFlags.ReportBatching,CaptureIntegrationSpecificIds=FeatureFlags.CaptureIntegrationSpecificIds,StartingInitialization=Messages.InformationMessages.StartingInitialization;/**
|
|
1389
1400
|
* <p>All of the following methods can be called on the primary mParticle class. In version 2.10.0, we introduced <a href="https://docs.mparticle.com/developers/sdk/web/multiple-instances/">multiple instances</a>. If you are using multiple instances (self hosted environments only), you should call these methods on each instance.</p>
|
package/dist/mparticle.esm.js
CHANGED
|
@@ -15,7 +15,7 @@ map:function map(a,b){var c,d,e;if(null===this)throw new TypeError(" this is nul
|
|
|
15
15
|
filter:function filter(a/*, thisArg*/){if(void 0===this||null===this)throw new TypeError;var b=Object(this),c=b.length>>>0;if("function"!=typeof a)throw new TypeError;for(var d=[],e=2<=arguments.length?arguments[1]:void 0,f=0;f<c;f++)if(f in b){var g=b[f];a.call(e,g,f,b)&&d.push(g);}return d},// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray
|
|
16
16
|
isArray:function isArray(a){return "[object Array]"===Object.prototype.toString.call(a)},Base64:Base64$1};
|
|
17
17
|
|
|
18
|
-
var version = "2.33.
|
|
18
|
+
var version = "2.33.1";
|
|
19
19
|
|
|
20
20
|
var Constants={sdkVersion:version,sdkVendor:"mparticle",platform:"web",Messages:{DeprecationMessages:{MethodIsDeprecatedPostfix:"is a deprecated method and will be removed in future releases",AlternativeMethodPrefix:"Please use the alternate method:"},ErrorMessages:{NoToken:"A token must be specified.",EventNameInvalidType:"Event name must be a valid string value.",EventDataInvalidType:"Event data must be a valid object hash.",LoggingDisabled:"Event logging is currently disabled.",CookieParseError:"Could not parse cookie",EventEmpty:"Event object is null or undefined, cancelling send",APIRequestEmpty:"APIRequest is null or undefined, cancelling send",NoEventType:"Event type must be specified.",TransactionIdRequired:"Transaction ID is required",TransactionRequired:"A transaction attributes object is required",PromotionIdRequired:"Promotion ID is required",BadAttribute:"Attribute value cannot be object or array",BadKey:"Key value cannot be object or array",BadLogPurchase:"Transaction attributes and a product are both required to log a purchase, https://docs.mparticle.com/?javascript#measuring-transactions",AudienceAPINotEnabled:"Your workspace is not enabled to retrieve user audiences."},InformationMessages:{CookieSearch:"Searching for cookie",CookieFound:"Cookie found, parsing values",CookieNotFound:"Cookies not found",CookieSet:"Setting cookie",CookieSync:"Performing cookie sync",SendBegin:"Starting to send event",SendIdentityBegin:"Starting to send event to identity server",SendWindowsPhone:"Sending event to Windows Phone container",SendIOS:"Calling iOS path: ",SendAndroid:"Calling Android JS interface method: ",SendHttp:"Sending event to mParticle HTTP service",SendAliasHttp:"Sending alias request to mParticle HTTP service",SendIdentityHttp:"Sending event to mParticle HTTP service",StartingNewSession:"Starting new Session",StartingLogEvent:"Starting to log event",StartingLogOptOut:"Starting to log user opt in/out",StartingEndSession:"Starting to end session",StartingInitialization:"Starting to initialize",StartingLogCommerceEvent:"Starting to log commerce event",StartingAliasRequest:"Starting to Alias MPIDs",LoadingConfig:"Loading configuration options",AbandonLogEvent:"Cannot log event, logging disabled or developer token not set",AbandonAliasUsers:"Cannot Alias Users, logging disabled or developer token not set",AbandonStartSession:"Cannot start session, logging disabled or developer token not set",AbandonEndSession:"Cannot end session, logging disabled or developer token not set",NoSessionToEnd:"Cannot end session, no active session found"},ValidationMessages:{ModifyIdentityRequestUserIdentitiesPresent:"identityRequests to modify require userIdentities to be present. Request not sent to server. Please fix and try again",IdentityRequesetInvalidKey:"There is an invalid key on your identityRequest object. It can only contain a `userIdentities` object and a `onUserAlias` function. Request not sent to server. Please fix and try again.",OnUserAliasType:"The onUserAlias value must be a function.",UserIdentities:"The userIdentities key must be an object with keys of identityTypes and values of strings. Request not sent to server. Please fix and try again.",UserIdentitiesInvalidKey:"There is an invalid identity key on your `userIdentities` object within the identityRequest. Request not sent to server. Please fix and try again.",UserIdentitiesInvalidValues:"All user identity values must be strings or null. Request not sent to server. Please fix and try again.",AliasMissingMpid:"Alias Request must contain both a destinationMpid and a sourceMpid",AliasNonUniqueMpid:"Alias Request's destinationMpid and sourceMpid must be unique",AliasMissingTime:"Alias Request must have both a startTime and an endTime",AliasStartBeforeEndTime:"Alias Request's endTime must be later than its startTime"}},NativeSdkPaths:{LogEvent:"logEvent",SetUserTag:"setUserTag",RemoveUserTag:"removeUserTag",SetUserAttribute:"setUserAttribute",RemoveUserAttribute:"removeUserAttribute",SetSessionAttribute:"setSessionAttribute",AddToCart:"addToCart",RemoveFromCart:"removeFromCart",ClearCart:"clearCart",LogOut:"logOut",SetUserAttributeList:"setUserAttributeList",RemoveAllUserAttributes:"removeAllUserAttributes",GetUserAttributesLists:"getUserAttributesLists",GetAllUserAttributes:"getAllUserAttributes",Identify:"identify",Logout:"logout",Login:"login",Modify:"modify",Alias:"aliasUsers",Upload:"upload"},StorageNames:{localStorageName:"mprtcl-api",localStorageNameV3:"mprtcl-v3",cookieName:"mprtcl-api",cookieNameV2:"mprtcl-v2",cookieNameV3:"mprtcl-v3",localStorageNameV4:"mprtcl-v4",localStorageProductsV4:"mprtcl-prodv4",cookieNameV4:"mprtcl-v4",currentStorageName:"mprtcl-v4",currentStorageProductsName:"mprtcl-prodv4"},DefaultConfig:{cookieDomain:null,cookieExpiration:365,logLevel:null,timeout:300,sessionTimeout:30,maxProducts:20,forwarderStatsTimeout:5e3,integrationDelayTimeout:5e3,maxCookieSize:3e3,aliasMaxWindow:90,uploadInterval:0// Maximum milliseconds in between batch uploads, below 500 will mean immediate upload. The server returns this as a string, but we are using it as a number internally
|
|
21
21
|
},DefaultBaseUrls:{v1SecureServiceUrl:"jssdks.mparticle.com/v1/JS/",v2SecureServiceUrl:"jssdks.mparticle.com/v2/JS/",v3SecureServiceUrl:"jssdks.mparticle.com/v3/JS/",configUrl:"jssdkcdns.mparticle.com/JS/v2/",identityUrl:"identity.mparticle.com/v1/",aliasUrl:"jssdks.mparticle.com/v1/identity/",userAudienceUrl:"nativesdks.mparticle.com/v1/"},Base64CookieKeys:{csm:1,sa:1,ss:1,ua:1,ui:1,csd:1,ia:1,con:1},// https://go.mparticle.com/work/SQDSDKS-6039
|
|
@@ -127,7 +127,7 @@ var Messages$9=Constants.Messages,createCookieString=function(a){return replaceC
|
|
|
127
127
|
"".concat(1e7,"-").concat(1e3,"-").concat(4e3,"-").concat(8e3,"-").concat(1e11).replace(/[018]/g,// zeroes, ones, and eights with
|
|
128
128
|
generateUniqueId// random hex digits
|
|
129
129
|
)},getRampNumber=function(a){if(!a)return 100;var b=generateHash(a);return Math.abs(b%100)+1},isObject=function(a){var b=Object.prototype.toString.call(a);return "[object Object]"===b||"[object Error]"===b},parseNumber=function(a){if(isNaN(a)||!isFinite(a))return 0;var b=parseFloat(a);return isNaN(b)?0:b},parseStringOrNumber=function(a){return isStringOrNumber(a)?a:null},replaceCommasWithPipes=function(a){return a.replace(/,/g,"|")},replacePipesWithCommas=function(a){return a.replace(/\|/g,",")},replaceApostrophesWithQuotes=function(a){return a.replace(/\'/g,"\"")},replaceQuotesWithApostrophes=function(a){return a.replace(/\"/g,"'")},replaceMPID=function(a,b){return a.replace("%%mpid%%",b)},replaceAmpWithAmpersand=function(a){return a.replace(/&/g,"&")},createCookieSyncUrl=function(a,b,c){var d=replaceAmpWithAmpersand(b),e=c?replaceAmpWithAmpersand(c):null,f=replaceMPID(d,a),g=e?replaceMPID(e,a):"";return f+encodeURIComponent(g)},returnConvertedBoolean=function(a){return "false"!==a&&"0"!==a&&!!a},decoded=function(a){return decodeURIComponent(a.replace(/\+/g," "))},converted=function(a){return 0===a.indexOf("\"")&&(a=a.slice(1,-1).replace(/\\"/g,"\"").replace(/\\\\/g,"\\")),a},isString=function(a){return "string"==typeof a},isNumber=function(a){return "number"==typeof a},isBoolean=function(a){return "boolean"==typeof a},isFunction=function(a){return "function"==typeof a},isValidCustomFlagProperty=function(a){return isNumber(a)||isString(a)||isBoolean(a)},toDataPlanSlug=function(a){// Make sure we are only acting on strings or numbers
|
|
130
|
-
return isStringOrNumber(a)?a.toString().toLowerCase().replace(/[^0-9a-zA-Z]+/g,"_"):""},isDataPlanSlug=function(a){return a===toDataPlanSlug(a)},isStringOrNumber=function(a){return isString(a)||isNumber(a)},isEmpty=function(a){return null==a||!(Object.keys(a)||a).length},moveElementToEnd=function(a,b){return a.slice(0,b).concat(a.slice(b+1),a[b])},queryStringParser=function(a,b){void 0===b&&(b=[]);var c,d={};if(!a)return d;if("undefined"!=typeof URL&&"undefined"!=typeof URLSearchParams){var e=new URL(a);c=new URLSearchParams(e.search);}else c=queryStringParserFallback(a);return isEmpty(b)?c.forEach(function(a,b){d[b]=a;}):b.forEach(function(a){var b=c.get(a);b&&(d[a]=b);}),d},queryStringParserFallback=function(a){var b={},c=a.split("?")[1]||"",d=c.split("&");return d.forEach(function(a){var c=a.split("="),d=c[0],e=c
|
|
130
|
+
return isStringOrNumber(a)?a.toString().toLowerCase().replace(/[^0-9a-zA-Z]+/g,"_"):""},isDataPlanSlug=function(a){return a===toDataPlanSlug(a)},isStringOrNumber=function(a){return isString(a)||isNumber(a)},isEmpty=function(a){return null==a||!(Object.keys(a)||a).length},moveElementToEnd=function(a,b){return a.slice(0,b).concat(a.slice(b+1),a[b])},queryStringParser=function(a,b){void 0===b&&(b=[]);var c,d={};if(!a)return d;if("undefined"!=typeof URL&&"undefined"!=typeof URLSearchParams){var e=new URL(a);c=new URLSearchParams(e.search);}else c=queryStringParserFallback(a);return isEmpty(b)?c.forEach(function(a,b){d[b]=a;}):b.forEach(function(a){var b=c.get(a);b&&(d[a]=b);}),d},queryStringParserFallback=function(a){var b={},c=a.split("?")[1]||"",d=c.split("&");return d.forEach(function(a){var c=a.split("="),d=c[0],e=c.slice(1),f=e.join("=");if(d&&void 0!==f)try{b[d]=decodeURIComponent(f||"");}catch(a){console.error("Failed to decode value for key ".concat(d,": ").concat(a));}}),{get:function get(a){return b[a]},forEach:function forEach(a){for(var c in b)b.hasOwnProperty(c)&&a(b[c],c);}}},getCookies=function(a){// Helper function to parse cookies from document.cookie
|
|
131
131
|
var b=function parseCookies(){return "undefined"==typeof window?[]:window.document.cookie.split(";").map(function(a){return a.trim()})}();// Helper function to filter cookies by keys
|
|
132
132
|
// Parse cookies from document.cookie
|
|
133
133
|
// Filter cookies by keys if provided
|
|
@@ -515,7 +515,7 @@ this.convertTransactionAttributesToProductAction=function(a,b){a.hasOwnProperty(
|
|
|
515
515
|
return (a.Logger.verbose(Messages$5.InformationMessages.StartingLogCommerceEvent),a._Helpers.canLog())?(d=a._ServerModel.createEventObject({messageType:Types.MessageType.Commerce,sourceMessageId:null===c||void 0===c?void 0:c.sourceMessageId}),d.EventName="eCommerce - ",d.CurrencyCode=a._Store.currencyCode,d.ShoppingCart=[],d.CustomFlags=e(d.CustomFlags,b),d):(a.Logger.verbose(Messages$5.InformationMessages.AbandonLogEvent),null)},this.sanitizeAmount=function(b,c){if(!a._Helpers.Validators.isStringOrNumber(b)){var d=[c,"must be of type number. A",_typeof$1(b),"was passed. Converting to 0"].join(" ");return a.Logger.warning(d),0}// if amount is a string, it will be parsed into a number if possible, or set to 0
|
|
516
516
|
return a._Helpers.parseNumber(b)};}
|
|
517
517
|
|
|
518
|
-
var ForegroundTimeTracker=/** @class */function(){function a(a){this.isTrackerActive=!1,this.localStorageName="",this.startTime=0,this.totalTime=0,this.localStorageName="
|
|
518
|
+
var ForegroundTimeTracker=/** @class */function(){function a(a){this.isTrackerActive=!1,this.localStorageName="",this.startTime=0,this.totalTime=0,this.localStorageName="mprtcl-tos-".concat(a),this.timerVault=new LocalStorageVault(this.localStorageName),this.loadTimeFromStorage(),this.addHandlers(),!1===document.hidden&&this.startTracking();}return a.prototype.addHandlers=function(){var a=this;// when user switches tabs or minimizes the window
|
|
519
519
|
document.addEventListener("visibilitychange",function(){return a.handleVisibilityChange()}),window.addEventListener("blur",function(){return a.handleWindowBlur()}),window.addEventListener("focus",function(){return a.handleWindowFocus()}),window.addEventListener("storage",function(b){return a.syncAcrossTabs(b)}),window.addEventListener("beforeunload",function(){return a.updateTimeInPersistence()});},a.prototype.handleVisibilityChange=function(){document.hidden?this.stopTracking():this.startTracking();},a.prototype.handleWindowBlur=function(){this.isTrackerActive&&this.stopTracking();},a.prototype.handleWindowFocus=function(){this.isTrackerActive||this.startTracking();},a.prototype.syncAcrossTabs=function(a){if(a.key===this.localStorageName&&null!==a.newValue){var b=parseFloat(a.newValue)||0;this.totalTime=b;}},a.prototype.updateTimeInPersistence=function(){this.isTrackerActive&&this.timerVault.store(Math.round(this.totalTime));},a.prototype.loadTimeFromStorage=function(){var a=this.timerVault.retrieve();isNumber(a)&&null!==a&&(this.totalTime=a);},a.prototype.startTracking=function(){document.hidden||(this.startTime=Math.floor(performance.now()),this.isTrackerActive=!0);},a.prototype.stopTracking=function(){this.isTrackerActive&&(this.setTotalTime(),this.updateTimeInPersistence(),this.isTrackerActive=!1);},a.prototype.setTotalTime=function(){if(this.isTrackerActive){var a=Math.floor(performance.now());this.totalTime+=a-this.startTime,this.startTime=a;}},a.prototype.getTimeInForeground=function(){return this.setTotalTime(),this.updateTimeInPersistence(),this.totalTime},a.prototype.resetTimer=function(){this.totalTime=0,this.updateTimeInPersistence();},a}();
|
|
520
520
|
|
|
521
521
|
function createSDKConfig(a){// TODO: Refactor to create a default config object
|
|
@@ -1046,12 +1046,12 @@ this.appendUserInfo=function(b,c){if(c){if(!b)return c.MPID=null,c.ConsentState=
|
|
|
1046
1046
|
// tracked. If this is an `optOut` Event, we set `optOut` to the inverse of the SDK's
|
|
1047
1047
|
// `isEnabled` boolean which is controlled via `MPInstanceManager.setOptOut`.
|
|
1048
1048
|
// TODO: Why is Webview Bridge Enabled or Opt Out necessary here?
|
|
1049
|
-
if(a._Store.sessionId||c.messageType===Types.MessageType.OptOut||a._Store.webviewBridgeEnabled){var i=__assign({},c.customFlags);// https://go.mparticle.com/work/SQDSDKS-5053
|
|
1050
|
-
if(a._Helpers.getFeatureFlag&&a._Helpers.getFeatureFlag(Constants.FeatureFlags.CaptureIntegrationSpecificIds)){a._IntegrationCapture.capture();var
|
|
1049
|
+
if(a._Store.sessionId||c.messageType===Types.MessageType.OptOut||a._Store.webviewBridgeEnabled){var i=__assign({},c.customFlags),j=a._Store.integrationAttributes;// https://go.mparticle.com/work/SQDSDKS-5053
|
|
1050
|
+
if(a._Helpers.getFeatureFlag&&a._Helpers.getFeatureFlag(Constants.FeatureFlags.CaptureIntegrationSpecificIds)){a._IntegrationCapture.capture();var k=a._IntegrationCapture.getClickIdsAsCustomFlags();i=__assign(__assign({},k),i);var l=a._IntegrationCapture.getClickIdsAsIntegrationAttributes();j=__assign(__assign({},l),j);}g=c.hasOwnProperty("toEventAPIObject")?c.toEventAPIObject():{// This is an artifact from v2 events where SessionStart/End and AST event
|
|
1051
1051
|
// names are numbers (1, 2, or 10), but going forward with v3, these lifecycle
|
|
1052
1052
|
// events do not have names, but are denoted by their `event_type`
|
|
1053
1053
|
EventName:c.name||c.messageType,EventCategory:c.eventType,EventAttributes:a._Helpers.sanitizeAttributes(c.data,c.name),ActiveTimeOnSite:null===(e=a._timeOnSiteTimer)||void 0===e?void 0:e.getTimeInForeground(),SourceMessageId:c.sourceMessageId||a._Helpers.generateUniqueId(),EventDataType:c.messageType,CustomFlags:i,UserAttributeChanges:c.userAttributeChanges,UserIdentityChanges:c.userIdentityChanges},c.messageType!==Types.MessageType.SessionEnd&&(a._Store.dateLastEventSent=new Date),f={// FIXME: Deprecate when we get rid of V2
|
|
1054
|
-
Store:a._Store.serverSettings,SDKVersion:Constants.sdkVersion,SessionId:a._Store.sessionId,SessionStartDate:a._Store.sessionStartDate?a._Store.sessionStartDate.getTime():0,Debug:a._Store.SDKConfig.isDevelopmentMode,Location:a._Store.currentPosition,OptOut:h,ExpandedEventCount:0,AppVersion:a.getAppVersion(),AppName:a.getAppName(),Package:a._Store.SDKConfig["package"],ClientGeneratedId:a._Store.clientId,DeviceId:a._Store.deviceId,IntegrationAttributes:
|
|
1054
|
+
Store:a._Store.serverSettings,SDKVersion:Constants.sdkVersion,SessionId:a._Store.sessionId,SessionStartDate:a._Store.sessionStartDate?a._Store.sessionStartDate.getTime():0,Debug:a._Store.SDKConfig.isDevelopmentMode,Location:a._Store.currentPosition,OptOut:h,ExpandedEventCount:0,AppVersion:a.getAppVersion(),AppName:a.getAppName(),Package:a._Store.SDKConfig["package"],ClientGeneratedId:a._Store.clientId,DeviceId:a._Store.deviceId,IntegrationAttributes:j,CurrencyCode:a._Store.currencyCode,DataPlan:a._Store.SDKConfig.dataPlan?a._Store.SDKConfig.dataPlan:{}},g.EventDataType===MessageType.AppStateTransition&&(g.IsFirstRun=a._Store.isFirstRun,g.LaunchReferral=window.location.href||null),g.CurrencyCode=a._Store.currencyCode;var m=d||a.Identity.getCurrentUser();return b.appendUserInfo(m,g),c.messageType===Types.MessageType.SessionEnd&&(g.SessionLength=a._Store.dateLastEventSent.getTime()-a._Store.sessionStartDate.getTime(),g.currentSessionMPIDs=a._Store.currentSessionMPIDs,g.EventAttributes=a._Store.sessionAttributes,a._Store.currentSessionMPIDs=[],a._Store.sessionStartDate=null),f.Timestamp=a._Store.dateLastEventSent.getTime(),a._Helpers.extend({},g,f)}return null},this.convertEventToV2DTO=function(c){var d={n:c.EventName,et:c.EventCategory,ua:c.UserAttributes,ui:c.UserIdentities,ia:c.IntegrationAttributes,str:c.Store,attrs:c.EventAttributes,sdk:c.SDKVersion,sid:c.SessionId,sl:c.SessionLength,ssd:c.SessionStartDate,dt:c.EventDataType,dbg:c.Debug,ct:c.Timestamp,lc:c.Location,o:c.OptOut,eec:c.ExpandedEventCount,av:c.AppVersion,cgid:c.ClientGeneratedId,das:c.DeviceId,mpid:c.MPID,smpids:c.currentSessionMPIDs};c.DataPlan&&c.DataPlan.PlanId&&(d.dp_id=c.DataPlan.PlanId,c.DataPlan.PlanVersion&&(d.dp_v=c.DataPlan.PlanVersion));var e=b.convertToConsentStateV2DTO(c.ConsentState);return e&&(d.con=e),c.EventDataType===MessageType.AppStateTransition&&(d.fr=c.IsFirstRun,d.iu=!1,d.at=ApplicationTransitionType.AppInit,d.lr=c.LaunchReferral,d.attrs=null),c.CustomFlags&&convertCustomFlags(c,d),c.EventDataType===MessageType.Commerce?(d.cu=c.CurrencyCode,c.ShoppingCart&&(d.sc={pl:convertProductListToV2DTO(c.ShoppingCart.ProductList)}),c.ProductAction?d.pd={an:c.ProductAction.ProductActionType,cs:a._Helpers.parseNumber(c.ProductAction.CheckoutStep),co:c.ProductAction.CheckoutOptions,pl:convertProductListToV2DTO(c.ProductAction.ProductList),ti:c.ProductAction.TransactionId,ta:c.ProductAction.Affiliation,tcc:c.ProductAction.CouponCode,tr:a._Helpers.parseNumber(c.ProductAction.TotalAmount),ts:a._Helpers.parseNumber(c.ProductAction.ShippingAmount),tt:a._Helpers.parseNumber(c.ProductAction.TaxAmount)}:c.PromotionAction?d.pm={an:c.PromotionAction.PromotionActionType,pl:c.PromotionAction.PromotionList.map(function(a){return {id:a.Id,nm:a.Name,cr:a.Creative,ps:a.Position?a.Position:0}})}:c.ProductImpressions&&(d.pi=c.ProductImpressions.map(function(a){return {pil:a.ProductImpressionList,pl:convertProductListToV2DTO(a.ProductList)}}))):c.EventDataType===MessageType.Profile&&(d.pet=c.ProfileMessageType),d};}
|
|
1055
1055
|
|
|
1056
1056
|
function forwardingStatsUploader(a){function b(){var b=a._Forwarders.getForwarderStatsQueue(),c=a._Persistence.forwardingStatsBatches.uploadsTable,d=Date.now();for(var e in b.length&&(c[d]={uploading:!1,data:b},a._Forwarders.setForwarderStatsQueue([])),c)(function(b){if(c.hasOwnProperty(b)&&!1===c[b].uploading){var d=function(){4===e.readyState&&(200===e.status||202===e.status?(a.Logger.verbose("Successfully sent "+e.statusText+" from server"),delete c[b]):"4"===e.status.toString()[0]?429!==e.status&&delete c[b]:c[b].uploading=!1);},e=a._Helpers.createXHR(d),f=c[b].data;c[b].uploading=!0,a._APIClient.sendBatchForwardingStatsToServer(f,e);}})(e);}this.startForwardingStatsTimer=function(){mParticle._forwardingStatsTimer=setInterval(function(){b();},a._Store.SDKConfig.forwarderStatsTimeout);};}
|
|
1057
1057
|
|
|
@@ -1378,12 +1378,23 @@ var facebookClickIdProcessor=function(a,b,c){if(!a||!b)return "";var d=null===b|
|
|
|
1378
1378
|
var h=c||Date.now();return "fb.".concat(g,".").concat(h,".").concat(a)};// Integration outputs are used to determine how click ids are used within the SDK
|
|
1379
1379
|
// CUSTOM_FLAGS are sent out when an Event is created via ServerModel.createEventObject
|
|
1380
1380
|
// PARTNER_IDENTITIES are sent out in a Batch when a group of events are converted to a Batch
|
|
1381
|
-
|
|
1381
|
+
// INTEGRATION_ATTRIBUTES are stored initially on the SDKEvent level but then is added to the Batch when the batch is created
|
|
1382
|
+
var IntegrationOutputs={CUSTOM_FLAGS:"custom_flags",PARTNER_IDENTITIES:"partner_identities",INTEGRATION_ATTRIBUTES:"integration_attributes"},integrationMapping={// Facebook / Meta
|
|
1382
1383
|
fbclid:{mappedKey:"Facebook.ClickId",processor:facebookClickIdProcessor,output:IntegrationOutputs.CUSTOM_FLAGS},_fbp:{mappedKey:"Facebook.BrowserId",output:IntegrationOutputs.CUSTOM_FLAGS},_fbc:{mappedKey:"Facebook.ClickId",output:IntegrationOutputs.CUSTOM_FLAGS},// Google
|
|
1383
|
-
gclid:{mappedKey:"GoogleEnhancedConversions.Gclid",output:IntegrationOutputs.CUSTOM_FLAGS},gbraid:{mappedKey:"GoogleEnhancedConversions.Gbraid",output:IntegrationOutputs.CUSTOM_FLAGS},wbraid:{mappedKey:"GoogleEnhancedConversions.Wbraid",output:IntegrationOutputs.CUSTOM_FLAGS},//
|
|
1384
|
-
|
|
1384
|
+
gclid:{mappedKey:"GoogleEnhancedConversions.Gclid",output:IntegrationOutputs.CUSTOM_FLAGS},gbraid:{mappedKey:"GoogleEnhancedConversions.Gbraid",output:IntegrationOutputs.CUSTOM_FLAGS},wbraid:{mappedKey:"GoogleEnhancedConversions.Wbraid",output:IntegrationOutputs.CUSTOM_FLAGS},// Rokt
|
|
1385
|
+
// https://docs.rokt.com/developers/integration-guides/web/advanced/rokt-id-tag/
|
|
1386
|
+
rtid:{mappedKey:"passbackconversiontrackingid",output:IntegrationOutputs.INTEGRATION_ATTRIBUTES,moduleId:1277},RoktTransactionId:{mappedKey:"passbackconversiontrackingid",output:IntegrationOutputs.INTEGRATION_ATTRIBUTES,moduleId:1277},// TIKTOK
|
|
1387
|
+
ttclid:{mappedKey:"TikTok.Callback",output:IntegrationOutputs.CUSTOM_FLAGS},_ttp:{mappedKey:"tiktok_cookie_id",output:IntegrationOutputs.PARTNER_IDENTITIES}},IntegrationCapture=/** @class */function(){function a(){this.initialTimestamp=Date.now(),this.filteredPartnerIdentityMappings=this.filterMappings(IntegrationOutputs.PARTNER_IDENTITIES),this.filteredCustomFlagMappings=this.filterMappings(IntegrationOutputs.CUSTOM_FLAGS),this.filteredIntegrationAttributeMappings=this.filterMappings(IntegrationOutputs.INTEGRATION_ATTRIBUTES);}/**
|
|
1385
1388
|
* Captures Integration Ids from cookies and query params and stores them in clickIds object
|
|
1386
|
-
*/return a.prototype.capture=function(){var a=this.captureQueryParams()||{},b=this.captureCookies()||{};a.fbclid&&b._fbc&&delete b._fbc,this.clickIds=__assign(__assign(__assign({},this.clickIds),a),b);},a.prototype.captureCookies=function(){var a=getCookies(Object.keys(integrationMapping));return this.applyProcessors(a)},a.prototype.captureQueryParams=function(){var a=this.getQueryParams();return this.applyProcessors(a,getHref(),this.initialTimestamp)},a.prototype.getQueryParams=function(){return queryStringParser(getHref(),Object.keys(integrationMapping))},a.prototype.getClickIdsAsCustomFlags=function(){return this.getClickIds(this.clickIds,this.filteredCustomFlagMappings)},a.prototype.getClickIdsAsPartnerIdentities=function(){return this.getClickIds(this.clickIds,this.filteredPartnerIdentityMappings)},a.prototype.
|
|
1389
|
+
*/return a.prototype.capture=function(){var a=this.captureQueryParams()||{},b=this.captureCookies()||{},c=this.captureLocalStorage()||{};a.fbclid&&b._fbc&&delete b._fbc,a.rtid&&c.RoktTransactionId&&b.RoktTransactionId?(delete c.RoktTransactionId,delete b.RoktTransactionId):a.rtid&&c.RoktTransactionId?delete c.RoktTransactionId:a.rtid&&b.RoktTransactionId?delete b.RoktTransactionId:c.RoktTransactionId&&b.RoktTransactionId&&delete b.RoktTransactionId,this.clickIds=__assign(__assign(__assign(__assign({},this.clickIds),a),c),b);},a.prototype.captureCookies=function(){var a=getCookies(Object.keys(integrationMapping));return this.applyProcessors(a,getHref(),this.initialTimestamp)},a.prototype.captureQueryParams=function(){var a=this.getQueryParams();return this.applyProcessors(a,getHref(),this.initialTimestamp)},a.prototype.captureLocalStorage=function(){var a={};for(var b in integrationMapping){var c=localStorage.getItem(b);c&&(a[b]=c);}return this.applyProcessors(a,getHref(),this.initialTimestamp)},a.prototype.getQueryParams=function(){return queryStringParser(getHref(),Object.keys(integrationMapping))},a.prototype.getClickIdsAsCustomFlags=function(){return this.getClickIds(this.clickIds,this.filteredCustomFlagMappings)},a.prototype.getClickIdsAsPartnerIdentities=function(){return this.getClickIds(this.clickIds,this.filteredPartnerIdentityMappings)},a.prototype.getClickIdsAsIntegrationAttributes=function(){var a,b,c,d={};// Integration IDs are stored in the following format:
|
|
1390
|
+
// {
|
|
1391
|
+
// "integration_attributes": {
|
|
1392
|
+
// "<moduleId>": {
|
|
1393
|
+
// "mappedKey": "clickIdValue"
|
|
1394
|
+
// }
|
|
1395
|
+
// }
|
|
1396
|
+
// }
|
|
1397
|
+
for(var e in this.clickIds)if(this.clickIds.hasOwnProperty(e)){var f=this.clickIds[e],g=null===(b=this.filteredIntegrationAttributeMappings[e])||void 0===b?void 0:b.mappedKey;if(!isEmpty(g)){var h=null===(c=this.filteredIntegrationAttributeMappings[e])||void 0===c?void 0:c.moduleId;h&&!d[h]&&(d[h]=(a={},a[g]=f,a));}}return d},a.prototype.getClickIds=function(a,b){var c,d={};if(!a)return d;for(var e in a)if(a.hasOwnProperty(e)){var f=a[e],g=null===(c=b[e])||void 0===c?void 0:c.mappedKey;isEmpty(g)||(d[g]=f);}return d},a.prototype.applyProcessors=function(a,b,c){var d,e={};for(var f in a)if(a.hasOwnProperty(f)){var g=a[f],h=null===(d=integrationMapping[f])||void 0===d?void 0:d.processor;e[f]=h?h(g,b,c):g;}return e},a.prototype.filterMappings=function(a){var b={};for(var c in integrationMapping)integrationMapping[c].output===a&&(b[c]=integrationMapping[c]);return b},a}();
|
|
1387
1398
|
|
|
1388
1399
|
var Messages=Constants.Messages,HTTPCodes=Constants.HTTPCodes,FeatureFlags=Constants.FeatureFlags,ReportBatching=FeatureFlags.ReportBatching,CaptureIntegrationSpecificIds=FeatureFlags.CaptureIntegrationSpecificIds,StartingInitialization=Messages.InformationMessages.StartingInitialization;/**
|
|
1389
1400
|
* <p>All of the following methods can be called on the primary mParticle class. In version 2.10.0, we introduced <a href="https://docs.mparticle.com/developers/sdk/web/multiple-instances/">multiple instances</a>. If you are using multiple instances (self hosted environments only), you should call these methods on each instance.</p>
|
package/dist/mparticle.js
CHANGED
|
@@ -203,7 +203,7 @@ var mParticle = (function () {
|
|
|
203
203
|
Base64: Base64$1
|
|
204
204
|
};
|
|
205
205
|
|
|
206
|
-
var version = "2.33.
|
|
206
|
+
var version = "2.33.1";
|
|
207
207
|
|
|
208
208
|
var Constants = {
|
|
209
209
|
sdkVersion: version,
|
|
@@ -713,9 +713,14 @@ var mParticle = (function () {
|
|
|
713
713
|
pairs.forEach(function (pair) {
|
|
714
714
|
var _a = pair.split('='),
|
|
715
715
|
key = _a[0],
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
716
|
+
valueParts = _a.slice(1);
|
|
717
|
+
var value = valueParts.join('=');
|
|
718
|
+
if (key && value !== undefined) {
|
|
719
|
+
try {
|
|
720
|
+
params[key] = decodeURIComponent(value || '');
|
|
721
|
+
} catch (e) {
|
|
722
|
+
console.error("Failed to decode value for key ".concat(key, ": ").concat(e));
|
|
723
|
+
}
|
|
719
724
|
}
|
|
720
725
|
});
|
|
721
726
|
return {
|
|
@@ -3883,7 +3888,7 @@ var mParticle = (function () {
|
|
|
3883
3888
|
this.localStorageName = '';
|
|
3884
3889
|
this.startTime = 0;
|
|
3885
3890
|
this.totalTime = 0;
|
|
3886
|
-
this.localStorageName = "
|
|
3891
|
+
this.localStorageName = "mprtcl-tos-".concat(timerKey);
|
|
3887
3892
|
this.timerVault = new LocalStorageVault(this.localStorageName);
|
|
3888
3893
|
this.loadTimeFromStorage();
|
|
3889
3894
|
this.addHandlers();
|
|
@@ -6649,6 +6654,7 @@ var mParticle = (function () {
|
|
|
6649
6654
|
// TODO: Why is Webview Bridge Enabled or Opt Out necessary here?
|
|
6650
6655
|
if (mpInstance._Store.sessionId || event.messageType === Types.MessageType.OptOut || mpInstance._Store.webviewBridgeEnabled) {
|
|
6651
6656
|
var customFlags = __assign({}, event.customFlags);
|
|
6657
|
+
var integrationAttributes = mpInstance._Store.integrationAttributes;
|
|
6652
6658
|
// https://go.mparticle.com/work/SQDSDKS-5053
|
|
6653
6659
|
if (mpInstance._Helpers.getFeatureFlag && mpInstance._Helpers.getFeatureFlag(Constants.FeatureFlags.CaptureIntegrationSpecificIds)) {
|
|
6654
6660
|
// Attempt to recapture click IDs in case a third party integration
|
|
@@ -6656,6 +6662,8 @@ var mParticle = (function () {
|
|
|
6656
6662
|
mpInstance._IntegrationCapture.capture();
|
|
6657
6663
|
var transformedClickIDs = mpInstance._IntegrationCapture.getClickIdsAsCustomFlags();
|
|
6658
6664
|
customFlags = __assign(__assign({}, transformedClickIDs), customFlags);
|
|
6665
|
+
var transformedIntegrationAttributes = mpInstance._IntegrationCapture.getClickIdsAsIntegrationAttributes();
|
|
6666
|
+
integrationAttributes = __assign(__assign({}, transformedIntegrationAttributes), integrationAttributes);
|
|
6659
6667
|
}
|
|
6660
6668
|
if (event.hasOwnProperty('toEventAPIObject')) {
|
|
6661
6669
|
eventObject = event.toEventAPIObject();
|
|
@@ -6694,7 +6702,7 @@ var mParticle = (function () {
|
|
|
6694
6702
|
Package: mpInstance._Store.SDKConfig["package"],
|
|
6695
6703
|
ClientGeneratedId: mpInstance._Store.clientId,
|
|
6696
6704
|
DeviceId: mpInstance._Store.deviceId,
|
|
6697
|
-
IntegrationAttributes:
|
|
6705
|
+
IntegrationAttributes: integrationAttributes,
|
|
6698
6706
|
CurrencyCode: mpInstance._Store.currencyCode,
|
|
6699
6707
|
DataPlan: mpInstance._Store.SDKConfig.dataPlan ? mpInstance._Store.SDKConfig.dataPlan : {}
|
|
6700
6708
|
};
|
|
@@ -9312,9 +9320,11 @@ var mParticle = (function () {
|
|
|
9312
9320
|
// Integration outputs are used to determine how click ids are used within the SDK
|
|
9313
9321
|
// CUSTOM_FLAGS are sent out when an Event is created via ServerModel.createEventObject
|
|
9314
9322
|
// PARTNER_IDENTITIES are sent out in a Batch when a group of events are converted to a Batch
|
|
9323
|
+
// INTEGRATION_ATTRIBUTES are stored initially on the SDKEvent level but then is added to the Batch when the batch is created
|
|
9315
9324
|
var IntegrationOutputs = {
|
|
9316
9325
|
CUSTOM_FLAGS: 'custom_flags',
|
|
9317
|
-
PARTNER_IDENTITIES: 'partner_identities'
|
|
9326
|
+
PARTNER_IDENTITIES: 'partner_identities',
|
|
9327
|
+
INTEGRATION_ATTRIBUTES: 'integration_attributes'
|
|
9318
9328
|
};
|
|
9319
9329
|
var integrationMapping = {
|
|
9320
9330
|
// Facebook / Meta
|
|
@@ -9344,6 +9354,18 @@ var mParticle = (function () {
|
|
|
9344
9354
|
mappedKey: 'GoogleEnhancedConversions.Wbraid',
|
|
9345
9355
|
output: IntegrationOutputs.CUSTOM_FLAGS
|
|
9346
9356
|
},
|
|
9357
|
+
// Rokt
|
|
9358
|
+
// https://docs.rokt.com/developers/integration-guides/web/advanced/rokt-id-tag/
|
|
9359
|
+
rtid: {
|
|
9360
|
+
mappedKey: 'passbackconversiontrackingid',
|
|
9361
|
+
output: IntegrationOutputs.INTEGRATION_ATTRIBUTES,
|
|
9362
|
+
moduleId: 1277
|
|
9363
|
+
},
|
|
9364
|
+
RoktTransactionId: {
|
|
9365
|
+
mappedKey: 'passbackconversiontrackingid',
|
|
9366
|
+
output: IntegrationOutputs.INTEGRATION_ATTRIBUTES,
|
|
9367
|
+
moduleId: 1277
|
|
9368
|
+
},
|
|
9347
9369
|
// TIKTOK
|
|
9348
9370
|
ttclid: {
|
|
9349
9371
|
mappedKey: 'TikTok.Callback',
|
|
@@ -9360,6 +9382,7 @@ var mParticle = (function () {
|
|
|
9360
9382
|
// Cache filtered mappings for faster access
|
|
9361
9383
|
this.filteredPartnerIdentityMappings = this.filterMappings(IntegrationOutputs.PARTNER_IDENTITIES);
|
|
9362
9384
|
this.filteredCustomFlagMappings = this.filterMappings(IntegrationOutputs.CUSTOM_FLAGS);
|
|
9385
|
+
this.filteredIntegrationAttributeMappings = this.filterMappings(IntegrationOutputs.INTEGRATION_ATTRIBUTES);
|
|
9363
9386
|
}
|
|
9364
9387
|
/**
|
|
9365
9388
|
* Captures Integration Ids from cookies and query params and stores them in clickIds object
|
|
@@ -9367,19 +9390,33 @@ var mParticle = (function () {
|
|
|
9367
9390
|
IntegrationCapture.prototype.capture = function () {
|
|
9368
9391
|
var queryParams = this.captureQueryParams() || {};
|
|
9369
9392
|
var cookies = this.captureCookies() || {};
|
|
9393
|
+
var localStorage = this.captureLocalStorage() || {};
|
|
9370
9394
|
// Exclude _fbc if fbclid is present
|
|
9371
9395
|
// https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/fbp-and-fbc#retrieve-from-fbclid-url-query-parameter
|
|
9372
9396
|
if (queryParams['fbclid'] && cookies['_fbc']) {
|
|
9373
9397
|
delete cookies['_fbc'];
|
|
9374
9398
|
}
|
|
9375
|
-
|
|
9399
|
+
// If both rtid and RoktTransactionId are present, prioritize rtid
|
|
9400
|
+
// If RoktTransactionId is present in both cookies and localStorage,
|
|
9401
|
+
// prioritize localStorage
|
|
9402
|
+
if (queryParams['rtid'] && localStorage['RoktTransactionId'] && cookies['RoktTransactionId']) {
|
|
9403
|
+
delete localStorage['RoktTransactionId'];
|
|
9404
|
+
delete cookies['RoktTransactionId'];
|
|
9405
|
+
} else if (queryParams['rtid'] && localStorage['RoktTransactionId']) {
|
|
9406
|
+
delete localStorage['RoktTransactionId'];
|
|
9407
|
+
} else if (queryParams['rtid'] && cookies['RoktTransactionId']) {
|
|
9408
|
+
delete cookies['RoktTransactionId'];
|
|
9409
|
+
} else if (localStorage['RoktTransactionId'] && cookies['RoktTransactionId']) {
|
|
9410
|
+
delete cookies['RoktTransactionId'];
|
|
9411
|
+
}
|
|
9412
|
+
this.clickIds = __assign(__assign(__assign(__assign({}, this.clickIds), queryParams), localStorage), cookies);
|
|
9376
9413
|
};
|
|
9377
9414
|
/**
|
|
9378
9415
|
* Captures cookies based on the integration ID mapping.
|
|
9379
9416
|
*/
|
|
9380
9417
|
IntegrationCapture.prototype.captureCookies = function () {
|
|
9381
9418
|
var cookies = getCookies(Object.keys(integrationMapping));
|
|
9382
|
-
return this.applyProcessors(cookies);
|
|
9419
|
+
return this.applyProcessors(cookies, getHref(), this.initialTimestamp);
|
|
9383
9420
|
};
|
|
9384
9421
|
/**
|
|
9385
9422
|
* Captures query parameters based on the integration ID mapping.
|
|
@@ -9388,6 +9425,19 @@ var mParticle = (function () {
|
|
|
9388
9425
|
var queryParams = this.getQueryParams();
|
|
9389
9426
|
return this.applyProcessors(queryParams, getHref(), this.initialTimestamp);
|
|
9390
9427
|
};
|
|
9428
|
+
/**
|
|
9429
|
+
* Captures local storage based on the integration ID mapping.
|
|
9430
|
+
*/
|
|
9431
|
+
IntegrationCapture.prototype.captureLocalStorage = function () {
|
|
9432
|
+
var localStorageItems = {};
|
|
9433
|
+
for (var key in integrationMapping) {
|
|
9434
|
+
var localStorageItem = localStorage.getItem(key);
|
|
9435
|
+
if (localStorageItem) {
|
|
9436
|
+
localStorageItems[key] = localStorageItem;
|
|
9437
|
+
}
|
|
9438
|
+
}
|
|
9439
|
+
return this.applyProcessors(localStorageItems, getHref(), this.initialTimestamp);
|
|
9440
|
+
};
|
|
9391
9441
|
/**
|
|
9392
9442
|
* Gets the query parameters based on the integration ID mapping.
|
|
9393
9443
|
* @returns {Dictionary<string>} The query parameters.
|
|
@@ -9409,6 +9459,36 @@ var mParticle = (function () {
|
|
|
9409
9459
|
IntegrationCapture.prototype.getClickIdsAsPartnerIdentities = function () {
|
|
9410
9460
|
return this.getClickIds(this.clickIds, this.filteredPartnerIdentityMappings);
|
|
9411
9461
|
};
|
|
9462
|
+
/**
|
|
9463
|
+
* Returns only the `integration_attributes` mapped integration output.
|
|
9464
|
+
* @returns {IntegrationAttributes} The integration attributes.
|
|
9465
|
+
*/
|
|
9466
|
+
IntegrationCapture.prototype.getClickIdsAsIntegrationAttributes = function () {
|
|
9467
|
+
var _a;
|
|
9468
|
+
var _b, _c;
|
|
9469
|
+
// Integration IDs are stored in the following format:
|
|
9470
|
+
// {
|
|
9471
|
+
// "integration_attributes": {
|
|
9472
|
+
// "<moduleId>": {
|
|
9473
|
+
// "mappedKey": "clickIdValue"
|
|
9474
|
+
// }
|
|
9475
|
+
// }
|
|
9476
|
+
// }
|
|
9477
|
+
var mappedClickIds = {};
|
|
9478
|
+
for (var key in this.clickIds) {
|
|
9479
|
+
if (this.clickIds.hasOwnProperty(key)) {
|
|
9480
|
+
var value = this.clickIds[key];
|
|
9481
|
+
var mappingKey = (_b = this.filteredIntegrationAttributeMappings[key]) === null || _b === void 0 ? void 0 : _b.mappedKey;
|
|
9482
|
+
if (!isEmpty(mappingKey)) {
|
|
9483
|
+
var moduleId = (_c = this.filteredIntegrationAttributeMappings[key]) === null || _c === void 0 ? void 0 : _c.moduleId;
|
|
9484
|
+
if (moduleId && !mappedClickIds[moduleId]) {
|
|
9485
|
+
mappedClickIds[moduleId] = (_a = {}, _a[mappingKey] = value, _a);
|
|
9486
|
+
}
|
|
9487
|
+
}
|
|
9488
|
+
}
|
|
9489
|
+
}
|
|
9490
|
+
return mappedClickIds;
|
|
9491
|
+
};
|
|
9412
9492
|
IntegrationCapture.prototype.getClickIds = function (clickIds, mappingList) {
|
|
9413
9493
|
var _a;
|
|
9414
9494
|
var mappedClickIds = {};
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@ export default class ForegroundTimeTracker {
|
|
|
9
9
|
public totalTime: number = 0;
|
|
10
10
|
|
|
11
11
|
constructor(timerKey: string) {
|
|
12
|
-
this.localStorageName = `
|
|
12
|
+
this.localStorageName = `mprtcl-tos-${timerKey}`;
|
|
13
13
|
this.timerVault = new LocalStorageVault<number>(this.localStorageName);
|
|
14
14
|
this.loadTimeFromStorage();
|
|
15
15
|
this.addHandlers();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SDKEventCustomFlags } from './sdkRuntimeModels';
|
|
2
|
+
import { IntegrationAttributes } from './store';
|
|
2
3
|
import {
|
|
3
4
|
Dictionary,
|
|
4
5
|
queryStringParser,
|
|
@@ -53,16 +54,19 @@ export const facebookClickIdProcessor: IntegrationCaptureProcessorFunction = (
|
|
|
53
54
|
// Integration outputs are used to determine how click ids are used within the SDK
|
|
54
55
|
// CUSTOM_FLAGS are sent out when an Event is created via ServerModel.createEventObject
|
|
55
56
|
// PARTNER_IDENTITIES are sent out in a Batch when a group of events are converted to a Batch
|
|
57
|
+
// INTEGRATION_ATTRIBUTES are stored initially on the SDKEvent level but then is added to the Batch when the batch is created
|
|
56
58
|
|
|
57
59
|
const IntegrationOutputs = {
|
|
58
60
|
CUSTOM_FLAGS: 'custom_flags',
|
|
59
61
|
PARTNER_IDENTITIES: 'partner_identities',
|
|
62
|
+
INTEGRATION_ATTRIBUTES: 'integration_attributes',
|
|
60
63
|
} as const;
|
|
61
64
|
|
|
62
65
|
interface IntegrationMappingItem {
|
|
63
66
|
mappedKey: string;
|
|
64
67
|
output: valueof<typeof IntegrationOutputs>;
|
|
65
68
|
processor?: IntegrationCaptureProcessorFunction;
|
|
69
|
+
moduleId?: number;
|
|
66
70
|
}
|
|
67
71
|
|
|
68
72
|
interface IntegrationIdMapping {
|
|
@@ -99,6 +103,19 @@ const integrationMapping: IntegrationIdMapping = {
|
|
|
99
103
|
output: IntegrationOutputs.CUSTOM_FLAGS,
|
|
100
104
|
},
|
|
101
105
|
|
|
106
|
+
// Rokt
|
|
107
|
+
// https://docs.rokt.com/developers/integration-guides/web/advanced/rokt-id-tag/
|
|
108
|
+
rtid: {
|
|
109
|
+
mappedKey: 'passbackconversiontrackingid',
|
|
110
|
+
output: IntegrationOutputs.INTEGRATION_ATTRIBUTES,
|
|
111
|
+
moduleId: 1277,
|
|
112
|
+
},
|
|
113
|
+
RoktTransactionId: {
|
|
114
|
+
mappedKey: 'passbackconversiontrackingid',
|
|
115
|
+
output: IntegrationOutputs.INTEGRATION_ATTRIBUTES,
|
|
116
|
+
moduleId: 1277,
|
|
117
|
+
},
|
|
118
|
+
|
|
102
119
|
// TIKTOK
|
|
103
120
|
ttclid: {
|
|
104
121
|
mappedKey: 'TikTok.Callback',
|
|
@@ -115,6 +132,7 @@ export default class IntegrationCapture {
|
|
|
115
132
|
public readonly initialTimestamp: number;
|
|
116
133
|
public readonly filteredPartnerIdentityMappings: IntegrationIdMapping;
|
|
117
134
|
public readonly filteredCustomFlagMappings: IntegrationIdMapping;
|
|
135
|
+
public readonly filteredIntegrationAttributeMappings: IntegrationIdMapping;
|
|
118
136
|
|
|
119
137
|
constructor() {
|
|
120
138
|
this.initialTimestamp = Date.now();
|
|
@@ -122,6 +140,7 @@ export default class IntegrationCapture {
|
|
|
122
140
|
// Cache filtered mappings for faster access
|
|
123
141
|
this.filteredPartnerIdentityMappings = this.filterMappings(IntegrationOutputs.PARTNER_IDENTITIES);
|
|
124
142
|
this.filteredCustomFlagMappings = this.filterMappings(IntegrationOutputs.CUSTOM_FLAGS);
|
|
143
|
+
this.filteredIntegrationAttributeMappings = this.filterMappings(IntegrationOutputs.INTEGRATION_ATTRIBUTES);
|
|
125
144
|
}
|
|
126
145
|
|
|
127
146
|
/**
|
|
@@ -130,6 +149,7 @@ export default class IntegrationCapture {
|
|
|
130
149
|
public capture(): void {
|
|
131
150
|
const queryParams = this.captureQueryParams() || {};
|
|
132
151
|
const cookies = this.captureCookies() || {};
|
|
152
|
+
const localStorage = this.captureLocalStorage() || {};
|
|
133
153
|
|
|
134
154
|
// Exclude _fbc if fbclid is present
|
|
135
155
|
// https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/fbp-and-fbc#retrieve-from-fbclid-url-query-parameter
|
|
@@ -137,7 +157,21 @@ export default class IntegrationCapture {
|
|
|
137
157
|
delete cookies['_fbc'];
|
|
138
158
|
}
|
|
139
159
|
|
|
140
|
-
|
|
160
|
+
// If both rtid and RoktTransactionId are present, prioritize rtid
|
|
161
|
+
// If RoktTransactionId is present in both cookies and localStorage,
|
|
162
|
+
// prioritize localStorage
|
|
163
|
+
if (queryParams['rtid'] && localStorage['RoktTransactionId'] && cookies['RoktTransactionId']) {
|
|
164
|
+
delete localStorage['RoktTransactionId'];
|
|
165
|
+
delete cookies['RoktTransactionId'];
|
|
166
|
+
} else if (queryParams['rtid'] && localStorage['RoktTransactionId']) {
|
|
167
|
+
delete localStorage['RoktTransactionId'];
|
|
168
|
+
} else if (queryParams['rtid'] && cookies['RoktTransactionId']) {
|
|
169
|
+
delete cookies['RoktTransactionId'];
|
|
170
|
+
} else if (localStorage['RoktTransactionId'] && cookies['RoktTransactionId']) {
|
|
171
|
+
delete cookies['RoktTransactionId'];
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
this.clickIds = { ...this.clickIds, ...queryParams, ...localStorage, ...cookies };
|
|
141
175
|
}
|
|
142
176
|
|
|
143
177
|
/**
|
|
@@ -145,7 +179,7 @@ export default class IntegrationCapture {
|
|
|
145
179
|
*/
|
|
146
180
|
public captureCookies(): Dictionary<string> {
|
|
147
181
|
const cookies = getCookies(Object.keys(integrationMapping));
|
|
148
|
-
return this.applyProcessors(cookies);
|
|
182
|
+
return this.applyProcessors(cookies, getHref(), this.initialTimestamp);
|
|
149
183
|
}
|
|
150
184
|
|
|
151
185
|
/**
|
|
@@ -156,6 +190,21 @@ export default class IntegrationCapture {
|
|
|
156
190
|
return this.applyProcessors(queryParams, getHref(), this.initialTimestamp);
|
|
157
191
|
}
|
|
158
192
|
|
|
193
|
+
/**
|
|
194
|
+
* Captures local storage based on the integration ID mapping.
|
|
195
|
+
*/
|
|
196
|
+
public captureLocalStorage(): Dictionary<string> {
|
|
197
|
+
let localStorageItems: Dictionary<string> = {};
|
|
198
|
+
for (const key in integrationMapping) {
|
|
199
|
+
const localStorageItem = localStorage.getItem(key);
|
|
200
|
+
if (localStorageItem) {
|
|
201
|
+
localStorageItems[key] = localStorageItem;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return this.applyProcessors(localStorageItems, getHref(), this.initialTimestamp);
|
|
206
|
+
}
|
|
207
|
+
|
|
159
208
|
/**
|
|
160
209
|
* Gets the query parameters based on the integration ID mapping.
|
|
161
210
|
* @returns {Dictionary<string>} The query parameters.
|
|
@@ -180,6 +229,37 @@ export default class IntegrationCapture {
|
|
|
180
229
|
return this.getClickIds(this.clickIds, this.filteredPartnerIdentityMappings);
|
|
181
230
|
}
|
|
182
231
|
|
|
232
|
+
/**
|
|
233
|
+
* Returns only the `integration_attributes` mapped integration output.
|
|
234
|
+
* @returns {IntegrationAttributes} The integration attributes.
|
|
235
|
+
*/
|
|
236
|
+
public getClickIdsAsIntegrationAttributes(): IntegrationAttributes {
|
|
237
|
+
// Integration IDs are stored in the following format:
|
|
238
|
+
// {
|
|
239
|
+
// "integration_attributes": {
|
|
240
|
+
// "<moduleId>": {
|
|
241
|
+
// "mappedKey": "clickIdValue"
|
|
242
|
+
// }
|
|
243
|
+
// }
|
|
244
|
+
// }
|
|
245
|
+
const mappedClickIds: IntegrationAttributes = {};
|
|
246
|
+
|
|
247
|
+
for (const key in this.clickIds) {
|
|
248
|
+
if (this.clickIds.hasOwnProperty(key)) {
|
|
249
|
+
const value = this.clickIds[key];
|
|
250
|
+
const mappingKey = this.filteredIntegrationAttributeMappings[key]?.mappedKey;
|
|
251
|
+
if (!isEmpty(mappingKey)) {
|
|
252
|
+
const moduleId = this.filteredIntegrationAttributeMappings[key]?.moduleId;
|
|
253
|
+
if (moduleId && !mappedClickIds[moduleId]) {
|
|
254
|
+
mappedClickIds[moduleId] = { [mappingKey]: value };
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return mappedClickIds;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
|
|
183
263
|
private getClickIds(
|
|
184
264
|
clickIds: Dictionary<string>,
|
|
185
265
|
mappingList: IntegrationIdMapping
|
package/src/serverModel.ts
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
Dictionary,
|
|
18
18
|
isValidCustomFlagProperty,
|
|
19
19
|
} from './utils';
|
|
20
|
-
import { ServerSettings } from './store';
|
|
20
|
+
import { IntegrationAttributes, ServerSettings } from './store';
|
|
21
21
|
import { MPID } from '@mparticle/web-sdk';
|
|
22
22
|
import {
|
|
23
23
|
IConsentStateV2DTO,
|
|
@@ -319,6 +319,7 @@ export default function ServerModel(
|
|
|
319
319
|
mpInstance._Store.webviewBridgeEnabled
|
|
320
320
|
) {
|
|
321
321
|
let customFlags: SDKEventCustomFlags = {...event.customFlags};
|
|
322
|
+
let integrationAttributes: IntegrationAttributes = mpInstance._Store.integrationAttributes;
|
|
322
323
|
|
|
323
324
|
// https://go.mparticle.com/work/SQDSDKS-5053
|
|
324
325
|
if (mpInstance._Helpers.getFeatureFlag && mpInstance._Helpers.getFeatureFlag(Constants.FeatureFlags.CaptureIntegrationSpecificIds)) {
|
|
@@ -328,6 +329,9 @@ export default function ServerModel(
|
|
|
328
329
|
mpInstance._IntegrationCapture.capture();
|
|
329
330
|
const transformedClickIDs = mpInstance._IntegrationCapture.getClickIdsAsCustomFlags();
|
|
330
331
|
customFlags = {...transformedClickIDs, ...customFlags};
|
|
332
|
+
|
|
333
|
+
const transformedIntegrationAttributes = mpInstance._IntegrationCapture.getClickIdsAsIntegrationAttributes();
|
|
334
|
+
integrationAttributes = {...transformedIntegrationAttributes, ...integrationAttributes};
|
|
331
335
|
}
|
|
332
336
|
|
|
333
337
|
if (event.hasOwnProperty('toEventAPIObject')) {
|
|
@@ -378,7 +382,7 @@ export default function ServerModel(
|
|
|
378
382
|
Package: mpInstance._Store.SDKConfig.package,
|
|
379
383
|
ClientGeneratedId: mpInstance._Store.clientId,
|
|
380
384
|
DeviceId: mpInstance._Store.deviceId,
|
|
381
|
-
IntegrationAttributes:
|
|
385
|
+
IntegrationAttributes: integrationAttributes,
|
|
382
386
|
CurrencyCode: mpInstance._Store.currencyCode,
|
|
383
387
|
DataPlan: mpInstance._Store.SDKConfig.dataPlan
|
|
384
388
|
? mpInstance._Store.SDKConfig.dataPlan
|
package/src/utils.ts
CHANGED
|
@@ -292,14 +292,19 @@ interface URLSearchParamsFallback {
|
|
|
292
292
|
}
|
|
293
293
|
|
|
294
294
|
const queryStringParserFallback = (url: string): URLSearchParamsFallback => {
|
|
295
|
-
|
|
295
|
+
const params: Dictionary<string> = {};
|
|
296
296
|
const queryString = url.split('?')[1] || '';
|
|
297
297
|
const pairs = queryString.split('&');
|
|
298
298
|
|
|
299
299
|
pairs.forEach(pair => {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
300
|
+
const [key, ...valueParts] = pair.split('=');
|
|
301
|
+
const value = valueParts.join('=');
|
|
302
|
+
if (key && value !== undefined) {
|
|
303
|
+
try {
|
|
304
|
+
params[key] = decodeURIComponent(value || '');
|
|
305
|
+
} catch (e) {
|
|
306
|
+
console.error(`Failed to decode value for key ${key}: ${e}`);
|
|
307
|
+
}
|
|
303
308
|
}
|
|
304
309
|
});
|
|
305
310
|
|