How to Effectively Capture Referrals Using Genius Referrals SDKs

Discover how to effectively capture referrals when users click on shared links and arrive at your landing page. This guide will provide you with step-by-step instructions on integrating Genius Referrals with your application using the PHP SDK, ensuring seamless referral tracking and management.

Prerequisites:

  1. Registration on the platform: Log in to Genius Referrals and obtain your API credentials.
  2. Genius Referrals SDK: Ensure you have installed the Genius Referrals SDK for PHP.

Step 1: Capture URL Parameters

Capture the parameters that come in the URL when a shared link from an advocate is visited and store them using PHP sessions.

The parameters you need to extract from the landing page URL are:

  • gr_at: Token of the advocate who shared the referral.
  • gr_cs: Campaign identifier.
  • gr_ro: Referral origin identifier.

<?php
// En tu método acción, haz algo similar a esto
$strGRAdvocateReferrerToken = $_GET['gr_at'];
$strGRCampaignSlug = $_GET['gr_cs'];
$strGRReferralOriginSlug = $_GET['gr_ro'];

$_SESSION['strGRAdvocateReferrerToken'] = $strGRAdvocateReferrerToken;
$_SESSION['strGRCampaignSlug'] = $strGRCampaignSlug;
$_SESSION['strGRReferralOriginSlug'] = $strGRReferralOriginSlug;
?>


Note: To link the referred user with the advocate who shared the referral, the referred user must complete a conversion action. Without this, the referral may not result in a customer.

Step 2: Create the Connection Between the Referred User and the Advocate

Once the referred user completes a conversion action, retrieve the session values strGRAdvocateReferrerToken, strGRCampaignSlug, and strGRReferralOriginSlug and create the referral using the PHP SDK.

Here's an example:

<?php

require_once "../vendor/autoload.php";
$contentType = "application/json"; // The content type
$xAuthToken = "2f266b71b8038e6"; // Your API Token, you can get your token here https://app.geniusreferrals.com/en/settings/api-access
$accountSlug = 'sandbox';

$client = new GeniusReferralsLib\GeniusReferralsClient($contentType, $xAuthToken);

// Loading parameters from session
$strGRAdvocateReferrerToken = $_SESSION['strGRAdvocateReferrerToken'];
$strGRCampaignSlug = $_SESSION['strGRCampaignSlug'];
$strGRReferralOriginSlug = $_SESSION['strGRReferralOriginSlug'];

// The referral's details from the registration process
$strReferralFirstName = 'Jane';
$strReferralLastName = 'Doe';
$strReferralEmail = 'jane.doe@example.com';

// Creating the Referral, which is a promoter who cannot refer
$advocatesController = $client->getAdvocates();

// Preparing data needed to sent on the request
$advocateModel = new \GeniusReferralsLib\Models\Advocate();
$advocateModel->name = $strReferralFirstName;
$advocateModel->lastname = $strReferralLastName;
$advocateModel->email = $strReferralEmail;
$advocateModel->payoutThreshold = 1;
$advocateModel->canRefer = 0; // un referido no puede referir.

$newReferredAdvocate = $advocatesController->postAdvocate($accountSlug, new \GeniusReferralsLib\Models\AdvocateForm($advocateModel));

// Adding the currency to the referral
$advocatePatchForm = new \GeniusReferralsLib\Models\AdvocatePatchForm();
$advocatePatchForm->currencyCode = 'USD';

// Referral currency successfully added
$advocatesController->patchAdvocate($accountSlug, $newReferredAdvocate->token, $advocatePatchForm);

//Creating the referral object to connect the referral and the advocate
$referralsController = $client->getReferrals();

// Preparing data needed to create the referral
$referralModel = new \GeniusReferralsLib\Models\Referral();
$referralModel->campaignSlug = $strGRCampaignSlug;
$referralModel->httpReferer = $_SERVER['HTTP_REFERER'];
$referralModel->referralOriginSlug = $strGRReferralOriginSlug;
$referralModel->referredAdvocateToken = $newReferredAdvocate->token;

$referral = $referralsController->postReferral($accountSlug, $strGRAdvocateReferrerToken, new \GeniusReferralsLib\Models\ReferralForm($referralModel));

if(isset($referral->id)){
    // Referral successfully created
}
else{
    // handle errors
}
Was this page helpful?
LANGUAGE