简体   繁体   English

如何实现对网页浏览量进行计数的跟踪像素?

[英]How to implement a Tracking Pixel that counts the Page Views?

I want to implement a tracking pixel in my pages and email like this: 我想在我的页面和电子邮件中实现一个跟踪像素,如下所示:

<img src="someurl/tracking.js">

What do I have to write in my tracking.js in order to get the code executed? 为了执行代码,我必须在tracking.js中编写什么? Can I use JQuery inside this code? 我可以在此代码内使用JQuery吗?

The src attribute of the img tag can be either absolute image URL or relative image URL. img标签的src属性可以是绝对图像URL或相对图像URL。 You cannot just run arbitrary JavaScript that way. 您不能仅以这种方式运行任意JavaScript。 Use instead 改用

<script src="someurl/tracking.js"/>

I found the answer in this blog post: http://grooovygeorge.wordpress.com/2012/12/13/serving-a-blind-gif-from-a-string-in-grails/ 我在此博客文章中找到了答案: http : //grooovygeorge.wordpress.com/2012/12/13/serving-a-blind-gif-from-a-string-in-grails/

 import org.springframework.security.core.codec.Base64

class TrackingController {


private static final String PIXEL_B64 = "R0lGODlhAQABAPAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="
private static final byte[] PIXEL_BYTES = Base64.decode(PIXEL_B64.getBytes())


def track() {

 // track the request here...
 // send the GIF image
 response.setContentType("image/gif")
 response.outputStream << PIXEL_BYTES
 return // this statement is required.
}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM