Create Your First referral with Affast

This guide will show you how to check if a customer is referred by a marketer as well as creating a referral.

How to Know a Customer Is Referred by a Marketer?

When a customer visits an affiliate link, Affast will create a cookie like this:

  • name: affast_affiliate.
  • value is the marketer's affiliate tag.

Affast Cookie

You can get that cookie with your backend language.

Below is how PHP works (If your application is using Laravel, consider to try this official package: Laravel Affast Client)

$affiliateTag = $_COOKIE['affast_affiliate'];

Another way to get the affiliate tag is adding this hidden input with id affast_affiliate to your form (regularly the registration form).

This hidden field will be filled with the affiliate tag automatically. Whenever the form is submitted, you can get it from your server:

<input type="hidden" id="affast_affiliate" value=""/>

Create a Referral

After getting the affiliate tag, then you can make a request to the Referral API endpoint to create a referral.

// Only create referral if an affiliate tag is exists.
if ($affiliateTag = $_COOKIE['affast_affiliate'] ?? null) {
    $response = Http::post('https://affast.app/api/referrals', [
        'affiliate_tag' => $affiliateTag,
        'referee_id' => $customer->id, // Customer id from your application
        'referee_name' => $customer->name, // Optional
        'referee_email' => $customer->email, // Optional
        'is_recurring' => false, // Default is false
    ]);

    $referral = $response->body();

    // Remove cookie
    unset($_COOKIE['affast_affiliate']);

    // Update customer with the referral id.
    $customer->update(['referred_by' => $referral['data']['id']]);
}

The response will contain a Referral ID that you can save it in your application database for referencing later.

Note: Don't forget to clear the cookie after the referral was created.

Recurring Referral

By default, the referral is not recurring, you can override it by setting the is_recurring attribute to true when creating the referral.

Http::post('https://affast.app/api/referrals', [
    ...,
    'is_recurring' => true, // Make the referral is recurring. 
]);