How to put PHP tracking code on individual Wordpress Posts

by 4 replies
5
This PHP tracking code below is what I want to put on this ONE page on my site How Buy Silver Bullion

PHP Code:
<? 
    $referrer = urlencode($_SERVER['HTTP_REFERER']); 
    $referrer =  str_replace("http://","", $referrer);
    $referrer =  str_replace("https://","", $referrer);
    if(!$_GET['apflag']) header("Location: http://www.ourkangen.net/affiliateprophetscript/go.php?uid=1&cid=1&apflag=1&referrer=$referrer&".$_SERVER["QUERY_STRING"]);
    if(!$_COOKIE['apid']) setcookie("apid", $_GET['apid'], time()+300000000);
?>
I have no idea how to even do that but there must be a way. Please tell me what I need to do in order to successfully add that tracking code

Thanks!
#programming #code #php #tracking #wordpress
  • I was getting a blank screen on the submission process when trying to post the above post.

    I guess I pressed "submit post" 3 times which is why this post appears 3 times in a row.
  • The best place to put common code like this is on a page that is called throughout your website. The header.php and footer.php files are perfect examples of that. So you could place this is either of those files and you should be set.

    You can edit these files right from your WP admin. Just find the files under the Appearance tab.
    • [1] reply
    • ya but I need the tracking only for one specific page on my website and that sounds like a global solution
  • From the look of it, it don't seems to be a tracking code, but a redirecting code. It is meant to redirect user to another page, as one of the line read " header("Location: http://somesite.com") "

    Normally, a tracking code is not PHP code, but a Javascript code (same as Google Analytics) or a single 1x1 pixel image (called tracking pixel). You don't have to edit any template files to insert them. Just edit your existing post and put the code there. That's all.

    - Rufas

Next Topics on Trending Feed