Attribute revenue with Lemon Squeezy (other methods)
Attribute any Lemon Squeezy payment through the customer's email.
Make sure you've connected your Lemon Squeezy account first.
When you can't pass metadata, credit the payment through the customer's email. On the page buyers land on after paying, call:
js
// On your success page, once you know who paid
window.datasense("payment", { email: customer.email })Datasense matches it to the Lemon Squeezy payment with that email, whether the webhook arrived before or after.
Example
Say buyers are redirected to /welcome after checkout. In React:
components/payment-tracker.jsx
"use client"
import { useEffect } from "react"
export function PaymentTracker({ email }) {
useEffect(() => {
window.datasense?.("payment", { email })
}, [email])
return null
}Make it reliable
If the call can run before the script has loaded, add this to the page's <head>, above the script, so the call is queued:
html
<script>
window.datasense = window.datasense || function () {
(window.datasense.q = window.datasense.q || []).push(arguments)
}
</script>When to use it
- Custom checkouts and third-party tools built on Lemon Squeezy
- Mobile app payments
The email is matched as a SHA-256 hash and never stored in plain text.