polar icon indicating copy to clipboard operation
polar copied to clipboard

Docs: Document PolarEmbedCheckout.create + events it exposes

Open birkjernstrom opened this issue 7 months ago • 0 comments

Customer investigated and shared the below and that it would be great to expose this in our docs for the embed modal.

Making it easier for developers who want to add their own events, e.g tracking, related to the modal.

const polarCheckoutInstance = await PolarEmbedCheckout.create(
  checkoutUrl,
  "light",
)

// Right after we create the checkout, we know it's open, nice for conversion tracking, especially in funnels
await window.sendEvent("Open checkout", checkoutConfig)

// nice for tracking "i'd like to purchase, but something is off" type of scenarios
polarCheckoutInstance.addEventListener("close", async () => {
  await window.sendEvent("Close checkout")
})

// this way is more robust than tracking it on success page, since user can't trigger it more than once by refreshing the page etc.
polarCheckoutInstance.addEventListener("success", async () => {
  await window.sendEvent("Purchase")
})

birkjernstrom avatar Apr 03 '25 20:04 birkjernstrom