run(); } run_jamkazam(); function track_affiliate() { $affiliate_id = $_GET['affiliate']; $expiration = current_time( 'timestamp' ) + ( DAY_IN_SECONDS * 2 ); #cookies[:affiliate_visitor] = { :value => params[:affiliate], :expires => Time.now + 3600 * 24} # 1 day from now if(isset($affiliate_id)) { setcookie('affiliate_visitor', $affiliate_id, $expiration, '/', '.jamkazam.com'); } } function track_origin() { $source = $_GET["utm_source"]; if(isset($source)) { setcookie('origin', json_encode(array('utm_source' => $_GET['utm_source'], 'utm_medium' => $_GET['utm_medium'], 'utm_campaign' => $_GET['utm_campaign'])), strtotime( '+1 year' ), '/', '.jamkazam.com'); } } /** * Set affiliate tracking cookie if there is an `?affiliate=xxxx` parameter in the URL * The rails set honors this cookie, and a new user will be associated with the affiliate. */ add_action( 'init', 'process_post' ); function process_post() { track_affiliate(); track_origin(); }