-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
154 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,84 @@ | ||
var SHA256 = require('crypto-js/sha256'); | ||
function Common() {} | ||
|
||
Common.prototype.exampleMethod = function () { | ||
return 'I am an example'; | ||
} | ||
|
||
module.exports = Common; | ||
Common.prototype.logId5 = function () { | ||
var id5Id = this.id5Instance.getUserId(); | ||
debugger; | ||
|
||
//Checks and saves ID5 ID if it is new | ||
if (id5Id != this.id5Id) { | ||
this.id5Id = id5Id; | ||
this.id5IdSent = false | ||
} | ||
|
||
//Only sends the ID5 ID Custom Event if unsent | ||
if (this.id5IdSent == false){ | ||
var currentUser = mParticle.Identity.getCurrentUser(); | ||
currentUser.setUserAttribute('ID5ID', id5Id); | ||
this.id5IdSent = true; | ||
} | ||
}; | ||
|
||
Common.prototype.buildPartnerData = function (mParticleUser) { | ||
var pdKeys = {}; | ||
var userIdentities = mParticleUser.getUserIdentities(); | ||
|
||
var email = userIdentities.userIdentities['email']; | ||
if (email) { | ||
var processedEmail = normalizeAndHashEmail(email); | ||
pdKeys[1] = processedEmail; | ||
} | ||
|
||
var phone = userIdentities.userIdentities['mobile_number']; | ||
if (phone) { | ||
var processedPhone = normalizeAndHashPhone(phone); | ||
pdKeys[2] = processedPhone; | ||
} | ||
|
||
//Candidates to be removed | ||
var fullUrl = window.location.href; | ||
if (fullUrl) pdKeys[8] = encodeURIComponent(fullUrl); | ||
|
||
var domain = window.location.host; | ||
if (domain) pdKeys[9] = domain; | ||
|
||
var userAgentString = navigator.userAgent; | ||
if (userAgentString) pdKeys[12] = encodeURIComponent(userAgentString); | ||
// above may be pulled from PD as they are un needed for the ID5 ID generation as a basic level | ||
|
||
|
||
var pdRaw = Object.keys(pdKeys).map(function(key){ | ||
return key + '=' + pdKeys[key] | ||
}).join('&'); | ||
|
||
return btoa(pdRaw); | ||
} | ||
|
||
function normalizeAndHashEmail(email) { | ||
var parts = email.split("@") | ||
var charactersToRemove = ['+', '.'] | ||
|
||
if (parts[1] != 'gmail.com') { | ||
return email; | ||
} | ||
|
||
charactersToRemove.forEach(function(character) { | ||
parts[0] = parts[0].replaceAll(character, '').toLowerCase(); | ||
}) | ||
|
||
return SHA256(parts.join('@')); | ||
} | ||
|
||
function normalizeAndHashPhone(phone) { | ||
var charactersToRemove = [' ', '-', '(', ')'] | ||
charactersToRemove.forEach(function(character) { | ||
phone = phone.replaceAll(character, ''); | ||
}) | ||
return SHA256(phone); | ||
} | ||
|
||
module.exports = Common; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
// import SHA256 from 'crypto-js/sha256'; | ||
|
||
var initialization = { | ||
name: 'ID5', | ||
moduleId: '248', | ||
|
@@ -11,31 +9,25 @@ var initialization = { | |
userIdentities example: { 1: 'customerId', 2: 'facebookId', 7: '[email protected]' } | ||
additional identityTypes can be found at https://github.com/mParticle/mparticle-sdk-javascript/blob/master-v2/src/types.js#L88-L101 | ||
*/ | ||
initForwarder: function(forwarderSettings, testMode, userAttributes, userIdentities, processEvent, eventQueue, isInitialized, common, appVersion, appName, customFlags, clientId) { | ||
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 */ | ||
|
||
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 | ||
Generally, our integrations create script tags and append them to the <head>. Please follow the following format as a guide: | ||
*/ | ||
|
||
var clientScript = document.createElement('script'); | ||
clientScript.type = 'text/javascript'; | ||
clientScript.async = true; | ||
clientScript.src = 'https://cdn.id5-sync.com/api/1.0/id5-api.js'; // <---- Update this to be your script | ||
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(clientScript); | ||
clientScript.onload = function() { | ||
var partnerData = buildPartnerData(userIdentities); | ||
|
||
//To-Do: PartnerUserId to be added to the init options once received from id5 | ||
window.ID5.init({partnerId: forwarderSettings.partnerId, pd: partnerData}).onAvailable(function(status) { | ||
var id5Id = status.getID5Id(); | ||
var idType = forwarderSettings.id5IdType; | ||
var identities = {}; | ||
identities[idType] = id5Id; | ||
|
||
window.mParticle.Identity.modify({userIdentities: identities}, identityCallback) | ||
}); | ||
var id5Script = document.createElement('script'); | ||
id5Script.src = 'https://cdn.id5-sync.com/api/1.0/id5-api.js'; // <---- Update this to be your script | ||
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(id5Script); | ||
debugger; | ||
common.id5Id = null; | ||
common.id5IdSent = false; | ||
common.parterId = forwarderSettings.partnerId; | ||
|
||
id5Script.onload = function() { | ||
isInitialized = true; | ||
common.id5Instance = window.ID5.init({partnerId: forwarderSettings.partnerId}) | ||
}; | ||
} else { | ||
// For testing, you should fill out this section in order to ensure any required initialization calls are made, | ||
|
@@ -44,60 +36,4 @@ var initialization = { | |
} | ||
}; | ||
|
||
|
||
function buildPartnerData(userIdentities) { | ||
var pdKeys = {}; | ||
|
||
var email = userIdentities.userIdentities['email']; | ||
var processedEmail = normalizeAndHashEmail(email); | ||
if (processedEmail) pdKeys[1] = processedEmail; | ||
|
||
var phone = userIdentities.userIdentities['mobile_number']; | ||
var processedPhone = normalizeAndHashPhone(phone); | ||
if (processedPhone) pdKeys[2] = processedPhone; | ||
|
||
var fullUrl = window.location.href; | ||
if (fullUrl) pdKeys[8] = encodeURIComponent(fullUrl); | ||
|
||
var domain = window.location.host; | ||
if (domain) pdKeys[9] = domain; | ||
|
||
// Below may not be accessible from kit | ||
var userAgentString; | ||
if (userAgentString) pdKeys[12] = encodeURIComponent(userAgentString); | ||
|
||
var pdRaw = Object.keys(pdKeys).map(function(key){ | ||
return key + '=' + pdKeys[key] | ||
}).join('&'); | ||
|
||
return btoa(pdRaw); | ||
} | ||
|
||
function normalizeAndHashEmail(email) { | ||
var SHA256 = require('crypto-js/sha256'); | ||
|
||
var parts = email.split("@") | ||
var charactersToRemove = ['+', '.'] | ||
|
||
if (parts[1] != 'gmail.com') { | ||
return email; | ||
} | ||
|
||
charactersToRemove.forEach(function(character) { | ||
parts[0] = parts[0].replaceAll(character, '').toLowerCase(); | ||
}) | ||
|
||
return SHA256(parts.join('@')); | ||
} | ||
|
||
function normalizeAndHashPhone(phone) { | ||
var SHA256 = require('crypto-js/sha256'); | ||
|
||
var charactersToRemove = [' ', '-', '(', ')'] | ||
charactersToRemove.forEach(function(character) { | ||
phone = phone.replaceAll(character, ''); | ||
}) | ||
return SHA256(phone); | ||
} | ||
|
||
module.exports = initialization; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.