Skip to content

Instantly share code, notes, and snippets.

@mrandyclark
Created November 13, 2024 16:50
Show Gist options
  • Save mrandyclark/2194f012600a83a96e9d3edcc7579691 to your computer and use it in GitHub Desktop.
Save mrandyclark/2194f012600a83a96e9d3edcc7579691 to your computer and use it in GitHub Desktop.
analytics.subscribe("checkout_completed", (event) => {
var script = document.createElement('script');
script.onload = function() {
const cacheBust = Math.random() * 10000000000000;
const total = event.data.checkout.totalPrice.amount;
const email = event.data.checkout.email;
const orderId = event.data.checkout.order.id;
const protocol = "https:" === document.location.protocol ? "https://" : "http://";
const imageUrl = `${protocol}trkn.us/pixel/c?ppt=24332&g=purchase&gid=60337&cv1=${orderId}&rev=${total}&ord=${cacheBust}&v=120`
const x = document.createElement("IMG");
x.setAttribute("src", imageUrl);
x.setAttribute("width", "1");
x.setAttribute("height", "1");
document.body.appendChild(x);
}
script.src = document.location.protocol + '//trkn.us/pixel/c';
script.async = true;
document.head.appendChild(script);
});
@mrandyclark
Copy link
Author

  • Updated var to const
  • Updated imageUrl concatenation
  • Fixed parens and bracket notation
  • Fixed == vs ===
  • Line 20 - in the code sent via slack, this does not have .js in the url, where the original code does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment