简体   繁体   中英

Tracking onhashchange events

Looking for a best practice for the following scenario:

In a traditional webapp, we perform analytics on logs based on http GETs. The project in question leverages HTML5, jQuery and Mustache.js to dynamically render templates from JSONP calls. The views respond to onhashchange events to create bookmark-able URLs, with parameters via jQuery BBQ.

My issue is that the hash isn't passed to the server, so these changes in URL aren't going to show in regular access logs. The best solution that's been offered so far, is to track the hash changes locally, and PUT / POST them to a service when the browser fires onbeforeunload .

I'm interested in other solutions for tracking local hash history changes on the server, I can't use Google Analytics for this.

Call a simple file ( track.html , track.php , track.asp ) depending on your server architecture. The file can be empty.

onhashchange , do an AJAX call to the simple tracking file with the hash as the querystring ( track.html?hash=hashStringValue ). This should show up in your access logs.

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.

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