I am using SwiftMailer to send emails to people who are registered on my website. I want to track opens & click throughs, and I have the opens working perfectly. The click throughs are almost there...
When you open the email I use an image set to 1px by 1px that loads a PHP script. This tracks the person's email address and records the number of times they've opened it in my MySql database. All of the links in the email first take the user to a script on my site that uses GET requests to read their email address and the email that the link was contained in. This script then records this information in my DB.
The problem is that when you click on a link in the email, it records the first click just fine. And it will record every different link a user clicks on, but it will only record each click from the same source once.
IE: In the footer of each email is a link to like the company on Facebook, and another one for Twitter. When you click on FB, the DB is updated to say you clicked on 1 link. If you click on FB again, it will not update. But if you click on Twitter, it will say you clicked on 2 links.
If I load the script directly in my browser it will keep track of each click properly.
EDIT:
URL structure: https://<my website>.com/emails.php?type=click&email=<id of email>&address=<user email>&url=<link to click on>
PHP:
if($_GET['type'] == 'click') {
$email = $_GET['email'];
$address = $_GET['address'];
$url = $_GET['url'];
// Get Worker Email
$sql = mysqli_query($con, "SELECT * FROM worker_emails WHERE id='$email'");
$row = mysqli_fetch_array($sql);
// Unserialize Array
$array = unserialize($row['clicks']);
// Update Array
$array[''.$address.'']['Clicks'] = $array[''.$address.'']['Clicks'] + 1;
// Serialize Array
$array = serialize($array);
// Update Click Tracking
mysqli_query($con, "UPDATE worker_emails SET clicks='$array' WHERE id='$email'");
// Send User to Link
header("Location: ".$url);
}
Suggestions?