looking for a little help with a click tracking script

Discussion in 'PHP' started by mikemason, Sep 22, 2009.

  1. #1
    I have been having a hard time finding a script to track my newsletter members clicks, I know this should be an easy 10 line code. and I think I saw this on an open source forum once but now can't find it.

    I want to pass links like: http://mysite.com/?test@mail.com?file.zip
    (this is the same as http://mysite.com/file.zip)

    I want to track the email address + the files name when clicked to a flat file .txt or .html

    any thoughts?
    Thanks, Mike
     
    mikemason, Sep 22, 2009 IP
  2. firemarsh

    firemarsh Peon

    Messages:
    153
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    why not send it in a form using a POST variable to the page?

    So something like

    
    <form id = 'foo' name='foo' action = 'filedownload.asp' method = 'post'>
    <input type = 'hidden' name = 'userEmailFromDatabase' value= 'test@email.com'>
    <input type = 'hidden' name = 'filename' value = 'file.zip'>
    <input type = 'hidden' name = 'subchk' value = '1'>
    <input type = 'submit' name = 'submit'  value = 'Download File'>
    </form>
    
    PHP:
    then your filedownload.asp would look something like

    
    
    if ($_POST['subchk'] == '1' && $_POST['filename'] > '' && $_POST['userEmailFromDatabase'] > '' ) {
    
     $track =  callTheFunctionForTracking($_POST['userEmailFromDatabase'], $_POST['filename']); // call a function which updates the database with an email to filename link 
    
    // then set the function to return true on success so you know you're tracking and then start the file download
    if($track){
    echo '<a href = './files/file.zip'> click here to download the file </a>'
    } else {
       echo'error message goes here';
    
    }
    
    PHP:
    Not saying this code here is the best or will work out of the box, (didnt test) but might give you an idea?
     
    firemarsh, Sep 22, 2009 IP
  3. dweebsonduty

    dweebsonduty Active Member

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    Digital Goods:
    1
    #3
    Using hidden fields is a great way to do it.

    But if it is just a link and not a form, you could use an onclick function in the url and do some ajax call.
     
    dweebsonduty, Sep 22, 2009 IP
  4. mikemason

    mikemason Peon

    Messages:
    184
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks firemarsh, forms is a really good idea, but my auto-responder has trouble with forms... but I may try it for something else.

    Thanks dweebsonduty, how would the ajax call look? I really don't know any ajax
     
    mikemason, Sep 23, 2009 IP