Home / Admin / snapchat capi email hashing
Duplicate Snippet

Embed Snippet on Your Site

snapchat capi email hashing

Mohamed Alsalhe
<10
Code Preview
js
<script>
async function sha256(email) {
    const encoder = new TextEncoder();
    const data = encoder.encode(email.trim().toLowerCase());
    const hash = await crypto.subtle.digest("SHA-256", data);
    return Array.from(new Uint8Array(hash)).map(b => b.toString(16).padStart(2, "0")).join("");
}
async function sendToSnapchatCAPI(email) {
    if (email) {
        const hashedEmail = await sha256(email);
        fetch("https://tr.snapchat.com/v2/conversion", {
            method: "POST",
            headers: {
                "Content-Type": "application/json"
            },
            body: JSON.stringify({
                pixel_id: "2d63937e-8c58-4e6f-8f05-17c2a94791d7",
                event_type: "WhatsAppClick",
                event_conversion_type: "WEB",
                timestamp: new Date().toISOString(),
                event_id: "wa_click_" + new Date().getTime(),
                user: {
                    email: hashedEmail
                }
            })
        });
    }
}
</script>

Comments

Add a Comment