I've called this blog post part one primarily as I am hoping to be able to write a few follow ups explaining the results we saw and ways we are evolving this project so please do check back or feel free to e-mail me with any questions.
The challenge :
Can you measure instore footfall with Google Analytics?
This was the question one of our clients posed to the analytics team at 4Ps Marketing.
There are numerous footfall technologies available however these can be quite costly and so we wanted to build our own solution.
We hosted a workshop to discuss a simple solution and decided to try using a PIR sensor. PIR sensors change voltage when they detect movement, so by having one near the entrance of the store would mean that in theory it would fire each time movement was detected.
The Measurement Protocol allows hits to be sent to Google Analytics from any internet enabled device. As most PIR sensors aren't internet enabled we needed something to connect to it and send hits back to Google Analytics. We decided on using a Raspberry Pi and connecting the PIR sensor to its GPIO (General Purpose Input / Output) header and then writing code to send a hit when movement was detected.
From Amazon we ordered:
1 x Raspberry Pi
1 x PIR Sensor
1 x USB Wireless Dongle
1 x Wireless Keyboard / Mouse (you don't need this but it helps)
1 x Jumper Leads
1 x HDMI Lead
1 x Power supply
Total Cost: £70
The PIR sensor had three connections, these supplied voltage and thus were wired to the appropriate power pins on the GPIO with the third being where the signal would change if motion detected.
After connecting the PIR sensor we then needed to write some script to "query" the appropriate GPIO pin and send a hit if movement was detected. For this, we used Python. Python is a very powerful development language and is part of the stack provided with the Linux distribution which comes with Raspberry Pi.
The first thing we needed to do was to include the GPIO library, the time library to allow us to access the sleep command and urllib2, this allows us to make HTTP requests.
import RPi.GPIO as GPIO
counter = 0
After this we have a loop, this looks for GPIO input on PIN 26 and when there is input we increment our counter and use the urllib2.urlopen function to send this hit to Google Analytics. In this example the client id is fixed (in essence meaning one session) and we are using pageviews to determine customers, however, we could easily make Python create a random Client Id if needed.
The dp parameter (page path) is /offline/pir/ with the value of the counter and the dt (document title) parameter is set to PIR Motion (%20 is a space).
We then sleep for a short period to allow the PIR sensor to clear.
counter = counter + 1
print "Someone has been seen " + str(counter) + " hit(s)"
urllib2.urlopen("https://www.google-analytics.com/collect?v=1&t=pageview&tid=" + strUA + "&cid=12345-12345-12345-12345&dt=PIR%20Motion&dp=/offline/pir/" + str(counter)
In order for this to work, the PIR sensor needed to have a clear view of the door and the Raspberry Pi needed power. We were able to use an in store television with a USB port to power the Raspberry Pi. As the television was located on the mezzanine above the main entrance it gave the PIR sensor a good view of the door.
View of PIR
Raspberry Pi on TV
Data began flowing into Google Analytics instantaneously. As a big advocate of GA I may be being biased here but I personally feel this shows how good a tool GA is in terms of it does this for free!
We created a very simple dashboard to show the number of instore visits (pageviews) and then widgets to break down pageviews by day and hour of the day. Unfortunately the Dashboard feature in GA is a bit limited (you can only have 9 bars) but with things like Data Studio 360, Analytics Canvas / Tableau it would be easy to mash up a nicer dashboard comparing visit performance by hour and day. I think it is important to state this was version one and so we wanted to see if the concept worked before elaborating.
Example GA Dashboard
Learnings and Next Steps:
The most important learning we have taken so far is to use an independent power supply. This may sound silly but as we were drawing power from a television it needed to be on and staff quite often fogot to turn it on, or turned it off mid day meaning no data. We're in the process of giving the Raspberry Pi its own supply (possibly thermonuclear ;) ).
Google Analytics also allows us to define Custom Dimensions and Metrics and so we are going to introduce a Store Visit metric and pass the Date and Time from the Raspberry Pi to Google Analytics. As the store has two floors we are also planning on introducing a second Raspberry Pi to the second floor so we can pass Floor and see what % of store visitors go upstairs.
We may also use a calculated metric to half the number of visits as it is possible for the PIR to detect people leaving as well as entering the store.
The next iteration then is one which is really exciting however also it could be quite difficult and that is to switch from PIR to use a camera to detect individuals possibly using Googles Cloud Vision API. This would stop double counting and potentially (depending upon how simple or complex you wanted to make things) allow use the hash of a persons face somehow as a User or Client Id understanding how many times the same person may visit a store.
I would really love to hear from you if you can help or have any ideas so feel free to reach out either on Twitter, or by e-mail!