Developers · Revenue attribution
Stripe and Shopify revenue attribution, every sale credited to its source.
Webhook sales usually arrive with no idea where the buyer came from. Add the visit to the checkout, and each Stripe or Shopify sale joins the buyer’s visit, so the ad, search or newsletter that brought them gets the credit.
Stripe
Add the visit, then read the webhook.
stripeMetadata() puts the visit on the Checkout Session, inside the buyer’s request. When Stripe calls your webhook, fromStripe() turns the event into a sale.
- Paid checkouts become Purchase
- Renewals become Subscription renewed
- Amounts converted from Stripe’s cents, for every currency
- The event id is set for you
import { stripeMetadata, fromStripe } from 'nahnu-analytics-sdk';
// Inside the buyer's request
await stripe.checkout.sessions.create({
/* … */
metadata: { ...stripeMetadata(request, website.id) },
});
// Your Stripe webhook
const sale = fromStripe(event);
if (sale) await stats.events.send(sale.site ?? website.id, sale.event);Shopify
The orders/paid webhook, one helper.
fromShopify() uses the buyer’s address and browser that Shopify keeps on the order, so the sale joins their visit without any change to your store.
- Works from the orders/paid webhook
- Test orders are left out
- The order id becomes the event id
- Any other app: send name, revenue, ip and user_agent
import { fromShopify } from 'nahnu-analytics-sdk';
const sale = fromShopify(order); // test orders → null
if (sale) await stats.events.send(website.id, sale);await stats.events.send(website.id, {
name: 'Purchase', id: order.id,
revenue: { amount: 49, currency: 'USD' },
ip: order.ip, user_agent: order.userAgent,
});Where the credit shows
See which source made the money.
Once a sale joins the visit, it shows wherever revenue does.
Paths to conversion
The channel of the visit that bought, and of the buyer’s first visit.
Top sources and campaigns
Revenue per source and per campaign.
Goals and events
Purchase and Subscription renewed, with revenue.
Funnels
Revenue at each step to the sale.
Counted once
No double sales, no lost ones.
Webhooks get sent again. Stats shouldn’t count them again.
One id, one sale
The same event id within 3 days counts once.
Never breaks a checkout
track() never throws. A stats hiccup can’t stop an order.
Past ad blockers
The sale goes from your server, not the buyer’s browser.
No visit? Still counted
Without the address and browser, the sale counts as its own visitor.
Which attribution does it use?
Paths to conversion shows the channel of the visit that bought and of the buyer’s first visit. Earlier days are matched when Recognize returning visitors is on, or for people a site names with identify().
What if the buyer used an ad blocker?
The sale still counts, because it goes from your server. It joins their visit when the visit was counted too.
What if Stripe sends the webhook twice?
It counts once. fromStripe() sets the event id, and the same id within 3 days is a duplicate.
Does it work with currencies without decimals?
Yes. Amounts are converted from Stripe’s cents for each currency, including those with no decimals or three.
What about WooCommerce?
WooCommerce, SureCart, FluentCart and Easy Digital Downloads count sales by themselves with the free connector.
Know which source sold.
Unlimited websites, every feature, one license.