Attribution Script
Track where your revenue comes from with a lightweight client-side script.
The attribution script collects visitor context (UTM parameters, referrer, device info) and stores it in a cookie. When your customer checks out, you pass this data as checkout metadata so Money Fast can attribute each order to its source.
Step 1: Install the Script
Add this script tag to your website's <head> section:
<script defer src="https://moneyfa.st/js/script.min.js"></script>The script is lightweight (~1KB gzipped), loads asynchronously, and sets a _moneyfast cookie containing attribution data. The cookie is valid for 30 days and automatically refreshes when a visitor arrives with new UTM parameters.
Debug Mode
To see what the script collects, enable debug mode:
<script defer src="https://moneyfa.st/js/script.min.js" data-debug="true"></script>Open your browser's developer console to see [MoneyFast] log messages.
Step 2: Pass Metadata to Checkout
When creating a checkout session, read the cookie and pass its values as metadata. The example below uses Stripe — other providers follow the same pattern.
Stripe — Node.js / Next.js Example
import Stripe from 'stripe';
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
// Parse the _moneyfast cookie from the request
function getMoneyFastMeta(cookieHeader) {
const match = cookieHeader?.match(/(^| )_moneyfast=([^;]+)/);
if (!match) return {};
try {
return JSON.parse(decodeURIComponent(match[2]));
} catch {
return {};
}
}
// Create Checkout Session
export async function createCheckout(req) {
const meta = getMoneyFastMeta(req.headers.get('cookie'));
// Add exit_page and remove internal fields
meta.moneyfast_exit_page = new URL(req.url).pathname;
delete meta.moneyfast_ts;
const session = await stripe.checkout.sessions.create({
mode: 'subscription', // or 'payment'
line_items: [{ price: 'price_xxx', quantity: 1 }],
success_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel',
// Pass metadata to checkout session
metadata: meta,
// For subscriptions, also pass to subscription_data
subscription_data: {
metadata: meta,
},
});
return session.url;
}Client-side (Browser) Example
If you create checkout sessions from the frontend, use the global MoneyFast.meta() method:
const response = await fetch('/api/create-checkout', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
priceId: 'price_xxx',
// Pass MoneyFast attribution metadata
metadata: window.MoneyFast?.meta() || {},
}),
});Then on the server, merge the metadata into the checkout session:
const session = await stripe.checkout.sessions.create({
// ...other options
metadata: req.body.metadata,
subscription_data: {
metadata: req.body.metadata,
},
});Metadata Keys
All keys use the moneyfast_ prefix. Money Fast reads these from payment event metadata automatically.
| Key | Description | Source |
|---|---|---|
moneyfast_ref | Traffic source | utm_source, ref, or via query param |
moneyfast_campaign | Campaign name | utm_campaign query param |
moneyfast_medium | Traffic medium | utm_medium query param |
moneyfast_term | Search term | utm_term query param |
moneyfast_content | Ad content | utm_content query param |
moneyfast_landing_page | First page visited | Auto-detected |
moneyfast_exit_page | Checkout page | Set by MoneyFast.meta() |
moneyfast_referrer | Referrer URL | Auto-detected |
moneyfast_device | Device type | desktop, mobile, or tablet |
moneyfast_browser | Browser name | Auto-detected |
moneyfast_os | Operating system | Auto-detected |
moneyfast_lang | Browser language | Auto-detected |
moneyfast_tz | Timezone | Auto-detected |
JavaScript API
The script exposes a global MoneyFast object:
// Get raw attribution data from the cookie
MoneyFast.get()
// Get metadata for checkout (adds exit_page, removes internal fields)
MoneyFast.meta()
// Manually re-collect attribution data
MoneyFast.collect()
// Clear attribution cookie
MoneyFast.clear()Important Notes
- Subscription metadata (Stripe): Stripe does NOT auto-propagate checkout session metadata to subscriptions. You must explicitly set
subscription_data.metadatafor subscription products, otherwise renewal events will lack attribution data. - Cookie scope: The
_moneyfastcookie is set on your domain withSameSite=Lax. It works across all pages of your site but does not track across domains. - No PII: The script does not collect any personally identifiable information. It only captures UTM parameters, page URLs, and device/browser info.