Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13

Thread: Link Tracking

  1. #1
    New Coder
    Join Date
    Jun 2008
    Posts
    44
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Link Tracking

    I'm sure that it's possible, but I'm wondering if it would be within the scope of a novice developer to do the following:

    I would like to know on a form when the user has been referred to that form from another website. Particularly one parent website. That way we could differentiate between leads that were developed through our own ppc and leads developed from the parent site.

    From the parent site there will be links directly to the form itself and to the index page (at which point they may later navigate to the form page).

    We do not have access to the parent sites FTP so anything done would have to be from our side (we could give them a special link though).

    Thanks for your help,
    Tyler

  • #2
    Regular Coder ohgod's Avatar
    Join Date
    Jun 2008
    Location
    Ohio
    Posts
    579
    Thanks
    6
    Thanked 69 Times in 69 Posts
    Quote Originally Posted by Len Whistler View Post
    Study PHP. Below are php functions that will read the IP address and the website your visitor came from, very usefull.

    $_SERVER['REMOTE_ADDR'];
    $HTTP_SERVER_VARS['HTTP_REFERER'];


    You then can use php to write this information to a database or txt file, I use just a simple txt file.



    -----------------
    ^

    you could save said links to a db and then runs your stats off that

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    REMOTE_ADDR will not give you the address you were referred from, its the attempt to resolve the IP of the browsing user.
    HTTP_REFERER is not very reliable either as it needs to be sent from the originating server.
    $HTTP_*_VARS are deprecated as well, you shouldn't rely on those.

    You are better of sending a querystring through you're url for anything thats remote indicating what is what. Next best bet is to use the HTTP_REFERER, but make sure you account for if the remote browser doesn't send it.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #4
    Regular Coder ohgod's Avatar
    Join Date
    Jun 2008
    Location
    Ohio
    Posts
    579
    Thanks
    6
    Thanked 69 Times in 69 Posts
    well personally i don't use that, but he's saying he doesn't have access to all the referring pages

  • #5
    New Coder
    Join Date
    Jun 2008
    Posts
    44
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Wouldn't it also be possible to add a link to a special page that simple runs a short php script to assign variable $referred="yes" and then add something in the header to pass it along using GET to each page.

    Then on the form page, no matter how many other pages the navigate through prior to filling out the form I can do a simple conditional to check referred?

    Will this be feasible?

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Yes, this was my recommendation, but I'm not sure how you're considering the implementation. The idea would be to have say an affiliate site link to you with a special id indicating that its their site referring traffic to yours. If you do not have access to these other site or have a contact who can change it, you're next best bet is $_SERVER['HTTP_REFERER'] (yes its spelled wrong, I don't know why they did that >.<). Generally, I find that HTTP_REFERER is sent by other servers, but it is no guarantee (my personal server does not send referrer for example).

    The idea that this would work is say I'm visiting a sister site, and I click on a link thats directed to you're site. You have a link thats like: http://youresite.com/?referrer=44646f5b77b1da67y322 for example and when I hit you're page you can establish the referrer from that point on. If you hash you're id's that are used to identify these sites you are more likely to keep the integrity of the referrals - if you do make sure the hashes are well thought out: md5(1) is pretty predictable, most people wouldn't waste their time on determining a 32byte length hash identifying a single referring id.

    This is a technique that you would use to establish a relationship with a specific site that has been identified. This will also prevent someone from directing their browser manually from the other site to you're site out of coincidence - something I do not consider to be a referral. HTTP_REFERER is really more to get a basic idea of where people are coming from, search engines for example. Since there is no direct relationship between the two sites there is no priority to establish a solid referrer.

    Does this make sense, I'm not great at explaining things, so let me know if I'm confusing you on anything!
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #7
    New Coder
    Join Date
    Jun 2008
    Posts
    44
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Once $referrer comes in from that website I would then have to pass it between each page in case they navigate around the site and then come back, correct?

    Why would I need to hash this arbitrary string used to identify the referral website? I don't see any security issues with it, unless this is to prevent someone from changing the link, but it's either referred by this one person or not, it's not like there are a bunch of referralers (referries?).


    Thanks so far! Going to work on implementing it today.

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    You can get around passing the referrer around by placing it in a session variable. This allows you to 'hide' the referrer from the user browsing but keep track of it at the same time.
    The hashing is not for security so much as for integrity. This depends of course on what its for and may not be necessary. Since the originals are passed through a url than technically a hash wouldn't help you at all - its just an idea to stop people from selecting arbitrary referrers while at you're site if you have a predictable format for you're referrers. This wouldn't be a big deal if you were say, tracking incoming users from you're sister site, but may be a bigger deal if you pay royalties for it. Do you understand what I'm getting at, I'm not great at explaining things, lol.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #9
    New Coder
    Join Date
    Jun 2008
    Posts
    44
    Thanks
    7
    Thanked 0 Times in 0 Posts
    I have it set up to work correctly now on the individual session page, but now I need to check into using sessions. I've never used them before and would like to learn.

    Could you point me to a tutorial on the hashing? I have a brief understanding of hashing through cryptography, but have no idea how to do the implementation.

    I think you're must better at explaining than you give yourself credit for. After all, you've been thanked 98 times in 95 posts

  • #10
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Thanks!
    PHP's builtin sessions are a piece of cake to work with, I found this one just now http://www.tizag.com/phpT/phpsessions.php. Seems pretty good, its brief, but covers it pretty good, and is using new session unlike most old ones (session_registers have been deprecated since 4.2).
    PHP Code:
    <?php
    session_start
    (); // Session start needs to be set before headers are sent  Just put it in the first line always.
    if (isset($_GET['referrer']))
    {
        
    $_SESSION['referrer'] = $_GET['referrer'];
    }
    You can retrieve a session anywhere you want, as long as that page has session_start() applied to the top. Access just like any other superglobal, but use the isset to check for existance.

    Cryptography is complex as you know. Don't stress yourself and just use a builtin function like md5() or sha1() for example. Of course, the downside is you now need to do comparisons between the hashed value and the original value that has been hashed, but thats really no big deal either.
    PHP Code:
    $hashedStr md5($myStr); 
    Done and done!

    Sessions have a default configuration that is kind of a pitfall. The directives are:
    Code:
    session.use_cookies = 1
    session.use_only_cookies = 1
    session.use_trans_sid = 0
    This forces you to use cookies to accept sessions which can be a pain. If you're not in secure and open sessions are really not a huge threat, I'd change these directives:
    PHP Code:
    <?php
    ini_set
    ('session.use_cookies'1);
    ini_set('session.use_only_cookies'0);
    ini_set('session.use_trans_sid'1);

    session_start();
    Its a pain, but the benefit is now you can use sessions without cookies enabled, and use_trans_sid will automatically append a session identifier to you're links and forms.

    Hope that helps!
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • Users who have thanked Fou-Lu for this post:

    p8ball4life (07-17-2008)

  • #11
    New Coder
    Join Date
    Jun 2008
    Posts
    44
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Having some trouble with it for some reason.

    Code:
    <?php
    
    ///////////////////////////////
    // Referred?                   //
    ///////////////////////////////
    
    session_start();
    if (isset($_GET['ID'])) {
        $_SESSION['referred'] = $_GET['ID'];
    	
    	if ($_SESSION['referred'] == "1337")
    		$referred2 = "Referred from xyz.com";
    	
    	else
    		$referred2 = " ";
    }
    
    else
    	$referred2 = " ";
    
    /////////////////////////
    // End Referral Code //
    /////////////////////////
    
    ?>
    
    //Later in the form I have the email body formatted with details and $referred printed like //the rest of the variables:
    
    $body .= "On $date, $fname $lname provided the following information:
    
    CONTACT INFORMATION
    --------------------------
    $fname $lname
    $email
    phone: $phone
    $haddress
    $city
    $state
    $zip
    
    ADDITIONAL COMMENTS
    ---------------------------
    Relocation Kit: $relocationdrop
    Daily Emails: $emaildrop
    $referred2
    ---------------------------
    $comments
    
    \n\n";
    Not sure why it's not picking up the $referred2 variable in the email body. I'll do some more troubleshooting in the meantime.

    Update: When testing the variable referred2 is working properly and reports the correct value based upon the ID value, but for some reason the '$referred2' inside of the body formatting is not working. I don't think it's a scope issue, because I tested $referred2 right in front of the $body = and it worked fine.
    Last edited by p8ball4life; 07-17-2008 at 07:54 PM.

  • #12
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Change the way you are looking at it and always fetch from the session variables.
    PHP Code:
    <?php
    session_start
    ();
    // This will prevent overwriting of the variable if it already exists.
    if (!isset($_SESSION['referred']))
    {
        
    $_SESSION['referred'] = '';
        if (isset(
    $_GET['ID']))
        {
            
    $_SESSION['referred'] = $_GET['ID'];
        }
    }

    // Then on whatever script you have (if its on a different one, make sure it has session_start on it too!)
    $referred '';
    if (isset(
    $_SESSION['referred']) && $_SESSION['referred'] == '1337')
    {
        
    $referred "Referred from xyz.com";
    }
    Just use $referred instead of $referred2 on the message body.

    You're coming along quite well, just keep tweaking it and eventually you'll get it to work
    Last edited by Fou-Lu; 07-17-2008 at 08:02 PM.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #13
    New Coder
    Join Date
    Jun 2008
    Posts
    44
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Do I need to have the session started on all pages they can possibly navigate to? It doesn't keep the variable if they navigate away then come back to the form.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •