Hello,
I have a toolset map hidden link with about 40 markers.
I would like to track the "opening" of those markers by clicks on the map, in order to be able to know which are more frequently opened by visitors.
How may I :
1- Add a class or listener to detect the click with GTM ?
2- Get the marker's title to store in the "label" in GTM ?
Thank you.
Hi Roman,
Thank you for waiting.
1- Add a class or listener to detect the click with GTM ?
- As explained in another support thread ( https://toolset.com/forums/topic/looking-for-event-on-infowindow-open/#post-491692 ), you can add a click listener event for each map marker, using custom script.
For example, the following code will show the title of the marker in a popup, when it will be clicked.
jQuery( document ).ready( function( $ ) {
jQuery( document ).on( 'js_event_wpv_addon_maps_init_map_completed',function(event_settings) {
var markers = WPViews.view_addon_maps.markers;
var map='map-1';
for(var marker in markers[ map ]) {
markers[ map ][marker].addListener('click', function() {
alert(this['title']);
});
}
});
});
2- Get the marker's title to store in the "label" in GTM ?
- Once, you have the information about the clicked marker, the next step would be to push it to the Google Tag Manager for tracking, using the "dataLayer".
Following are some useful guides on the topic:
hidden link
hidden link
For more personalized assistance around custom code, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/
regards,
Waqar