Run Experiments on Shopify Search Pages

Integrate Shopify

Note: All the details provided below are only useful for targeting based on page tags. 

If you used the tracking code for Shopify as explained on our Shopify Integration Page, you should already have page tags defined. You will need to modify them as follows. We'll use the page tag that defines the "page type" but any of the page tags that allows string comparison can be used.  If you do not already have any page tags defined, you need to define them before the main tracking code.

Testing on the search page when no results are returned

In order to do that we need to first tag the search results page, when there are no results, with a page tag. If you used the Shopify integration instructions, you already have a line that looks like this:


var _conv_page_type = "{% if template == 'index' %}homepage{% else template == "collections" %}collection{% else template == "article" %}article{% else template == "product" %}product{% else template == "cart" %}cart{% else %}other{% endif %}";

 We'll change that line to 

 var _conv_page_type = "{% if template == 'index' %}homepage{% elsif search.performed and search.results == empty %}searchnoresults{% else template == "collections" %}collection{% else template == "article" %}article{% else template == "product" %}product{% else template == "cart" %}cart{% else %}other{% endif %}";

Note the bold part which is what we added extra. That will define the page type as "searchnoresults" which we will use in the advanced experiment targeting in order to create an experiment's Site Area that only targets those pages:

 

Testing on the search page when there are results returned

In order to do that we need to first tag the search results page, when there are results, with a page tag. If you used the Shopify integration instructions, you already have a line that looks like this:

 var _conv_page_type = "{% if template == 'index' %}homepage{% else template == "collections" %}collection{% else template == "article" %}article{% else template == "product" %}product{% else template == "cart" %}cart{% else %}other{% endif %}";

 We'll change that line to 

 var _conv_page_type = "{% if template == 'index' %}homepage{% elsif search.performed and search.results != empty %}searchwithresults{% else template == "collections" %}collection{% else template == "article" %}article{% else template == "product" %}product{% else template == "cart" %}cart{% else %}other{% endif %}";

Note the bold part which is what we added extra. That will define the page type as "searchwithresults" which we will use in the advanced experiment targeting in order to create an experiment's Site Area that only targets those pages:

 

Of course the code can be combined so that it defines the tag with the right value for both with and without results. That way you can run tests on both pages without changing the tagging again:

var _conv_page_type = "{% if template == 'index' %}homepage{% elsif search.performed and search.results == empty %}searchnoresults{% elsif search.performed and search.results != empty %}searchwithresults{% else template == "collections" %}collection{% else template == "article" %}article{% else template == "product" %}product{% else template == "cart" %}cart{% else %}other{% endif %}";
Have more questions? Submit a request

Comments