Question

I need to track a button that redirects users to another site something like pinterest does. If someone clicks on an image it opens the image in bigger size, with a button that if u click on it it redirects to the original site, like pinterest.

As a way to resolve it I crated a sendmail function in order to send me an email every time a user clicks on a button. The code is this:

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

<?php
$message = "Item buy: ";
$link = $this->pin['from'];
mail('xxx@mail.com', '@Buy', $message.$link);
?> 
<img src="http://example.com/data/images/buy.jpg" alt="buy"   />                            
            </a>
            </div>

The problem is that it sends an email every time someone clicks on the image and I need to only track every time someone clicks on the button "buy.jpg"

Was it helpful?

Solution

PHP is executed at the server, so that send-mail is going to send you an email every time someone loads that page and not when someone clicks on your button.

You should link a PHP page with an AJAX request, which fires every time that image is clicked if you want that email only then.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top