Trigger Convert polling when URL hash changes

 

Important

If you use the latest version of the Convert script, none of what is described in this article is relevant, as it has built in and optimized features for SPAs.


Convert experiments do not run when the URL has a hash.

For example:

A website homepage loads with the following URL:

https://domain.com/

After clicking on a link the page loads something like this:

http://domain.com/#features

But, if we setup an experiment with that URL, and the user, does not load that URL as the first visit to the site, the experiment will not trigger. 

This is a common issue of single page apps (SPAs).

Just add the following code to the Project Global JS section of your project.

convert.$(document).ready(function () {
convert.$(window).on('hashchange', function () {
_conv_q = _conv_q || [];
_conv_q.push(["run","true"]);
});
});

Note: Please test it with your SPA framework, as it might not detect hash changes in all frameworks.