Skip Navigation

[Resolved] Count click events on markers with GTM

This support ticket is created 5 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 5 years, 6 months ago.

Assisted by: Waqar.

Author
Posts
#1246317

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.

#1246503

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