Support > Advanced Topics > How to integrate your store locator with Google Analytics

How to integrate your store locator with Google Analytics

In this guide we describe how to integrate your store locator with Google Analytics. This guide can also be used to integrate your locator with any external script.

The most common use for this sort of integration is so that you can track conversions inside Google Analytics whenever a visitor searches for a location inside your store locator. Whenever a search event occurs inside the locator, the following local function is called if it exists:

storeLocatorSearchEventHandler(eventData)

First, you'll need to ensure that you have added the Google Analytics Javascript tracking snippet to your web page by ensuring that the steps in the code at the top of this page have been completed as shown below: https://developers.google.com/analytics/devguides/collection/analyticsjs.

Once that's been completed, adding the following script anywhere underneath the above Javascript will enable tracking of store locator search events in your page: 

<script>
  function storeLocatorSearchEventHandler(eventData) {
    ga('send', 'event', 'Store Locator', 'Search', 'Store Locator Search Event');
  }
</script>

Getting information from other locator events

You can also retrieve additional activities from the locator such as tracking when someone clicks on the 'My Location' button or on a Store Name to view it's details on the map. To track this data you could add the following script as an example:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script>

  $('body').on('click', '.storelocator-viewlink', function() {
    ga('send', 'event', 'Store Locator', 'Search', 'Store Locator Store Click Event');
  });
</script>

Getting more information from the Search Event

So, the above script will call the ga function to send a pageview event whenever a search event takes place in your store locator:

Additional data about the search event is passed inside the eventData object and this can be used to enhance or provide further detail of the conversion type. Here are the attributes of the eventData object:

  • address: The address that was searched (either the address entered into the input field or the address of the midpoint of the map if the 'My Location' button was used to geolocate the visitor)
  • distance: The distance in kms to the closest location
  • filters: Any filters that were applied
  • map_lat: The latitude of the address
  • map_lng: The longitude of the address
  • nearest_storeid: The StoreID of the closest location
  • nearest_storename: The name of the closest location
  • referrer: The HTTP referrer if available (web page which linked to this page)
  • type: The type of search - either "geolocate" where geolocation (the My Location) button was used or "address" where an address was searched for.
  • uid: Your unique account user ID 
  • url: The URL of the current page

Any of these attributes can be passed from the EventData object in the first Javascript example.