Best Use Case for Google Analytics in WAB?

7808
24
11-14-2014 08:02 AM
BrianO_keefe
Regular Contributor II

So I want to have Google Analytics for my WAB Maps. I realize this is a MUCH better environment for this than back in Flex (where you had to have widgets and such to do this) but I am curious what the best way to do this would be?

I have considered creating a WAB Template map that has Google Analytics code pre-populated requiring minor adjustments. I have considered trying my hand at a Widget (for several reasons). I have considered just editing the code once the WAB Map is completed.

Is there a recommended process for this? Or are we wild westing this stuff right now since WAB is still in BETA?

0 Kudos
24 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Brain,

   I don't believe that esri has come out with a recommended process for this. The way that I always did it in Flex and will continue to do it in the StemApp is to add the GA code to the StemApp template (index.html).

DanielChantlos1
Occasional Contributor

Robert,

I would like to use Google Analytics to track widget usage rather than paste the tracking code into the index.html of of the WebApp. I've see Rene's post above, however some time has passed.... Is this possible? 

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Daniel,

  I have not had the need to track widget usage but since the widget manager uses events when a widget is opened then a developer could easily add widget usage to Ian's widget.

0 Kudos
ReneRubalcava
Frequent Contributor

This kind of depends on what you are looking to get out of it. GA will give you page/session stats, but not much details as to whether anyone ever clicks on a draw or search button.

Check out Dave Bouwmans post on this subject, lots of good stuff there. His samples are in Backbone, but no reason you couldn't do same hooks in widgets. Only problem is this is only good for widgets you write. It would be much easier if widget interaction in WAB was done via dojo/topic, but I'm not sure if it is.

BrianO_keefe
Regular Contributor II

My thoughts are simply a webcounter (if you will) showing each time a REST Service is hit. It would be GREAT if it could compile these hits into sessions. So that I could tell that USER X accessed the map, hit the REST Service 25 times (probably by scrolling or address locating) and access this REST Service twice via popups (I could tell popups because certain layers have popups and certain layers don't).

AmyKnight
New Contributor III

We also have a need to have Google Analytics tracking each time our WAB app is opened.  We have a web map application built with WAB for Developers 1.1 and recently deployed to our web server.  We have a snippet of GA code that goes into all our other web pages and I was asked to add it to the web map 'page'.  I am not sure where to paste it or best practice for doing so.  Any help would be appreciated! 

0 Kudos
StanMcShinsky
Regular Contributor

Amy,

If you just want to know when the app was opened and some user stats on that then you just need to place the GA script tags in the head of the index.html file for the app.

-Stan

AmyKnight
New Contributor III

Thank you Stan!  I think I've got it-   I was just doing what you suggest following Robert's post above.

SebastianRoberts
Occasional Contributor III

Thanks for this thread.  It was very useful.  I got analytics going, and thought I would share my method.  In the index.html, before the closing </head> tag,  I added the Analytics code from the top of this Google Page

I wrapped the whole thing in an if statement:

if (document.domain === 'gis.nevcounty.net' )

so that the tracking only occurs once the app is deployed to our production web server.

We have a separate tracker code for our widget analytics, so I also added this line:

ga('create', 'XX-XXXXXX-X', 'auto',{'name': 'widgetTracker'});

widgetTracker is just a name that is assigend so that you can send page views or events to either tracker.  Just use ga('send'....     for the first tracker, or ga('widgetTracker.send'.....  for the second tracker.

So when the eSearch tool is opened, I log a pageview using the widgetTracker code, by adding this code to the beginning of the postCreate function:

if (ga){

  ga('widgetTracker.send', 'pageview','MN_Widget/' + this.name);

  }

The above will only log once when the widget is created, so it tells you that the tool was used during this session.  I log specific events for various widget functions.  So for instance if a user does a search using the eSearch tool, I added the following lines in Widget.js to the onSearch function that will track the type of search that they did:

if (ga){

  var trackerLabelString = this.config.layers[this.AttributeLayerIndex].name

  ga('widgetTracker.send', 'event', 'search', 'by Attribute: ' + trackerLabelString , {'nonInteraction': 1});

}

According to the documentation, the 'nonInteraction' object will send the event without impacting your bounce rate.