Hashing user emails

DCO Pixel Implementation > Hashing user emails

πŸ“

This section refers to the Taboola DCO solution. For the standard e-commerce solution, see here.

Overview

To enrich DCO campaigns with user data, you can submit hashed email addresses to Taboola. This allows for better user identification and personalization while maintaining privacy and security.

πŸ“˜

Related docs

Why hashed emails?

Hashing emails is an industry standard for creating a persistent user identity without sharing the actual email address. The one-way hashing algorithm ensures that:

  • The hash value will be different for different email addresses
  • The original email address cannot be restored from the hash value
  • User privacy is maintained while enabling identity matching
🚧

Important

Sharing hashed email addresses is mandatory for optimal DCO performance. Include the hashed email in all pixel events using the unified_id parameter.

Hashing with SHA256

For legal and privacy reasons, all email addresses must be:

  1. Converted to lowercase (e.g., [email protected] β†’ [email protected])
  2. Hashed using SHA256 encryption

Example

Implementation

Client-side JavaScript

Use this method to hash emails directly in the browser:

<html>
<head>
    <title>SHA-256 Hash Example</title>
</head>
<body>
    <input type="text" id="input" placeholder="Enter text to hash">
    <button onclick="hashInput()">Hash</button>
    <p>Hashed Output: <span id="output"></span></p>

    <script>
        async function hashString(message) {
            const encoder = new TextEncoder();
            const data = encoder.encode(message.toLowerCase());
            const hashBuffer = await crypto.subtle.digest('SHA-256', data);
            const hashArray = Array.from(new Uint8Array(hashBuffer));
            const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
            return hashHex;
        }

        // Call the function when the button is clicked
        async function hashInput() {
            const input = document.getElementById('input').value;
            const output = await hashString(input);
            document.getElementById('output').textContent = output;
        }
    </script>
</body>
</html>
πŸ’‘

Testing the code

Create an HTML page with the above code, open it in a web browser, enter an email address, and click the button. Then verify the output.

Server-side PHP

Use this method to hash emails on your server before sending them to the browser:

<?php
// Function to hash an email address

/*
Sample input:
[email protected]

Sample output:
973dfe463ec85785f5f95af5ba3906eedb2d931c24e69824a89ea65dba4e813b
*/

function hashEmail($email) {
    // Convert the email address to lowercase
    $emailLower = strtolower($email);
    
    // Hash the lowercase email address using SHA-256
    $hashedEmail = hash('sha256', $emailLower);
    
    // Return the hashed email address
    return $hashedEmail;
}

// Example usage

$email = "[email protected]";
$hashedEmail = hashEmail($email);
echo "The hashed email address is: " . $hashedEmail;
?>
πŸ’‘

Testing the code

Edit the $email value under "Example usage", run the code in any PHP environment, then verify the output.

Verifying the output

  1. Use an online SHA256 tool to verify your implementation produces the correct result.

    Note: Enter the email address in lowercase - the tool performs hashing only.

  2. Sample input: [email protected]
  3. Expected output: 973dfe463ec85785f5f95af5ba3906eedb2d931c24e69824a89ea65dba4e813b

Usage in pixel events

Once you have the hashed email, add it to your pixel events using the unified_id parameter:

window._tfa.push({
  notify: 'event',
  name: 'page_view',
  id: ACCOUNT_ID,
  unified_id: '973dfe463ec85785f5f95af5ba3906eedb2d931c24e69824a89ea65dba4e813b'
});

For e-commerce events, include it alongside your event data:

_tfa.push({
  notify: 'ecevent',
  name: 'PRODUCT_VIEW',
  id: ACCOUNT_ID,
  productIds: ['PROD123'],
  unified_id: '973dfe463ec85785f5f95af5ba3906eedb2d931c24e69824a89ea65dba4e813b'
});
πŸ’‘

When to capture the email

Capture and hash the user's email whenever they log in or provide it through a form. Store the hashed value in a variable and include it in all subsequent pixel events during that session.