Skip to content

Instantly share code, notes, and snippets.

@guitavano
Created September 4, 2024 13:19
Show Gist options
  • Save guitavano/6de5f1068c85800b0702937b97c51ef2 to your computer and use it in GitHub Desktop.
Save guitavano/6de5f1068c85800b0702937b97c51ef2 to your computer and use it in GitHub Desktop.
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