Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: store id5 id to integration attributes #6

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 3 additions & 4 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,10 +24,6 @@ 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();
})
})
});