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.
<?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;
?>
<?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
}