- This topic has 16 replies, 2 voices, and was last updated 10 years, 10 months ago by .
- You must be logged in to reply to this topic.
Affiliates Management Plugin for WordPress
by
WordPress Affiliate Manager › Forums › Affiliate Manager Plugin › Get Affiliate's Username by their Affiliate ID/RefKey
Tagged: affiliate id, get, invite code, paid membership pro, refkey, username
I took a look at lines 225-266 of affiliate-manager/source/Tracking/RequestTracker.php and I found this:
$refKey = new WPAM_Tracking_TrackingKey();
$refKey->unpack( $strRefKey );
$db = new WPAM_Data_DataAccess();
$affiliateRepos = $db->getAffiliateRepository();
$affiliateId = $affiliateRepos->getAffiliateIdFromRefKey( $refKey->getAffiliateRefKey() );
if ( $affiliateId === NULL ) {
echo '<pre>Affiliate ID: ';
var_export($affiliateId);
echo "\n\n";
echo $refKey;
throw new Exception( __( 'invalid refkey data.', 'wpam' ) );
}
//#37 make sure the affiliate is active before tracking stats
$affiliate = $affiliateRepos->load( $affiliateId );
if ( ! $affiliate->isActive() )
return;
$idGenerator = new WPAM_Tracking_UniqueIdGenerator();
$trackTokenModel = new WPAM_Data_Models_TrackingTokenModel();
$trackTokenModel->dateCreated = time();
$trackTokenModel->sourceAffiliateId = $affiliateId;
$trackTokenModel->sourceCreativeId = $refKey->getCreativeId();
$trackTokenModel->trackingKey = $idGenerator->generateId();
$trackTokenModel->referer = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : NULL;
if ( isset( $request['wpam_affiliateSubCode'] ) ) {
$trackTokenModel->affiliateSubCode = $request['wpam_affiliateSubCode'];
}
$db->getTrackingTokenRepository()->insert( $trackTokenModel );
$db->getEventRepository()->quickInsert( time(), $trackTokenModel->trackingKey, 'visit' );
$binConverter = new WPAM_Util_BinConverter();
// store the tracking key in a cookie so we can monitor their activities
$return = setcookie( WPAM_PluginConfig::$RefKey,
$binConverter->binToString( $trackTokenModel->trackingKey ),
$this->getExpireTime(),
COOKIEPATH );
Am I on the right track with this code for setting the tracking cookie?
Yeah, that code should be a good example for you.