How to create and implement a pixel tracking code

陌路散爱 提交于 2019-12-02 14:58:07
nickhar

As Zend is built using PHP, it might be worth reading the following question and answer: Developing a tracking pixel.

In addition to this answer and as you're looking for a way of avoiding caching the tracking image, the easiest way of doing this is to append a unique/random string to it, which is generated at runtime.

For example, server-side and with the creation of each image, you might add a random URL id:

<?php

  // Generate random id of min/max length
  $rand_id = rand(8, 8);

  // Echo the image and append a random string
  echo "<img src='pixel.php?a=".$vara."&b=".$varb."&rand=".$rand_id."'>";

?>

First of all, the *.gif doesn't need to be that file type, the only thing that is of interest is the Content-Type http header. Set that to image/gif (or any other, appropiate type) in the beginning, execute your code and render some sort of image to the response body.

Well, all of the above codes are correct and is good but to be certain, the guy above mention "g.gif"

You can just add a simple php code to write to an sql or fwrite("file.txt",$opened) where var $opened serves as the counter++ if someone opened your mail... then save it as "g.gif"

TO DO all of this just add these:

<Files "/thisdirectory">
 AddType application/x-httpd-php .gif
</Files>

to your ".htaccess" file but be sure to make a new directory for that g.gif or whatever.gif where the directory only contains g.gif and .htaccess

Just adding my 2 cents to this thread because I think an important, and frequently used, option is missing: you don't necessarily need a scripting language to capture the request. A more efficient approach is to use the web server access log (like apache access log for instance) to log the request and then handle that log with whatever tools you see fit, like ELK stack for instance.

This makes serving the requests much lighter because no scripting language is loaded to prepare the response, just native apache response, which is typically much more efficient.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!