PeterEistrup
PeterEistrup

Reputation: 1

Google Tag Manager gtm.click {{Click Text}}

I have a table list with details from shops, such as opening hours, phone numbers etc. When a user clicks the shops name, the before mentioned details appear using javascript.

I would like to retrieve the shops name (SHOP NAME) whenever a user clicks it using Tag Manager and then show the information in Google Analytics. I've tried several things in GTM without any luck.

Any help is really appreciated.

The code is as follows:

<table>
  <tbody>
    <tr class="row" valign="top">
        <td class="locationGridColZip" onclick="javascript: locationGridAddressToggle(this);">
          <input type="hidden" name="ctl00$ContentRegion$ctl00$locationGridView$ctl02$hfStore" id="ctl00_ContentRegion_ctl00_locationGridView_ctl02_hfStore" value="2620|55,65739|12,35353">CITY
            </td>
            <td class="locationGridColImgOFF" onclick="javascript: locationGridAddressToggle(this);">
            </td>
            <td class="locationGridColAddress" onclick="javascript: locationGridAddressToggle(this);">
              <h3>SHOP NAME</h3>                    
            </td>
            <td class="locationGridColShow">
              <a onclick="javascript:map.setCenter(new google.maps.LatLng(55.65739, 12.35353));map.setZoom(12);" href="/butikker.aspx#gmap">SHOW ON MAP</a>
              <a class="countryGmap countryGmap1" onclick="javascript:map.setCenter(new google.maps.LatLng(55.65739, 12.35353));map.setZoom(12);" href="/butikker.aspx#gmap"><img src="https://cdn.fotoagent.dk/webshop/production_solr/images/gmapDanmarkAlt.gif" alt="Vis på kort" style="border-width:0px;"></a>
      </td>
    </tr>
  </tbody>
</table>

Upvotes: 0

Views: 2552

Answers (2)

nyuen
nyuen

Reputation: 8907

Since you have jQuery enabled, you could enable it in a Custom JS variable with the following (please modify as needed):

function(){
   try{
      var ce = {{Click Element}};
      var storeName = $(ce).closest('tr').find('.locationGridColZip').text().trim();
      if (storeName.length > 0){
         return storeName;
      }
      return 'undefined';
   }
   catch(e){
   }
}

Upvotes: 1

J Brazier
J Brazier

Reputation: 884

You can do this with a custom JavaScript variable. It will depend on your circumstances, in particular which element the 'click element' identifies at the point you'd like the tag to fire, but I would use something akin to:

function ()
{
  return {{Click Element}}.getElementsByTagName("h3")
}

There are some good example of custom Javascript variables here: http://www.apasters.com/blog/google-tag-manager-custom-javascript-variable-examples/

There's also a good general overview by Simo Ahava here: http://www.simoahava.com/analytics/variable-guide-google-tag-manager/#6

Upvotes: 0

Related Questions