SvelteKit

Install Partnersify tracking on SvelteKit, pixel setup and reading the affiliate cookie in server load functions.

SvelteKit's server-side load functions and form actions make it easy to read the affiliate cookie and forward it to Stripe at checkout.

Step 1: Add the pixel

Add the pixel to src/app.html so it loads on every page:

<!-- src/app.html -->
<!DOCTYPE html>
<html>
  <head>
    %sveltekit.head%
    <script>
      window.partnersify = window.partnersify || function() { (window.partnersify.q = window.partnersify.q || []).push(arguments); };
    </script>
    <script async src="https://partnersify.com/partner.js" data-partnersify="YOUR_MERCHANT_ID"></script>
  </head>
  <body>%sveltekit.body%</body>
</html>

Replace YOUR_MERCHANT_ID with the ID from Setup → Install tracking.

Read the cookie in a server-side action or +server.ts endpoint and pass it to Stripe:

// src/routes/checkout/+server.ts
import Stripe from 'stripe';
import type { RequestHandler } from './$types';

const stripe = new Stripe(import.meta.env.STRIPE_SECRET_KEY);

export const POST: RequestHandler = async ({ cookies }) => {
  const partner = cookies.get('psfy_partner') ?? null;

  const session = await stripe.checkout.sessions.create({
    // ... your line items, success_url, etc.
    metadata: {
      psfy_partner: partner,
    },
  });

  return Response.json({ url: session.url });
};

Or from a form action in +page.server.ts:

// src/routes/checkout/+page.server.ts
import Stripe from 'stripe';
import { redirect } from '@sveltejs/kit';
import type { Actions } from './$types';

const stripe = new Stripe(import.meta.env.STRIPE_SECRET_KEY);

export const actions: Actions = {
  default: async ({ cookies }) => {
    const partner = cookies.get('psfy_partner') ?? null;

    const session = await stripe.checkout.sessions.create({
      // ... your line items, success_url, etc.
      metadata: { psfy_partner: partner },
    });

    redirect(303, session.url!);
  },
};

Step 3: Test it

  1. Sign up as an affiliate on your own portal
  2. Visit your site via the referral link
  3. Run the Test Pixel check at Setup → Install tracking
  4. Complete a test Stripe checkout using a test card
  5. Confirm the attributed sale appears in Sales

Updated