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.

KeyDescriptionSource
moneyfast_refTraffic sourceutm_source, ref, or via query param
moneyfast_campaignCampaign nameutm_campaign query param
moneyfast_mediumTraffic mediumutm_medium query param
moneyfast_termSearch termutm_term query param
moneyfast_contentAd contentutm_content query param
moneyfast_landing_pageFirst page visitedAuto-detected
moneyfast_exit_pageCheckout pageSet by MoneyFast.meta()
moneyfast_referrerReferrer URLAuto-detected
moneyfast_deviceDevice typedesktop, mobile, or tablet
moneyfast_browserBrowser nameAuto-detected
moneyfast_osOperating systemAuto-detected
moneyfast_langBrowser languageAuto-detected
moneyfast_tzTimezoneAuto-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.metadata for subscription products, otherwise renewal events will lack attribution data.
  • Cookie scope: The _moneyfast cookie is set on your domain with SameSite=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.

Prompt for AI Agents

Copy the prompt below and paste it into your AI coding agent (Cursor, Claude Code, Windsurf, etc.) to integrate Money Fast attribution into your project.

Integrate Money Fast (moneyfa.st) revenue attribution into this project. Follow these instructions exactly.

## 1. Install tracking script

Add this script tag to the site's `<head>` (root layout, _app, index.html, etc.):

```html
<script defer src="https://moneyfa.st/js/script.min.js"></script>
```

## 2. Pass attribution data to Stripe Checkout metadata

Find where the Stripe Checkout session is created and add MoneyFast attribution metadata.

### How to read the cookie

The script sets a `_moneyfast` cookie. Read it with:

```js
JSON.parse(decodeURIComponent(cookieValue))
```

### ⚠️ CRITICAL: Do NOT add `moneyfast_` prefix

The cookie keys ALREADY include the `moneyfast_` prefix. The cookie looks like:

```json
{ "moneyfast_ref": "google", "moneyfast_device": "desktop", "moneyfast_browser": "Chrome", "moneyfast_os": "Windows", "moneyfast_landing_page": "/", "moneyfast_ts": 1710000000 }
```

Pass them as-is. If you add another `moneyfast_` prefix, the keys become `moneyfast_moneyfast_device` and all attribution data will be LOST.

```js
// ❌ WRONG
meta[`moneyfast_${key}`] = value;

// ✅ CORRECT
meta[key] = value;
```

### What to filter

- Exclude `moneyfast_ts` (internal timestamp, not needed in metadata)
- Add `moneyfast_exit_page` = current page pathname at checkout time (get from client side via `window.location.pathname`)
- Only include string values from the cookie

### Where to pass metadata

Pass the metadata object to ALL of these (depending on checkout mode):

- `metadata` — always (on the checkout session itself)
- `subscription_data.metadata` — if mode is `subscription` (Stripe does NOT auto-propagate session metadata to subscriptions)
- `payment_intent_data.metadata` — if mode is `payment` and `invoice_creation` is enabled

## 3. Verification

After implementation, verify:
1. Visit the site, open DevTools console, run `MoneyFast.get()` — should return an object with attribution data
2. Create a test checkout, inspect the Stripe Dashboard → Checkout Session → Metadata — keys should be `moneyfast_device`, `moneyfast_browser`, etc. (single prefix, NOT `moneyfast_moneyfast_*`)