Use Google Analytics Events to track how many times PushCrew opt-in for web notifications was displayed

Vipul Bansal
3 min readDec 11, 2016

--

Google Analytics

Web push notifications are the newest additions to an already long list of digital marketing channels. Numbers has it, web notifications, often referred to as browser notifications, have been very instrumental in upping the count of website re-engagements.

While it is important to bring visitors back to your website, it is equally important to measure the impact of web notifications to estimate something as complex as ROI or as simple as how many people actually clicked the notification.

Besides click through rates and delivery counts, you also might want to have a precise count of the number of times the opt-in modal was displayed to the user. In case you are unaware, opt-in modals are small boxes that ask for user’s permission to send them to web push notifications.

Opt-in modal

If you select Yes, you will be added to subscriber list and will receive all future web notifications from that particular website. Don’t worry you can always unsubscribe whenever you want.

To track the number of times opt-in modal was displayed, I am going to use Events feature provided in Google Analytics.

Just to give a little background, Events is an immensely useful feature that allow you to record any form of interaction happening on your website like clicks, video plays etc.

The only caveat involved in implementing Events is that it requires a little coding to get things in place. So, if you are not the ‘coder-type’ the ride might get a little scary for you.

The process::

The simple logic flow behind tracking the opt-in modal is like this:

  1. Detect if a particular class attribute is available. Repeat until the attribute is available.
  2. Fire a Google Analytics event.

This is what the final code looks like:

$(document).ready(function() {

var pc_modal = setInterval(function() {
if($(‘.pushcrew-chrome-style-notification’)){

clearInterval(pc_modal);
trackPcModal();

}}, 1000);

function trackPcModal(){

ga(‘send’,’event’,’pc-mod’,’pc-mod-visible’,’pc-opt-in’)

}});

The function trackPcModal fires off as soon as the opt-in modal is detected. The Event command has 3 components:

  1. Event category — pc-mod
  2. Event action — pc-mod-visible
  3. Event label — pc-opt-in

There is also a fourth component called Event value but we don’t require it here.

The result::

Now that everything is set, you would want to get back to your Google Analytics dashboard and view the result.

Under Reporting section, click on the Behavior tab and then go to Events. Next click on Top Events.

Top Events

As you can see, our event category pc-mod was recorded 5 times. This is indeed the total number of times the opt-in modal was displayed.

The limitation::

  1. This code will work only for PushCrew triggered opt-in modals.
  2. Since customised opt-ins, like the one shown in the image above, are available only for HTTP implementation, this code will work only if you are using HTTP implementation of web push notifications on your website.

--

--