Unless you’re a real Google Analytics geek, you’ve probably already heard from the Measurement Protocol but haven’t seen any applications besides the coffee machine video. This video suggest you need to be McGyver in order to be able to work with the Measurement Protocol. Sure, you could be, but you don’t have to. In this article, I’ll show you how to connect Spotify with Google Analytics. As a music fanatic, it’s a fun experiment for me to conduct. I realise there’s no real business objective yet. My hope is however, that this experiment provides you with inspiration on how you could use the Measurement Protocol versus your needs.
Resources related to this procedure already exist. An example is this article. Our methodology is fairly similar but includes an updated version of the applets & music technology used.
Step 1 - The blueprint
What do we want to do? It’s fairly simple:
- Each time a track is saved in Spotify
- We send an event to Google Analytics that maps the artist and track combination
Of course, we could dive straight into API’s and do some wicked coding. Full disclosure, I can’t as I’m not a developer at heart. But that doesn’t have to stop us. We’ll use an intermediary technology called IF THIS THEN THAT or IFTTT. According to the web IFTTT “is a free web-based service to create chains of simple conditional statements, called applets.”
It lets you create an action (output) based on a particular trigger (input). And that’s exactly what we’ll need.
In short - It does exactly what it says it does: if action A happens, then execute action B.
In our case our “applet” will do the following:
If a track is saved on Spotify then send a webrequest to Google Analytics.
We’ll need to 2 building blocks for this.
- The first one is an existing Spotify action called “new saved track”.
- The second is something called a “webhook” action service (formerly called “maker”).
The webhook action service basically allows you to hook up any input to anything that can handle a webrequest. In our case we’ll combine it with Spotify, but the possibilities are endless
This combination sets out the blueprint for our little experiment.
Step 2 - Build your hit!
The webhook action service will require a package or hit to be sent. The next step is to create the credentials that will allow us to send this package. We’ll do this using the Google Analytics Hit Builder.
After providing authorisation you’ll need to fill in the following elements:
- Set V to 1 as it refers to the Measurement Protocol version you’ll be using. The only version available today is version 1.
- Set t to event.
- Fill in your UA-ID in the tid field.
- Click the refresh icon in the cid field. It will provide you with a user id which will allow GA to recognise you as a single user. Instead of the refresh button, you could actually pick a value of your choice as well.
- The field above this form “hit payload” will now be populated with a URL. Copy paste this URL.
Step 3 - Complete the IFTTT recipe
The last step is to complete the webhook credentials touched upon in “step 1 - The Blueprint”.
- Open up the Webhook configuration.
- Past the URL you created in “step 2 - Build your hit!” into the URL field.
- Enrich the URL with the actual event values. More information can be found here. In this case we only used the mandatory values:
- EC - Event category
- EA - Event action
- EL - Event label
- Set the method to GET.
- Set the content type to TEXT/PLAIN.
- Save the recipe
The results in action
When listening to / discovery a new track on Spotify and hitting the “save” button, a package will be sent to GA. This works on all devices you’re logged into using the same Spotify account (as you authorised access). As such, it’s the equivalent of sending an event from a website, as you would usually do. However, in this case, the website has been replaced by a custom action, being a Spotify save.
The desktop equivalent of this action is pressing the little hearth.
An index of all saved songs becomes visible in Google Analytics under the “events” report.
Happy music exploration & Measurement Protocol experimentation!