Tutorials

How to track affiliate referrals from custom landing pages

Dan Rowden  ·  April 4, 2023

This tutorial shows how you can create custom affiliate-specific landing pages with easily-sharable URLs like mysite.com/dan, while still creating referrals via Lemon Squeezy.

How it works

We'll send visitors to custom landing pages for each affiliate, with a unique, memorable URL. On these pages we'll use the (cookie-free and privacy-friendly) Lemon Squeezy tracking script to save each "click", to make sure ách referral can be captured.

Affiliate codes in Lemon Squeezy look like ZylBs—a random string created by the system—which create URLs like mysite.com/?aff=ZylBs. The idea is that setting up a landing page like mysite.com/dan makes shareable URLs more brandable and create more user-friendly links.

1. Create pages in your website

The first steps is to create landing pages in your website. These can be regular pages in your CMS and could all use the same page content or template to make it easy to duplicate for all of your affiliates.

Alternatively you could create targeted pages for each affiliate, showing their name, avatar and some custom content for each. This would create a much stronger connection to the visitors who come through an affiliate's link, especially if they are a well-known person.

You'll need to create a page for each affiliate and use a related URL for the page. In this example, I'll use my first name dan, but you could use an affiliate's full name or social media handle.

Instead of creating a detailed landing page for each affiliate, you could instead redirect all visits to your home page. This would still require creating a page for each affiliate (you need the unique shareable link) but the page could be blank and used simply to record the referral click before sending the visitors on to your home page.

2. Get affiliate codes

Now your pages are ready, we need to get the affiliate code for each affiliate.

Head to the Affiliates page in your Lemon Squeezy dashboard, click on an affiliate and note their Affiliate URL. The code is the part after aff=. You will need this in the next step.

3. Add the Lemon Squeezy tracking script to your site

Now we need to add Lemon Squeezy's affiliate tracking script and some custom code so that we can capture the affiliate link click.

Your site's CMS may have a way to add code injection to your page or you may need to add this directly into the site's code.

The code below creates a configuration for our affiliate tracking script, defining a custom affiliate code of 1234 (you got this in step 2 above).

If you want to redirect to your homepage after the tracking has happened, you can add an onTrack handler, which fires after the tracking has taken place, like this:

And now you're all set! Visits to your landing pages will capture the affiliate clicks and your affiliates will have friendly, branded URLs to share to their audiences.

Previous
Custom domain