Reputation: 21
I have this tracking pixel that would usually be placed in the body of a "installed successfully" page:
<img src="http://domain.com/adclick.php" width="1" height="1" border="0" />
But instead, I'd like it to fire when someone clicks a download button. Is this possible? I’m thinking the download button could call a javascript function onClick that would hit the adclick.php page?
Thanks James
Upvotes: 2
Views: 5853
Reputation: 828
Just create an image with
var trackingPxl = new Image();
and inside your download function set the src
trackingPxl.src = 'http://example.com/adclick.php';
Upvotes: 0
Reputation: 2394
Another possible solution, if you are using jQuery:
<script type="text/javascript">
function downloadButtonClicked() {
$('<img src="http://example.com/adclick.php" width="1" height="1" border="0" />').appendTo('body');
}
</script>
<a href="/download" onclick="downloadButtonClicked();">Download</a>
Upvotes: 0
Reputation: 7388
Try the following:
<script>
function fire() {
var img = document.createElement("img");
img.setAttribute("src", "http://domain.com/adclick.php");
/* set other attributes here */
document.body.appendChild(img);
}
</script>
<button onClick="fire();">Click me</button>
Upvotes: 2
Reputation: 228
This isn't much of a PHP question, but at least you're tagging.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
function iteration() {
$.get("http://domain.com/adclick.php");
return false;
}
</script>
<input type="button" value="Tracking Text" onclick="iteration();" />
Upvotes: 0