Last active
November 22, 2021 16:28
-
-
Save carmoreira/b72dce3ccf064f39b324f5c5af8a9561 to your computer and use it in GitHub Desktop.
Interactive Geo Maps - Track events with Google Analytics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let mapID = 22309; // change to your MAP ID | |
let mapContainer = document.getElementById('map_' + mapID); | |
mapContainer.addEventListener('mapready', function(ev) { | |
iMaps.maps[mapID].series[0].mapPolygons.each(function(region) { | |
region.events.on("hit", function(ev) { | |
let data = region.dataItem.dataContext; | |
gtag('event', 'map_click', { | |
'event_label': 'My Map', | |
'event_category': 'Click', | |
'value': data.name, | |
'non_interaction': true | |
}); | |
}, this); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment