A great way to increase the recognition of your web data in Activation Studio & Marketing Cloud is to use hashed emails as an identifier. A hashed email is an anonymized version of an email address. Where test@test.com will be transformed into f660ab912ec121d1b1e928a0bb4bc61b15f5ad44d5efdc4e1c92a25e99b8e44a using the SHA-256 hashing algorithm. Follow the steps below to use hashed emails to link your web data collected using the Interaction Designer to your data model in Marketing Cloud.
Did you not yet setup a mapping table? Please see this article first.
1. Capture and send the hashed email address to Activation Studio
Note: This step uses Google Tag Manager. If you use another method to implement the Interactions, please check this with the person responsible for the implementation.
The code below contains the SHA256 hashing algorithm and will return the hashed email address if the email_variable value is not empty. Replace the email_variable with the name of the variable used to capture the raw email address. You might need to create this first.
Use the custom hashed email variable in your Interaction GTM template.
function() {
if( {{email_variable}} ) {
return sha256({{email_variable}});
} else {
return ""
}
function sha256(r){if(r){r=r.toString();for(var $,_,o=Math.pow,f=o(2,32),t="length",a="",n=[],h=8*r[t],i=sha256.h=sha256.h||[],c=sha256.k=sha256.k||[],e=c[t],s={},u=2;e<64;u++)if(!s[u]){for($=0;$<313;$+=u)s[$]=u;i[e]=o(u,.5)*f|0,c[e++]=o(u,1/3)*f|0}for(r+="\x80";r[t]%64-56;)r+="\0";for($=0;$<r[t];$++){if((_=r.charCodeAt($))>>8)return;n[$>>2]|=_<<(3-$)%4*8}for(_=0,n[n[t]]=h/f|0,n[n[t]]=h;_<n[t];){var v=n.slice(_,_+=16),g=i;for($=0,i=i.slice(0,8);$<64;$++){var l=v[$-15],k=v[$-2],x=i[0],S=i[4],d=i[7]+(A(S,6)^A(S,11)^A(S,25))+(S&i[5]^~S&i[6])+c[$]+(v[$]=$<16?v[$]:v[$-16]+(A(l,7)^A(l,18)^l>>>3)+v[$-7]+(A(k,17)^A(k,19)^k>>>10)|0),p=(A(x,2)^A(x,13)^A(x,22))+(x&i[1]^x&i[2]^i[1]&i[2]);(i=[d+p|0].concat(i))[4]=i[4]+d|0}for($=0;$<8;$++)i[$]=i[$]+g[$]|0}for($=0;$<8;$++)for(_=3;_+1;_--){var w=i[$]>>8*_&255;a+=(w<16?0:"")+w.toString(16)}return a}function A(r,$){return r>>>$|r<<32-$}}
}
2. Create a lookup table in Marketing Cloud
Step 1 is to create a lookup data extension of all your email addresses in Marketing Cloud. Create a data extension called AS_Hashed_Email_Lookup_Table with two columns; SubscriberKey (PrimaryKey) and hashedEmailAddress. You can use the following code in a SQL activity to fill this lookup table with hashed email addresses and create an automation to generate hashes of newly added email addresses. The interval is up to you, we recommend a maximum interval of 1 day.
SELECT
SubscriberKey,
LOWER(
CONVERT(
NVARCHAR(MAX),
HASHBYTES('SHA2_256',
CONVERT(VARCHAR(254), EmailAddress))
,2)
) as HashedEmailAddress
FROM _Subscribers
3. Add the lookup to your mapping table
In this step you will use the lookup table to find matching hashed email addresses. Please add this SQL activity to your existing Mapping Table automation.
IMPORTANT! Please rename Anonymous_Id in the query to the name of the column containing your anonymous ids in the mapping table. This is often the Google Analytics ID (GA_ID). And change the hashedEmail value to the name of the variable used in the Interaction (see next step).
SELECT
H.SubscriberKey,
MAX(I.SubscriberKey) AS Anonymous_Id
FROM AS_InteractionsVariables IV
LEFT JOIN AS_InteractionsData I ON IV.interaction_id = I.id
LEFT JOIN AS_Hashed_Email_Lookup_Table H ON H.HashedEmailAddress = IV.value_text
WHERE IV.name = 'hashedEmail'
AND IV.value_text IS NOT NULL
AND LEN(IV.value_text) > 0
AND IV.value_text != ' '
AND H.SubscriberKey IS NOT NULL
GROUP BY H.SubscriberKey