Submitting First Party Data

Submitting First Party Data from a web page

Overview

To enrich user data, you can submit First Party Data to Taboola, for a given visitor.

Taboola currently supports the ability to pass:

  • A hashed Email ID
  • Demographic Data (requires user consent)

Taboola Pixel using JavaScript

If you implemented Taboola Pixel via JavaScript, you can add the supported fields to your existing page_view event:

window._tfa.push({
    notify: "event",
    name: "page_view",
    id: 12345,
    unified_id: '973dfe463ec85...13b',
    demo: '{"g": "f", "a": "18"}'
})

📘

For an overview of Taboola pixel, see: Taboola pixel

For more information about Taboola pixel via JavaScript, see: Add the base pixel manually

Hashing with SHA256

For legal and privacy reasons, all Email IDs must be converted to lowercase and hashed via SHA256. The sample code snippets below illustrate.

Sample code snippets

Code Sample 1 - Convert to lower case and hash (Client-side JavaScript):

<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>

Code Sample 2 - Convert to lower case and hash (Server-side PHP):

<?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;
?>

Verifying the output

  1. You can use an online service to verify that your script is producing the correct result. (Enter the email address in lowercase - the service performs hashing only.)
  2. Sample input: [email protected]
  3. Sample output: 973dfe463ec85785f5f95af5ba3906eedb2d931c24e69824a89ea65dba4e813b