Thursday, July 22, 2021

Google Ads: Creating a Hash from an email address in SFMC

Google Ads allows you to upload email addresses into Google Ads and then target (or suppress) ads to people who own those email addresses.  

If you want to protect your PII, you may be required to upload the email addresses as an SHA-256 hash.  Google Ads will allow you to upload in plain text, but if you don't like having that kind of data lying around on your end, you'll want to hash them.  (If you don't, Google will immediately hash them as soon as they're uploaded.)

If you're using Salesforce Marketing Cloud (ExactTarget), the query to do the hashing is a little different than if you were to do the hashing outside of Marketing Cloud.  

Anywhere else:

lower(CONVERT(VARCHAR(100),
HASHBYTES('SHA2_256',
@EmailAddress),2)) as HashEmail

In SFMC:
lower(CONVERT(VARCHAR(100),
HASHBYTES('SHA2_256',
CONVERT(VARCHAR(100),@EmailAddress,0)),2)) as HashEmail
A second convert step is needed in the process or it starts with the wrong data for hashing and ends up with a hash that doesn't match anything. Took a lot of trial-and-error and research to get to this, so hopefully it's useful.



Tuesday, July 06, 2021

AMPscript: Quickly Calculate Integers in SFMC / ExactTarget

There's no integer function in SFMC, but you can get there quickly with mod and subtract.

As a reminder:

mod(a,b) = remainder of a divided by b

subtract(c,d) = c minus d

So....

mod(5.5,1) 
= remainder of 5.5 divided by 1
= remainder of 5.5
= 0.5

subtract(5.5,mod(5.5,1))
= 5.5 minus remainder of 5.5 divided by 1
= 5.5 minus remainder of 5.5
= 5.5 minus 0.5
= 5

So....

if your non-integer number is @numOriginal, your calculation 

set @numInteger = subtract(@numOriginal,mod(@numOriginal,1))

That's one fun secret... here's another: there are far more Email Marketing Jobs than there are people like us to do the work. Your next job may be waiting at emailmktgjobs.blogspot.com.