Search code examples
google-mapsgoogle-analyticsevent-tracking

Event tracking label to equal input field value


I have a website with an embedded google map on it, similar to https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete but with our offices displayed.

I'm trying to set up event tracking with google analytics and would like to track users using the map. I would like the label to be the value entered in the search field e.g.

<input type=”submit” onClick=”_gaq.push([‘_trackEvent('Search-form', 'Submit', 'London', 10]);” />

but 'London' = whatever the user has entered.

Is this possible?


Solution

  • Yes it is possible. You just need to add some code to grab the value entered for that particular field and populate that into the label parameter. If your city input field has a specific ID, then you could do something like

    _gaq.push(["_trackEvent", "category", "action", $("#city").val(), 10]);