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.