By default, the PureClarity script fires its requests after the DOMContentLoaded event fires. This ensures that the DOM is loaded, including the tags that PureClarity uses to retrieve BMZs and populate search results. For sites that have a long time until the DOMContentLoaded event fires this can provide a less than optimal user experience.
To provide a more optimal user experience there is an optional method for initialising PureClarity that allows the script to immediately fire its requests upon load and populate the relevant areas of the DOM as they become available. This involves modifying the `page_view` track event in the master function snippet.
The standard master function snippet is as follows:
(function(w, d, s, u, f) { w['PureClarityObject'] = f;
w[f] = w[f] || function() {(w[f].q = w[f].q || []).push(arguments)}; var p = d.createElement(s), h = d.getElementsByTagName(s)[0]; p.src = u;p.async=1;h.parentNode.insertBefore(p, h); })(window, document, 'script', '//pcs.pureclarity.net/<access_key>/cs.js', '_pc'); _pc('page_view');
To use the optional initialisation method, the `page_view` event takes an options object as an optional argument:
_pc('page_view', { page_type: 'homepage' });
Note that PureClarity will work as normal using the default behaviour if this optional argument is not provided.
The possible options to use in the optional argument are:
Name | Description | Example | Mandatory |
page_type | Specifies the page type so PureClarity knows which BMZs to load. The list of possible page types can be found below this table. | homepage | Y (if using the optional argument) |
sku | Specifies the product context of the current page. Used to load recommender results relevant to a product page. | P41923 | N |
category_id | Specifies the category context of the current page. Used to load category specific products for product listing pages or recommender results relevant to the category_id. | 3841 | N |
do_search | Indicates whether or not to perform a search on the page. If not present then this is inferred from the page_type, see the page_type section for more details. | true | N |
Page Type
The value provided in the page_type option is used for a couple of purposes. First, it defines the BMZ Group to load BMZs from. Second, it is used to infer whether or not a search should be performed if the do_search option is not present.
The possible page_type values are:
Page Type | Performs search if do_search not present |
homepage | N |
search_results | Y |
category_listing_page | N |
product_listing_page | Y |
product_page | N |
added_to_basket | N |
basket_page | N |
order_complete_page | N |
my_recommendations | N |
my_account | N |
content_page | N |
landing_page | N |
Examples:
//Specifies that the current page should use the homepage BMZs
_pc('page_view', { page_type: 'homepage' });
//Specifies that the current page should use the product page BMZs
//in the context of the product with a sku of P41923
_pc('page_view', { page_type: 'product_page', sku: 'P41923' });
//Specifies that the current page should use the product listing page
//BMZs in the context of the category with an id of 3841
_pc('page_view', { page_type: 'product_listing_page', category_id: '3841' });
Comments
0 comments
Please sign in to leave a comment.