How to Hash Email from dataLayer and Pass to XDM Object in Adobe Data Collection | Community
Skip to main content
Level 2
May 2, 2024
Solved

How to Hash Email from dataLayer and Pass to XDM Object in Adobe Data Collection

  • May 2, 2024
  • 1 reply
  • 5468 views

Hello everyone,

 

I'm relatively new to Adobe Data Collection and am seeking some guidance on handling data from a `dataLayer`.

Let me apologize in advance if this seems like a basic question.

 

On our web pages, the developer has implemented a `dataLayer` with the following structure:


dataLayer.push({
event: "pageLoad",
user: {
email: "test1@gmail.com",
authenticatedState: "Authenticated"
}
});

I'm able to capture the raw email address as a Data Element without any issues.

However, I'm struggling with how to process this email into a SHA-256 hashed version and then pass it into my xdm (Experience Data Model) object.

Could anyone provide insights or suggestions on how to achieve this? Basically, I want to pre-hash the email address in Data Collection first before it ingest the full email address into AEP.

 

Thanks,

Rap

Best answer by Bhoomika_S

Hello @bestimv ,

I can propose the following two methods, and you can choose any one of the below based on the flexibility and compatibility. 

………

Method 1:

 

Hashing at the dataLayer level hashes the email before it is actually sent to Adobe Data collection, and improves the privacy and security of the data.

 

Step 1: Include the CryptoJS library in your HTML, which can be from the CDN URL. Below example is:

 

<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"></script>

 

Step 2: Modify the current dataLayer push to include hashing the email with CryptoJS:

 

<script> function hashEmail(email) { return CryptoJS.SHA256(email).toString(); } // Example code to collect email var userEmail = “test1@gmail.com”; dataLayer.push({ event: “pageLoad”, user: { email: hashEmail(userEmail), authenticatedState: “Authenticated” } }); </script>

 

Method 2:

 

If you cannot change the website code, or if you prefer to keep data transformation in Adobe Data Collection, you can use a custom code data element to hash the email.

 

Step 1: Ensure CryptoJS is available in Adobe Data Collection. You can include it through a custom HTML tag.

 

Step 2: Create a new Data Element in Adobe Data collection.

Navigate to the Data Elements section and click "Add Data Element."

Select "Custom Code" under the type options. Enter the following code in the editor:

 

(function() { var userEmail = _satellite.getVar('Email'); // Retrieve the email using another Data Element return CryptoJS.SHA256(userEmail).toString(); })();

 

Name the Data Element something like “Hashed Email” and save.

 

Note: I have just used CryptoJS in the above examples. You can use any encryption library as per your convenience.

1 reply

Bhoomika_S
Adobe Champion
Bhoomika_SAdobe ChampionAccepted solution
Adobe Champion
May 2, 2024

Hello @bestimv ,

I can propose the following two methods, and you can choose any one of the below based on the flexibility and compatibility. 

………

Method 1:

 

Hashing at the dataLayer level hashes the email before it is actually sent to Adobe Data collection, and improves the privacy and security of the data.

 

Step 1: Include the CryptoJS library in your HTML, which can be from the CDN URL. Below example is:

 

<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"></script>

 

Step 2: Modify the current dataLayer push to include hashing the email with CryptoJS:

 

<script> function hashEmail(email) { return CryptoJS.SHA256(email).toString(); } // Example code to collect email var userEmail = “test1@gmail.com”; dataLayer.push({ event: “pageLoad”, user: { email: hashEmail(userEmail), authenticatedState: “Authenticated” } }); </script>

 

Method 2:

 

If you cannot change the website code, or if you prefer to keep data transformation in Adobe Data Collection, you can use a custom code data element to hash the email.

 

Step 1: Ensure CryptoJS is available in Adobe Data Collection. You can include it through a custom HTML tag.

 

Step 2: Create a new Data Element in Adobe Data collection.

Navigate to the Data Elements section and click "Add Data Element."

Select "Custom Code" under the type options. Enter the following code in the editor:

 

(function() { var userEmail = _satellite.getVar('Email'); // Retrieve the email using another Data Element return CryptoJS.SHA256(userEmail).toString(); })();

 

Name the Data Element something like “Hashed Email” and save.

 

Note: I have just used CryptoJS in the above examples. You can use any encryption library as per your convenience.

bestImvAuthor
Level 2
May 6, 2024

Hi @bhoomika_s,

Thank you for explaining both methods. Based on the client's preference for our side handling the processing, I've decided to proceed with method 2.

I also came across the "Set Customer ID" feature of the Adobe Cloud ID service and am considering its implementation. Do you know whether it's feasible to create a Data Element to store the hashed value? If so, how can we properly configure this Data Element to work with the "Set Customer ID"?


Thanks for your guidance!

 

Thanks,
Rap

 

 

Bhoomika_S
Adobe Champion
Adobe Champion
May 6, 2024

Hello @bestimv ,

 

Let me help clarify a few points to make sure we're on the same page....

1. The Adobe Experience Cloud ID Service does support using hashed IDs, but it doesn't do the hashing for you. What you need to do is hash the data, like email addresses, on your own before sending them over. When setting up the "Set Customer IDs", make sure to specify the type of hash you used, such as SHA-256. This ensures that everything is processed smoothly on Adobe’s end...


2. You can set up a Data Element in Adobe Tags to handle hashed values. Please follow the below steps on how to do it

Follow the steps mentioned in Method 2 in my previous answer

Continuation...

- Jump to the Rules tab in Adobe Data Collection

Add an action with these settings:

  • Extension: Adobe Experience Cloud ID Service.
  • Action Type: "Set Customer IDs".
  • Configuration:
    • Customer ID: Pick the "Hashed Email" Data Element.
    • Auth State: Set to "Authenticated" or whatever suits your scenario.
    • Hash Type: select as "SHA-256".


Make sure to save your changes.

 

I also recommend thoroughly testing this configuration in a staging environment to ensure that the hashed email is processed and stored as expected.


A quick note on Method 2: If you need the output to be a readable hex string, which is commonly used for displaying hashes, please use the line provided below instead.

return CryptoJS.SHA256(userEmail).toString(CryptoJS.enc.Hex);