How did you hear about us?

29 March 2017
Intended audience: store owner, web developer

We all want to know how effective our marketing has been and one way to do this is to ask shoppers when they register on your online shop "how did you hear about us?".

The 'HowDidYouHearAboutUs' drop-down box on the customer registration page.

The customer registration page that comes with your FoodCommerce online shop already has this facility complete with some very basic choices. Chances are that you will want to change them and most importantly you will want to add those things that you are spending money on. By adding them as choices, rather than leaving it for the shopper to specify, you will makes it much easier to accurately quantify where your customers are coming from.

Accessing and measuring the data

The data is stored against the customer and can be seen on the "general" tab against individual customers. To analyse it you need to export it out of FoodCommerce as a CSV and import it into another application of your choice.

  1. In the FoodCommerce control panel go into "customers" and click on the "export" tab.
  2. Choose "full export" and then click on the "export" button

    Export customer data
  3. The export will download as a CSV file which you need to save somewhere suitable.

CSV files are files that contain tabular data (numbers and text) in plain text and are primarily used to exchange data between applications. Typically you would open your customer export in a spreadsheet or import it into a database to analyse the data. In my example I am going to use LibreOffice Calc, which is a free open-source spreadsheet similar to Microsoft Excel. To download and install LibreOffice go to Ninite.

  1. Open the export in Calc.
  2. Click on a (single) cell somewhere in the data.
  3. In the "data" menu click on the "pivot table" and then "create".
    Creating a pivot table in LibreOffice Calc

  4. Calc will automatically select your data and offer it to you as "current selection" so just click "OK".
    Select the data range for the pivot table

  5. Next you are presented with the "pivot table layout" dialog box. Drag the "HowDidYouHearAboutUs" field into the "Row Fields" box and then again into the "Data Fields" box.
    Pivot table layout dialog box

  6. You will have noticed that Calc automatically decided we want to sum the values in the data field, which is incorrect as they are text values, and instead we need to count them. Double click on "Sum - HowDidYouHearAboutUs" to open the "data field" dialog box, change it to "count" and click "OK".
    data field dialog box

  7. Click OK to the pivot table layout.
    Pivot table layout dialog box after changing to 'count'

  8. We now have our pivot table showing how many times customers chose each option. You will of course notice there are more here than are available in the drop-down box on the registration page and these are the free text ones that customers entered when they selected "other". For our list to make any sense we now need to sort it with the option selected the most at the top. To do this select both columns and then click on "sort" in the "data" menu.
    Data sort menu

  9. If it isn't already there select "Count - HowDidYouHearAboutUs" as "sort key 1", check the "descending" radio button and click "OK".
    Data sort dialog box

    Finished pivot table example

Changing the options in the drop-down box

You may have noticed in the above example there were a lot of customers who chose "other" and then entered their own version of how they came across us. This suggests for too many there was not a suitable option and on closer examination it was that they already knew us so lets add another option to the drop-down box of "previous customer".

Important: to make these changes in your FoodCommerce theme you need to be comfortable editing raw HTML code.

  1. In the FoodCommerce control panel click "edit" against your current theme and "edit" against the "/register/" page, which you will find on page 3 of "core pages".

    opening the register page for editing

  2. Whereas it is of course possible to edit the code directly in FoodCommerce I would recommend when you are making big changes, like this one, you instead copy it into a text editor and do it there. Basically you make your changes, copy the code back, save it and then check the page works as intended. Repeat until you get it right. The advantages of doing it this way is that it is much easier to see what you are doing and more importantly if you do happen to make a mess of it you have an easy way of getting back by simply undoing in your text editor. As I have a Windows PC I am using a text editor named Notepad++ that can again be downloaded and installed using Ninite. If you are using a Mac then the free version of BBEdit seems to be the place to be.

    Having copied the code for the register page into my text editor I want to make it more readable and to do that I use the "language" menu and change it to "HTML". I am now looking for the <select> tag for the drop-down box and on an unchanged register page it should be somewhere around line 166. That is then followed by a number of lines with the <option> tags and finally a line with the closing </select> tag.

    The 'HowDidYouHearAboutUs' select tag in the register page code.
    click for full-size image

  3. Adding another option is simply a matter of copying an option that is already there, inserting it in a new line in the code and then changing the value in three places to the new option. The "other" option should always be the last one, but otherwise you can put your options in whatever order you want. In my example I have inserted a new "previous customer" option at the end just before "other".
    The 'HowDidYouHearAboutUs' select tag in the register page code.
    click for full-size image
  4. Test your code by registering as a new customer choosing your new option. Assuming that was successful, you should then check this new customer in the control panel to make sure the "how did you hear about us?" value says what you expect it to say.

The updated 'HowDidYouHearAboutUs' drop-down box on the customer registration page.


Tony Fear
Tony Fear