Remix
Install Partnersify tracking on Remix, pixel setup in root.tsx and reading the affiliate cookie in action functions.
Remix's root.tsx is the right place for the pixel, and action functions or resource routes handle passing the affiliate cookie to Stripe.
Step 1: Add the pixel
Add the pixel in root.tsx inside the <head> of your document:
// app/root.tsx
import { Links, Meta, Scripts } from '@remix-run/react';
export default function App() {
return (
<html>
<head>
<Meta />
<Links />
<script
dangerouslySetInnerHTML={{
__html: `window.partnersify = window.partnersify || function() { (window.partnersify.q = window.partnersify.q || []).push(arguments); };`,
}}
/>
<script
async
src="https://partnersify.com/partner.js"
data-partnersify="YOUR_MERCHANT_ID"
/>
</head>
<body>
{/* ... */}
<Scripts />
</body>
</html>
);
}
Replace YOUR_MERCHANT_ID with the ID from Setup → Install tracking.
Step 2: Pass the affiliate cookie to Stripe
In a Remix action or resource route, parse the Cookie header and forward it to your Stripe Checkout Session:
// app/routes/checkout.tsx (or a resource route)
import { redirect } from '@remix-run/node';
import type { ActionFunctionArgs } from '@remix-run/node';
import Stripe from 'stripe';
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
export async function action({ request }: ActionFunctionArgs) {
const cookieHeader = request.headers.get('Cookie') ?? '';
const partner = parseCookie(cookieHeader, 'psfy_partner');
const session = await stripe.checkout.sessions.create({
// ... your line items, success_url, etc.
metadata: {
psfy_partner: partner ?? null,
},
});
return redirect(session.url!);
}
function parseCookie(header: string, name: string): string | null {
const match = header.match(new RegExp(`(?:^|;\\s*)${name}=([^;]*)`));
return match ? decodeURIComponent(match[1]!) : null;
}
If you prefer, install the cookie npm package for parsing. The pattern above works without dependencies.
Step 3: Test it
- Sign up as an affiliate on your own portal
- Visit your site via the affiliate referral link
- Run the Test Pixel check at Setup → Install tracking
- Complete a test Stripe checkout using a test card
- Confirm the attributed sale appears in Sales within 30 seconds
Updated