SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2008
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question track hyperlink clicks

    I have a php website which is only accessible to members. Once member logs in, there are two hyperlinks on a particular web page. I would to track how many times the hyperlinks are clicked by which member. Could someone advise me how to achieve this?

    I did some research online, they are all about counting hyperlink clicks on the whole website, no matter who made the clicks. What I really want is to track the number by different members.

    I'm really stuck here and your help is greatly appreciated!

  2. #2
    SitePoint Zealot Steveiwonder's Avatar
    Join Date
    Nov 2008
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    //home.php
    Code PHP:
     
    <?php
    echo "<a href='page1.php?click=1'>Page1</a>";
    echo "<a href='page2.php?click=1'>Page2</a>";
    ?>

    page1.php
    Code PHP:
    <?php
    page_tracker();
     
    //page code...
    ?>

    page2.php
    Code PHP:
    <?php
    page_tracker();
     
    //page code...
    ?>

    Function to call at the top of each page.
    Code PHP:
    <?php
    function page_tracker{
      if(isset($_GET['click'])){
        if($_GET['click']=='1'){
          //insert user id, date, time, page into DB?
        }
      }
    }
    ?>

    I'm sure you can do it with some OnClick function using Javascript which might be more effective, but i can't help you there.

  3. #3
    SitePoint Addict
    Join Date
    Jan 2008
    Posts
    326
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Pass the final page as a GET variable to an intermediate page that will log the information for you. Assuming the user is already logged in you could log your information in a database, etc and then send them on to their destination.

  4. #4
    SitePoint Zealot evilunix's Avatar
    Join Date
    Jun 2008
    Location
    York, UK.
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code on page 2 (or whatever page you want to track clicks to):
    Code PHP:
    <?php
    if(isset($_GET['from'])) {
        $from = $_GET['from'];
        // log the current page, $from and the user id
        // if we came from page 1, we know they clicked the link to page 2 on page 1
    }

    Your link from page 1 is something like index.php?p=page2&from=page1


Bookmarks

Posting Permissions

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