Recording url tag to database for a conversion

Hey all,

I’ve inherited a wordpress site which includes an ad extension (id) tagged on inlinks to the site (i.e. example.com/?ad_ext=100) then that extension gets recorded to a cookie (by a file called in wp-blog-header.php) and that cookie content gets recorded in a database when a conversion happens.

The problem is though that for some reason if the person converts (submits a form) on the first page they enter on then the cookie value isn’t recorded even though the cookie is made instantly. If they land and refresh the page, or click to go to another page then convert, it records the cookie data properly.

Does anyone have any idea why this might be happening, or alternatively if the code below, which gets the cookie info prior to recording it, could be modified to have an else statement at the end which would grab the ext. number directly from the url.

Any ideas?

Thanks a lot.

Pete


function adExtNo($defaultExt = '1004'){
	if(isset($_COOKIE[__FSCOOKIE_PRINT_EXT])){ //Detect custom print media ad ext number
		$adCookie = $_COOKIE[__FSCOOKIE_PRINT_EXT];
		return $adCookie;
	}else{ //Else detect ppc ad ext number
		if(isset($_COOKIE[__FSCOOKIE_PPC_EXT])){
				$adCookie = $_COOKIE[__FSCOOKIE_PPC_EXT];
				return $adCookie;
		}else{ //Else just set ext number to web default
				return $defaultExt;
		}
	}
}

I’ve done a bunch of research and think this code might be a lot closer but it still doesn’t quite work.

The second else{ is added and I’m trying to get it to detect if ex. ?ppc_ext=1234 exists in the URL, and if it does then set $adCookie as that variable value.

Anyone know what’s wrong?



function adExtNo($defaultExt = '1004'){
	if(isset($_COOKIE[__FSCOOKIE_PRINT_EXT])){ //Detect custom print media ad ext number
		$adCookie = $_COOKIE[__FSCOOKIE_PRINT_EXT];
		return $adCookie;
	}else{ //Else detect ppc ad ext number
		if(isset($_COOKIE[__FSCOOKIE_PPC_EXT])){
				$adCookie = $_COOKIE[__FSCOOKIE_PPC_EXT];
				return $adCookie;
	}else{ //Else detect ppc ad ext number in url
		if(isset($_GET[ppc_ext])){
				$adCookie = $_GET[ppc_ext];
				return $adCookie;
		}else{ //Else just set ext number to web default
				return $defaultExt;
		}
	}
}

just in case anyone else was in need of this, here it is thanks to HuggyEssex on digitalpoint


function adExtNo($defaultExt = '1004'){
    if(isset($_COOKIE[__FSCOOKIE_PRINT_EXT])) {
        //Detect custom print media ad ext number
        $adCookie = $_COOKIE[__FSCOOKIE_PRINT_EXT];
        return $adCookie;
    }elseif(isset($_COOKIE[__FSCOOKIE_PPC_EXT])) {
        //Else detect ppc ad ext number
        $adCookie = $_COOKIE[__FSCOOKIE_PPC_EXT];
        return $adCookie;
    }elseif(isset($_GET[ppc_ext])) {
        //Else detect ppc ad ext number in url
        $adCookie = $_GET[ppc_ext];
        return $adCookie;
    }else{
        //Else just set ext number to web default
        return $defaultExt;
    }
}