Search code examples
phpjavascripturlhttp-redirectoutbound

Tracking purchases via dynamic button that redirects to outbound links


I need to track purchases on my site via a dynamic button that redirects to another sites.

The code:

<div class="buyproduct">
<a onclick="target='_blank'" href="<?php echo $this->product['from'];?>">

<img src="http://xxx.com/data/images/buy.jpg" alt="Buy!"/>                          
</a>
</div>

Everytime a user clicks on the button it redirects to another site outside mine.

For example if I click on a jeans and then in the buy button, it redirects to wrangler site.

I need to track everytime this happens and know exactly to what url the user is beeing redirected.

The site is in PHP and Javascript.


Solution

  • You could create an intermediate page on your server, maybe something like (out.php). You could then redirect all traffic to the out.php page, do the processing there, and then redirect.

    <a target="_blank" href="/out.php?url=<?php echo urlencode($this->product['from'])?>">
        <img src="http://xxx.com/data/images/buy.jpg" alt="Buy!"/>
    </a>
    

    out.php

    <?php
    $url = urldecode($_GET['url']);
    /*
    MySQL CODE TO PROCESS TRACKING
    */
    header("Location: ".$url);
    exit;?>