acme.store
<script
defer
data-website-id="demo"
src="https://usedatasense.com/js/script.js"
></script>// From JavaScript
window.datasense?.("signup", { plan: "pro" })
// Or declaratively on any element
<button data-ds-goal="checkout" data-ds-goal-plan="pro">Buy</button>Pick a short, unique path. Filter lists match common analytics paths, not /_ds on your own domain.
// next.config.ts
import type { NextConfig } from "next"
const nextConfig: NextConfig = {
async rewrites() {
return [
{ source: "/_ds/js/script.js", destination: "https://usedatasense.com/js/script.js" },
{ source: "/_ds/api/e", destination: "https://usedatasense.com/api/e" },
]
},
}
export default nextConfig<script
defer
data-website-id="demo"
src="/_ds/js/script.js"
></script>// 1. In the browser, when the visitor starts checkout
await fetch("/api/checkout", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
plan: "pro",
datasense_session_id: window.datasense?.sessionId?.(),
}),
})// 2. On your server, keep it on the checkout session
const session = await stripe.checkout.sessions.create({
line_items: [/* … */],
metadata: { datasense_session_id: body.datasense_session_id },
})// 3. In your payment webhook, report the successful payment
await fetch("https://usedatasense.com/api/v1/payments", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.DATASENSE_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
amount: 29.99, // in major units, not cents
currency: "USD",
transaction_id: payment.id, // makes retries safe
datasense_session_id: payment.metadata.datasense_session_id,
customer_id: payment.customer, // optional
renewal: false, // true for subscription renewals
// refunded: true, // send again with this for a refund
}),
})