Created
September 4, 2024 13:19
-
-
Save guitavano/6de5f1068c85800b0702937b97c51ef2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.addEventListener("load", () => { | |
// Cookie name to check if the user is part of the test | |
const TEST_COOKIE = "deco_matcher_2187709" | |
async function onLoadMarketing() { | |
const orderForm = await vtexjs.checkout.getOrderForm(); | |
function getCookie(name) { | |
const cookies = document.cookie.split(";"); | |
for (let cookie of cookies) { | |
cookie = cookie.trim(); | |
if (cookie.startsWith(name + "=")) { | |
return cookie.substring(name.length + 1); | |
} | |
} | |
return null; | |
} | |
const testCookie = getCookie(TEST_COOKIE); | |
// Feel free to add this info in other fields | |
// of the marketingData object | |
const marketingData = orderForm.marketingData | |
? { | |
...orderForm.marketingData, | |
"utmiPart": testCookie?.endsWith("0") ? "deco" : "vtex", | |
} | |
: { | |
"utmiPart": testCookie?.endsWith("0") ? "deco" : "vtex", | |
}; | |
await vtexjs.checkout.sendAttachment( | |
"marketingData", | |
marketingData, | |
); | |
} | |
onLoadMarketing(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment