Particle Google Analytics Webhooks – ScreenView

Google Analytics

Particle Google Analytics WebHook series

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:

Particle Google Analytics Webhooks – ScreenView

This is is post number four in my Particle Google Analytics Webhook Tutorial series.  In this tutorial we will look at how to send a Screen view hit to Google Analytics using Particle a webhook.  Screen views are just generic hits sent to Google Analytics.    When a user opens a screen on an android app this is a ScreenView.    It is similar to a PageView on a website Google Analytics account.

Why you would want to use a screen view instead of an event. Opening a door could be a screen view i guess, however it could also be an event. I guess it will depend on how you want to do it. The main change here is the t parameter is screenview instead of event.

Create Webhook

While it is possible to create a webhook using the web interface I found it easier to do this command line

Place the following code into a file and run the following comand line

Particle webhook create eventHook.json

You should now have a new webhook created. Remember AccountId is the id of your account in the Google Analytics website.


When Google Analytics records a hit it gets the location from the location it was sent from. Webhooks are like little bots run by Particle. By sending uip we should be telling Google Analytics that the event is coming from us instead of particles servers. I had this working before but for some reason it doesn’t detect that i am sending events from Denmark in real time however the standard reports do detect that its Denmark.    I will work on this and see if i can track down the reason why it is no longer working as i would expect.


As you can see I am just building up a jSon string with the values i want the WebHook to send. CM1 is my custom metric number 1. This is just something simple i put together to show you how to do it.

You could just as easily a custom metric of the current temperature, or current light level.

I have this set up in my kitchen recording light levels. Then in the event the light level changes by more then 50 from the last detection I send a light change event. The main reason for this was to detect when the automatic lights outside are activated. We have a cat that likes to sleep on the car and were wondering how often it does this. Answer is not that often or its not triggering the light.

Remember there are some parameters that you must send in order to send the hit.  Check the previous tutorial  Particle Google Analytics webhook – Measurement Protocol before you start to remove some of the parameters I am sending here.


To see if your hits are being recorded you can go to the Real-time report you they should show up there as soon as you send them.


Creating a Google Analytics screenview webhook like I have done will enable you to send Google Analytics hits from any of your particle devices.   We are sending the account from the device so the webhook will work with any Google analytics account.

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.