Particle Google Analytics webhook – Introduction


Partical

ForWord

[wp_ad_camp_3]
I actually get a lot of requests for tutorials, and I have been known to accept the challenge on a number of occasions, however the time frame is normally a week or more. Last night I was given a challenge I couldn’t refuse.      My original tweet was wondering if anyone would be interested in a library for Particle that would send hits Google Analytics.      It didn’t take that long for me to get a response.

Oooo could you write a webhook for it and share the code in a tutorial?

What was fun about this is that the request was from Richard Whitney who just so happens to work at Particle.    I have a personal rule if anyone at Google asks me for a favor I do it as soon as I can.    I think its time I extend that.   Someone like Richard wants me to write him a tutorial.   You got it no problem!

However you need to remember a few things as you follow along on this journey.   This will be a journey, because it wont be possible to explain this in just one  tutorial you are going to get a tutorial series.   I like to design my tutorials with the novice in mind.   I am going to assume that you know little or nothing about Google Analytics and analytics in general.  Each tutorial will walk you though the step in the journey to sending your IoT data to Google Analytics.   If you happen to be an expert in Google Analytics and familiar with the measurement protocol feel free to fast forward to the next tutorial.

A lot of this is going to be ruff ideas and theories.  No one to my knowledge has attempted this before.  We are walking a new path on our journey we may have to kill some of the bugs together.

A word of warning I have only been playing with Particle now for 5 days,  the first versions of this code will likely be rough around the edges. I hope that some other people will be willing to help me polish it.     All I am going to do is teach you how to send the hits.  How you send them and what you send will in the end be up to you.    Also all I have right now is a little light sensor so we are using that for an example, more stuff has already been ordered.

Particle Google Analytics WebHook series

Google Analytics
Welcome to my Google Analytics Particle webhook tutorial series.   As you know from a number of my past tutorial series I like to keep things short.   I would rather stick to one topic in each tutorial so that you get the full idea of what we are trying to achieve.   You are more then welcome to skip around in the series if I mention something that was covered in another tutorial I will link you to that so that you can find clarification if you need.

In the first tutorial I will give you a little introduction into Google Analytics and my opinion on how it can be used with Internet of things devices (IoT) .  In the second tutorial we look how the measurement protocol is used to send data to Google Analytics and I explained about the parameters that are required to send data to Google Analytics.  In the third tutorial we looked at how to send Events to Google Analytics using Particle webhooks, and in the final tutorial we will look at sending Screen Views to an application Google Analytics account.

Particle Google Analytics WebHook series:

 

Google Analytics Introduction

Google Analytics is a freemium web and Mobile analytics service offered by Google that tracks and reports website traffic. Google Analytics is now the most widely used web analytics service on the Internet.

Now that you know the technical term lets look at it.    Google Analytics was designed to record web hits (pageviews) and mobile device hits (ScreenViews).       When a user visits your website a page View hit is recorded in a web Google Analytics account.   When a user logs into a mobile application a screen View hit is recorded in an application Google Analytics account.   If you send a page view to a mobile account it will accept the data but it will not be able to display it to you because the analytics is different so you are essential wasting your time.

Google Analytics with IOT

Google analytics was designed with the idea of either page views or screen views in mind.  So there are only two types of Google Analytics accounts Web Google Analytics accounts used for websites which record page views,   and mobile Google Analytics accounts which record screen views.    Like I said before they can not be mixed.

So what do we do with IoT devices they are there are no pages or screens to view.   I have had sometime to think about how best to log analytical data to Google Analytics from an IoT device.   With my experience on how Google Analytics works I am going to show you my best recommendations as to how to hack Google analytics to record data for IoT devices. This is not optimal and I may bring it up with the Google Analytics team that it might be an idea for them to begin to offer IoT analytics as well.      However that being said I have made a number of requests to the Google Analytics team in the past and they have not always agreed with me.  So for now we hack it.

[wp_ad_camp_5]

And hack we shall

For starters I want you to create an Mobil or Application Google Analytics account.   In my opinion this is as close as we are going to get,   Internet of Things (IOT) is really not web in my opinion.   If you disagree find me on twitter love to argue the semantics of this with someone.   If you have a web account already there is no reason you cant use that.

Go to the Google Analytics website if you don’t already have an account create one using a gmail or any other email address.    I am not going to tell you how to do that if you are playing with IoT devices I am sure you can handle creating your own Google Analytics Account.

  1. Go to Admin at the top of the page
  2. In the left hand column there is a drop down under Account click create new account. It should be the last option
  3. At the very top of this page there are two buttons Website and Mobile app.    It is very important now that you click the Mobile app button
  4. Fill the rest of the stuff out,  Account Name and App Name.    It does not matter what you name them totally up to you.
  5. Set the time zone your device is currently in
  6. finally click get Tracking Id

If you already had a Google Analytics account set up you can just create a new web property for your Internet of Things (IOT) device that will work as well.   To send data to Google Analytics all you is the tracking id found in the Property column.   It should look something like this UA-XXXXXXX-1

Now for the bad news.   If you just created a new Google Analytics account and didn’t just add a new web property under an existing Google Analytics account.    You can come back and continue tomorrow.  It takes 24 – 48 hours for a Google Analytics account to start showing data.    Anything you try to send now is going to be lost in space somewhere. I am actually not sure if it even excepts the hits or if they just vanish or if maybe we will see them tomorrow.   Either way there will be no way for us to verify that what we are doing is working so its best to just come back tomorrow and continue.

Conclusion

You should now understand why we are going to have to hack Google Analytics to send hits to a system that was not really designed for IoT.    You should have a Google Analytics Mobile account all set up on the Google Analytics Website.

If that is true the next step is to understand a little about how data is sent to Google Analytics.   Using the Measurement protocol.   That is going to be tutorial number two.

 

 


About Linda Lawton

My name is Linda Lawton I have more than 20 years experience working as an application developer and a database expert. I have also been working with Google APIs since 2012 and I have been contributing to the Google .Net client library since 2013. In 2013 I became a a Google Developer Experts for Google Analytics.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.