Firing asynchronous quantcast pixels

If you are building an AJAX-driven web application (like a swipe-driven mobile website) and want to register quantcast pageviews at times other than window.onload, here is a small change to the code snippet quantcast provides that will get you there.

Note that this does not remove or replace any existing functionality, you will still need to initialize it with their snippet:

<code><script type="text/javascript">var _qevents = _qevents || [];

(function() {
	var elem = document.createElement('script');

	elem.src = (document.location.protocol == "https:" ? "https://secure" : "http://edge") + "";
	elem.async = true;
	elem.type = "text/javascript";
	elem.onload = function(){
               // attach the asynchronous pixel handler
		__qc.async = function(){
			__qc.qpixelsent = [];
			        qacct: __qc.qopts.qacct
	var scpt = document.getElementsByTagName('script')[0];
	scpt.parentNode.insertBefore(elem, scpt);  
<script type="text/javascript">
_qevents.push( { qacct:"p-test123"} );
<div style="display: none;"><img src="" height="1" width="1" alt="Quantcast"/></div>

Just drop that snippet in your page and you will be ready to track asynchronous events, here is an example of usage:

	method: 'GET',
	success: function(response){
		// track the asynchronous page view

Happy Coding!

3 thoughts on “Firing asynchronous quantcast pixels

    • Glad it was helpful to you. I never found documentation on that feature, I had to reverse engineer their library to figure out how to force `firepixels` to send.

Leave a Reply