Listing the top viewed products

Our web access logs capture the product IDs (the item field in the logs) that the users view and add to their shopping carts. Understanding the top products that people view can help influence our sales and marketing strategy, and even product direction. Products viewed on an e-commerce website might not always necessarily translate into sales of that product though.

In this recipe, we will write a Splunk search to chart the top 10 products that users successfully view and compare against the number of successful shopping cart additions for each product. For example, if a product has a high number of views but the product is not added to carts and subsequently purchased, this could indicate that something is not right—perhaps the pricing of the product is too high.

Getting ready

To step through this recipe, you will need a running Splunk Enterprise server, with the sample data loaded from Chapter 1, Play Time – Getting Data In. You should be familiar with the Splunk search bar and the time range picker.

How to do it…

Follow the given steps to search for the top products being searched over the past week:

  1. Log in to your Splunk server.
  2. Select the Search & Reporting application.
  3. Ensure that the time range picker is set to Last 7 days and type the following search into the Splunk search bar. Then, click on Search or hit Enter.
    index=main sourcetype=access_combined uri_path="/viewItem" OR uri_path="/addItem" status=200  | dedup JSESSIONID uri_path item | chart count(eval(uri_path="/viewItem")) AS view, count(eval(uri_path="/addItem")) AS add by item | sort – view | head 10
  4. Splunk will return a tabulated list of items (products), detailing the number of times a product was successfully viewed versus the number of times that product was actually added to the shopping cart.
    How to do it…
  5. Save this search by clicking on Save As and then on Report. Give the report the name cp02_top_products_viewed and click on Save. On the next screen, click on Continue Editing to return to the search.

How it works…

In this recipe, our search returned a count by item of how many items were viewed versus how many were added to the cart. In this case, the item field represents a unique item ID that pertains to a specific product. Let's break down the search piece by piece:

Search fragment

Description

index=main sourcetype=access_combined

You should now be familiar with this search from the earlier recipes in this chapter.

uri_path="/viewItem" OR uri_path="/addItem" status=200

Following best practice of making our search as granular as possible, we only search for events that contain uri_paths related to viewing items and adding items, and have a successful status code of 200. This type of granularity greatly limits the number of records we search, making our search a lot faster.

| dedup JSESSIONID uri_path item

Using the dedup command, we de-duplicate our data by the JSESSIONID, the uri_path, and the item values. Why? Well, because a user in a given session could view a product many times in that session before adding it, so we want to ensure that we only count one view and one addition per user session of a product.

| chart count(eval(uri_path="/viewItem")) AS view, count(eval(uri_path="/addItem")) AS add by item

Using the chart and eval commands, we count the number of views and adds by item.

| sort - view | head 10

Using the sort command, we sort in descending order on the view field, such that the items with the most number of views are at the top. We then leverage the head command to keep only the first 10 rows of data, leaving us with the top 10 searched products.

There's more…

This recipe provides us with some insight into product views and subsequent shopping cart additions that might then lead on to a sale. However, we can keep adding to the search to make it even easier to understand the relationship between the two.

Searching for the percentage of cart additions from product views

We can further amend the search from this recipe to evaluate a new column that calculates the percentage of product views added to the cart. We do this using the eval command and some basic math, as follows:

index=main sourcetype=access_combined uri_path="/viewItem" OR uri_path="/addItem" status=200  | dedup JSESSIONID uri_path item | chart count(eval(uri_path="/viewItem")) AS view, count(eval(uri_path="/addItem")) AS add by item | sort – view | head 10 | eval  cart_conversion=round(add/view*100)."%"

We firstly evaluate a new field called cart_conversion and then calculate the percentage, dividing purchase by view and multiplying by 100. We use the round function of eval to eliminate the decimal places and then tack on the % character at the end. Now, we can easily see what percentage of views lead to cart additions.

See also

Also refer to the following recipes for more information:

  • The Displaying web page response time statistics recipe
  • The Identifying the top-referring websites recipe
  • The Finding the most used web browsers recipe
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.150.89