如何创建和实施像素跟踪代码 [英] How to create and implement a pixel tracking code

查看:153
本文介绍了如何创建和实施像素跟踪代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,这是我一直在寻找的目标.

OK, here's a goal I've been looking for a while.

众所周知,大多数广告和分析公司都使用所谓的像素"代码来跟踪网站的浏览,交易,转化等.

As it's known, most advertising and analytics companies use a so called "pixel" code in order to track websites views, transactions, conversion etc.

我确实对它的工作原理有一个大致的了解,问题是如何实现它.跟踪代码由几部分组成.

I do have a general idea on how it works, the problem is how to implement it. The tracking codes consist from few parts.

  1. 跟踪代码本身. 这是用户在<head>部分中的网页上插入的代码.该代码的主要目标是设置一些客户特定的变量并调用*.js文件.

  1. The tracking code itself. This is the code that the users inserts on his webpage in the <head> section. The main goal of this code is to set some customer specific variables and to call the *.js file.

*.js文件. 该文件包含所有CRUD(创建/读取/更新/删除)cookie的魔力,可跟踪用户的事件以及与网页的交互.

*.js file. This file holds all the magic of CRUD (create/read/update/delete) cookies, track user's events and interaction with the webpage.

像素代码. 这是一个<img>标记,其中src属性指向图像*.gif(例如)文件,该文件采用页面上收集的所有参数,并将它们存储在数据库中.

The pixel code. This is an <img> tag with the src atribute pointing to an image *.gif (for example) file that takes all the parameters collected on the page, and stores them in the database.

示例:

WordPress像素代码:<img id="wpstats" src="http://stats.wordpress.com/g.gif?host=www.hostname.com&amp;list_of_cookies_value_pairs;" alt="">

WordPress pixel code: <img id="wpstats" src="http://stats.wordpress.com/g.gif?host=www.hostname.com&amp;list_of_cookies_value_pairs;" alt="">

Google Analitycs: http://www.google-analytics.com/__utm.gif?utmwv=4&utmn=769876874&etc

Google Analitycs: http://www.google-analytics.com/__utm.gif?utmwv=4&utmn=769876874&etc

现在,很明显,*.gif请求必须到达服务器端脚本语言才能读取参数数据并将其存储在db中.

Now, it's obvious that the *.gif request has to reach a server side scripting language in order to read the parameters data and store them in a db.

有人知道如何在Zend中实现这一点吗?

Does anyone have an idea how to implement this in Zend?

更新 我感兴趣的另一件事是:如何避免用户的浏览器加载缓存的*.gif?随机参数值可以解决问题吗?例如:src="pixel.gif?nocache=random_number",其中每个请求的nocache参数值都将不同.

UPDATE Another thing I'm interested in is: How to avoid the user's browser to load the cached *.gif ? Will a random parameter value do the trick? Example: src="pixel.gif?nocache=random_number" where the nocache parameter value will be different on every request.

推荐答案

由于Zend是使用PHP构建的,因此可能值得阅读以下问答:

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.

例如,在服务器端以及创建每个图像时,您可以添加一个随机URL ID:

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."'>";

?>

这篇关于如何创建和实施像素跟踪代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆