Skip to content Skip to sidebar Skip to footer

Php - How To Track Pages Visited By Users After They Leave My Website?

I have a website where people can search for cheapest prices of products gathered from 25 websites. It is not an e-commerce site, it's just a site trying to increase the traffic of

Solution 1:

If you use Google Analytics you can also track clicks as follows:

functiontrackOutboundLink(link, category, action, opt_label) { // google analytics trackingtry { 
    _gaq.push(['_trackEvent', category , action, opt_label]); 
    } catch(err){}

    if (link.target == '_blank')
        window.open(link.href);
     else {
        setTimeout(function() {
        document.location.href = link.href;
        }, 100);
     }
}

then use in the <a></a>

<aonclick="trackOutboundLink(this, 'CategoryName', 'ActionName', 'LabelName'); return false;"href="whatever.html"target="_blank">External Website Name</a>

where CategoryName, ActionName and LabelName can be anything you want and will show in Analytics

Solution 2:

you need to add a redirection php to save where they are going and redirect them manually. use something like: when a link to partner site is clicked which looks like: redirect.php?url=<?php echo urlencode("www.partnersite.com/products.php?productid=34"); ?>

redirect.php:

<?php$urltoRedirect = $_GET['url'];
//save $urltoRedirect to database / increment redirection count
header("Location: " . $urltoRedirect);
?>

you can't save that data neither to cookie nor session, since cookies are kept locally and sessions expire as soon as user close the browser / or after a limited time.

Solution 3:

The links redirecting to the sites themselves should not be writtent directly, instead they should be something like:

<ahref="YOUR_DOMAIN/redirect.php?id=1">The lowest price website</a>

Redirect.php will grad the id the user wants to visite, check it, secure it, write in your DB that this id was hit, means an update on one of your tables like

UPDATE site_hits SET hits = hits +1WHERE id = $id;

And then directly redirect the user using a header or meta

Post a Comment for "Php - How To Track Pages Visited By Users After They Leave My Website?"