Track Maps using Google Analytics

Last year I gave a talk at the Google Developer Day about Google Maps API - Best Practices and focused in the final section on how to use Google Analytics to keep track of your app’s usage.

Because many map applications are single-page websites, it is hard to analyze the user’s behavior because the default _trackPageview() method is called only once per page.

One way to solve this is to use virtual pageviews. For example, you can create a path structure that represents the logical structure of your content:

// track current page
pageTracker._trackPageview();

// track a virutal page view
pageTracker._trackPageview(
  "/path/to/virtual/page.html"
);

// example: virtual map view
pageTracker._trackPageview(
  "/map/germany/berlin/reichstag"
);

Note: Virtual pageviews will be added to your total pageview count and might create a wrong impression of daily usage. To avoid this, switch to Event Tracking provided by Google Analytics.

This is what an event tracker looks like:

pageTracker._trackEvent(
  'category', 
  'action', 
  'label (optional)', 
  'value (optional)'
);

The category describes a group of objects you want to track, eg. “Markers” or “Search”. The action is uniquely paired with each category, and commonly used to define the type of user interaction for the object. label and value are optional parameters and provide additional dimensions and numerical data about the event.

To following example shows how to track clicks on a marker:
function track_click(){
  pageTracker._trackEvent([
    'Marker', 
    'Click', 
    marker_title
  );
}

google.maps.event.addListener(
  marker, 
  'click',
  track_click
});
We use Event Tracking on several aspects of our applications:
  • General interaction (e.g. use of Map Type switcher)
  • Map content (Marker click or drag events)
  • Track load performance (“Init”, “DOM Ready”, “Map Drawn”)
  • Location Search (e.g. Geocoding requests)

Two screens of a sample report:

As you can see, Google Analytics Event Tracking is a highly flexible and powerful way to measure the usage of Google Maps applications and lets you analyze user behavior on single-page websites.

Address

Ubilabs GmbH

Juliusstraße 25

22769 Hamburg, Deutschland

About Ubilabs

Ubilabs develops individual web-applications and is an official Google Maps Enterprise Partner. Ubilabs is specialized in location based services and Google Maps integration.

Official Google Partner

© 2013 Ubilabs Imprint