Trending Products

Shopify includes a number of sort options, however a key one is missing - the ability to sort by the number of views a product has had recently.

The Trending Products feature adds a new sort order that will show the most popular products currently on your site, and behind the scenes uses an advanced algorithm that you can even adjust to suit your store.

A key concept of the trending products feature is the way that the views are calculated - instead of being the top views for all time, it is an system that calculates the hottest products on your store for the last few days or weeks.

Generally the order of your products will update once every 24 hours, but this may be longer for very large stores.

Installation

To get started you need to start tracking your visitors. This is as easy as installing the tracking code using the install button, or using the theme installer, and some additional code examples are below should you need further help.

Once you have installed the tracking code it is best to leave it a few days to collect data, but this is optional as the system will only re-order your selected collections when there is enough data present.

Updating Collections

You can set the sort order a number of ways within Power Tools. Note that the collection will appear as sorted manually in the Shopify Admin.

The easiest way is to press the 'Set All Collections To Trending' button on the Trending products admin.

Secondly you can set the sort order when creating a collection within Power Tools, or you can edit a single collection within the Power Tools interface.

You can also set all smart or custom collections to have the trending sort order using the Sort Orders App if you have it installed.

And finally you can add this as a sort order option in Sort Selector app.

Settings

There are a number of settings that go with this app, and in general the defaults are suitable for all stores initially.

Starting Position

Generally you would want to highlight new products, however there is also a trade-off between displacing your current most popular items with un-proven new products.

To solve this dilemma the starting position setting allows you to choose the insertion point for new products as a percentage.

For example if you set this value to 20% and you have 100 products, then new products will be started at position 20.

A value such as 20% gives a good balance between making sure new products get showcased, without disrupting sales of your existing top products.

Average Days

The algorithm uses an exponentially decaying value for the daily views, which sounds complex (and is) - but it can be easily approximated by saying how many days of data to include in the sample. If you are familiar with a moving average, then that is also a good approximation.

The longer you set the days to average over the less change there will be in the sort order from day to day.

Since it can be quite hard to know what value to use there is an Auto setting which will calculate the optimal value based on your traffic.

This can also be overridden - allowing you to specify how many days worth of data you would like to use when the sort orders are updated.

Average Days (Auto) Speed

If you use the Auto setting above there is an optional setting for tuning how often products will change order.

If you select Slow 3 times more data will be used, and if you select Fast then one third (1/3) of the data will be used compared to the Standard setting.

Minimum Standard Deviation (Advanced)

If you site does not receive much traffic then even a small number of visitors can have an significant affect on the sort order. If your sort orders are being affected by a small number of users then increase this number, and if the sort orders are not updating every day and you would like it to then decrease it.

Enabled/Disabled

You can keep the sort orders constant for a period of time by un-checking the enabled box. This might be useful during a sale or other marketing period. Note that the app will still collect data, it just won't change the order of the collections.

Tracking Code

The tracking code is listed below if you want to install it manually (an automatic option is available on the setting page). Just paste it before the </body> tag near the bottom of your theme.liquid file in themes.

<!-- Power Tools view count code -->
{% if template contains 'product' %}
<script type="text/javascript">
    (function () {
        var oldonload = window.onload;
        window.onload = function(){
            var scr = document.createElement("script");
            scr.setAttribute('async', 'true');
            scr.type = "text/javascript";
            scr.src = "https://ping.powertoolsapp.com/ping/{{ shop.permanent_domain }}/{{ product.id }}?weight=1{% if collection %}&collection_id={{ collection.handle }}{% endif %}";
            ((document.getElementsByTagName('head') || [null])[0] ||
                    document.getElementsByTagName('script')[0].parentNode).appendChild(scr);
            if(oldonload){oldonload()}};
    }());
</script>
{% endif %}
<!-- Power Tools view count code -->

Weighting

As noted in the URL there is a weight option, which allows you to set how many 'views' to record. Since the tracking code can be called anywhere an idea might be to add an additional call when the product is added to cart with a stronger weighting of say 5.

This can give you a mix of 'Trending' and 'Best Sellers'. There a helper in the theme installers section for adding such functionality.

Order By Revenue

For many stores the most expensive items will be the most profitable, but may also have a lower view count due to having a smaller audience.

To push higher value items up a smart way is to order your products by the total revenue that is shown to users, as opposed to the number of clicks.

For example a $100 product is weighted as 100, while the $10 is weighted as 10. This means that the $10 product needs to be clicked at least 10 times more frequently to be shown higher than the $100 product.

Simply change the snipped in your theme.liquid where is says ?weight=1 to ?weight={{ product.price | money_without_currency }}

As you can see the change is quite simple and you are free to create more complex logic.

Note that this will also reduce the 'Average Days' value when using the 'Auto' setting.

Questions

How come the sort order does not match my Google Analytics?

Google and Power Tools use different algorithms to determine what users are real users, and what counts as a view.

Also Google will show you the total sum of view for a month or whatever period you select, whereas Power Tools uses an advanced algorithm to give a greater weighting to more recent views. The app utilises an exponential decay function for the weighting, to get technical.