1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Code to Track Clicks on a Banner

Discussion in 'PHP & Perl' started by nam6641, Jul 8, 2010.

  1. nam6641

    nam6641 Supreme Member

    Joined:
    Nov 15, 2008
    Messages:
    1,476
    Likes Received:
    914
    Location:
    East Coast
    Is there a simple piece of code I can use that will allow me to track the number of clicks on a banner on my site? Something that will write to a text file and not cause any delay for the user in being redirected to the banner's site?
     
  2. Grizzy

    Grizzy Senior Member

    Joined:
    Nov 11, 2008
    Messages:
    919
    Likes Received:
    999
    Just a thought, but you could use a little php script to do that.

    Code:
    <a href="http://www.example.com/banner.php?id=1"><img src.... /></a>
    would be what you would use for the banner. And banner.php could look something like this:

    PHP:
    <?php

    $file 
    fopen('data.txt''w');
    fwrite($file$_GET['id'] . '\n');
    fclose($file);

    ?>
    Very very basic, but you get the idea. It would be better to write to sql, and keep in mind if you do anything other then direct link to an offer it will cause some sort of delay (unavoidable).
     
    • Thanks Thanks x 1
  3. voyevoda

    voyevoda Regular Member Premium Member

    Joined:
    Mar 21, 2010
    Messages:
    217
    Likes Received:
    97
    Location:
    Eastern Front
    You probably want to use this instead:

    PHP:
    $file fopen('data.txt''a');
    Otherwise, you will truncate the file every time someone clicks on the banner.

    I'd actually do this:

    PHP:
    <?php file_put_contents('log.txt'$_GET['id']. "\n"FILE_APPEND); ?>
    Only one line. :)
     
    • Thanks Thanks x 1
  4. Grizzy

    Grizzy Senior Member

    Joined:
    Nov 11, 2008
    Messages:
    919
    Likes Received:
    999
    haha voyevoda is right, my bad. Listen to him, he is a much more knowledgeable guy when it comes to this sort of stuff then me :D