Some time ago I needed a QR code for a project and also wanted to find out how many people used that QR code. Googling returns many, many options, too many in my opinion. Each web site has different features, some provide counters, every web site has different data types you can export (from bad quality jpgs and pngs to vector graphics), but on most you need to register and some even require payment. There are also desktop applications available, but they also have mostly poor quality images. Since a QR code is actually a quite simply thing, it just has to follow some encoding rules.
“QR Code Structure Example 3” by Bobmath – This file was derived from QR Code Structure Example 2.svg: . Licensed under CC BY-SA 3.0 via Commons.
Since it is so simple I thought probably someone has already made an R package and yes, there are even two (see below)! To know how many people visit my blog I already use Google Analytics, so this approach is the best option for me and I don’t need to register on any other website (which would be required anyway for a trackable QR code).
Contents
Google URL builder
First you need to go to Google URL builder. Enter the Website URL (in my case blog.haunschmid.name), the Campaign Source (e.g. “qrcode”), Campaign Medium and Campaign Name (I used “qrcode-shirt” for both because I created a shirt with my QR code). You can also fill the other fields if you want to.
What happens is that the Google URL builder appends parameters to the URL of your website which Google Analytics can use. You can actually do this by yourself, just set
- utm_source=campaign_source
- utm_medium=campaign_medium
- utm_campaign=campaign_name
such that it looks like this (without the new lines of course):
utm_source=campaign_source
&utm_medium=campaign_medium
&utm_campaign=campaign_name
But using the Google URL builder is definitely more convenient 🙂 And if you’ve never created and URL and wondered what & and ? stand for, just use the URL builder!
Create QR Code using R
Package “qrcode”
For creating QR codes I found the package qr code. You install it like a normal R package and then you simply use
qrcode_gen("blog.haunschmid.name/?utm_source=qrcode&utm_medium=qr-blog&utm_campaign=qr-qrpost")
to generate a QR code (you might notice I used different parameters for this URL – just for this post).
When you are in RStudio, you can save the image using the export functionality or just use the png() method to save an image.
Package “qrencoder”
There is also a package qrencoder but I think it is only available from github. Here is a howto by the package author. Installing this package requires the library devtools which allows to directly install packages from github.
library(devtools)
install_github("hrbrmstr/qrencoder")
library(qrencoder)
When you are using devtools the first time like me this takes some time.
Google Analytics
If you have setup Google Analytics for you website or blog, you can easily use Google Analytics for tracking usage of your QR code instead of using one of the many web services. They often include redirects (otherwise they can not count how many users call the link) and I don’t like that.
Go to your Google Analytics menu to Acquisition > Campaigns > All campaigns and you will get campaign information.
Go to Acquisition > All traffic > Source/Medium and you will get that information.
Now you know why there were three mandatory fields when building the URL, campaign, source and medium! 🙂