Skip to content

Commit

Permalink
Update logId5Id to save id as an integration attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
SbDove committed Oct 24, 2024
1 parent 415515c commit 3a1b523
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
14 changes: 4 additions & 10 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@ Common.prototype.exampleMethod = function () {
}

Common.prototype.logId5Id = function (id5Id) {
//Checks and saves ID5 ID if it is new
if (id5Id !== this.id5Id) {
this.id5Id = id5Id;
this.id5IdSent = false
}

//Sets user attribute if ID is unsent.
//This function will be updated once the decryption architecture is finalized.
//TO-DO: Log the ID5 ID to correct location

var integrationAttributes = {};
integrationAttributes['encryptedId5Id'] = id5Id;
integrationAttributes['id5IdType'] = this.id5IdType;
window.mParticle.setIntegrationAttributes(this.moduleId, integrationAttributes);
};

Common.prototype.buildPartnerData = function (mParticleUser) {
Expand Down
7 changes: 4 additions & 3 deletions src/initialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ var initialization = {
*/
initForwarder: function(forwarderSettings, testMode, userAttributes, userIdentities, processEvent, eventQueue, isInitialized, common) {
/* `forwarderSettings` contains your SDK specific settings such as apiKey that your customer needs in order to initialize your SDK properly */
common.partnerId = forwarderSettings.partnerId;
common.id5IdType = forwarderSettings.id5IdType;
common.moduleId = this.moduleId;

if (!testMode) {
/* Load your Web SDK here using a variant of your snippet from your readme that your customers would generally put into their <head> tags
Expand All @@ -21,9 +24,7 @@ var initialization = {
id5Script.src = 'https://cdn.id5-sync.com/api/1.0/id5-api.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(id5Script);

common.id5Id = null;
common.id5IdSent = false;
common.partnerId = forwarderSettings.partnerId;


id5Script.onload = function() {
isInitialized = true;
Expand Down
16 changes: 15 additions & 1 deletion test/src/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('ID5 Forwarder', function () {
// -------------------START EDITING BELOW:-----------------------
// -------------------mParticle stubs - Add any additional stubbing to our methods as needed-----------------------
var userAttributes = {};

var integrationAttributes = {};
mParticle.Identity = {
getCurrentUser: function() {
return {
Expand All @@ -40,6 +40,11 @@ describe('ID5 Forwarder', function () {
};
}
};

mParticle.setIntegrationAttributes = function(id, attributes) {
integrationAttributes[id] = attributes;
}

// -------------------START EDITING BELOW:-----------------------
var MockID5 = function() {
var self = this;
Expand Down Expand Up @@ -86,6 +91,7 @@ describe('ID5 Forwarder', function () {
// Include any specific settings that is required for initializing your SDK here
var sdkSettings = {
partnerId: 1234,
id5IdType: "other_5"
};

// The third argument here is a boolean to indicate that the integration is in test mode to avoid loading any third party scripts. Do not change this value.
Expand Down Expand Up @@ -313,5 +319,13 @@ describe('ID5 Forwarder', function () {
validated.should.equal(false);
done();
})

it ('should log an integration attribute when logId5Id is called', function(done) {
mParticle.forwarder.common.logId5Id("testId");
var attributes = integrationAttributes[248];
attributes['encryptedId5Id'].should.equal('testId');
attributes['id5IdType'].should.equal('other_5')
done();
})
})
});

0 comments on commit 3a1b523

Please sign in to comment.