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? Can I use JQuery inside this code?
The src attribute of the img
tag can be either absolute image URL or relative image URL. You cannot just run arbitrary JavaScript that way. 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/
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.
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.