2016-09-26 112 views
0

我有一個表格,裏面有來自商店的詳細信息,例如開放時間,電話號碼等。當用戶點擊商店名稱時,前面提到的細節會使用javascript顯示。谷歌標籤管理器gtm.click {{Click Text}}

每當用戶使用跟蹤代碼管理器點擊商店名稱(SHOP NAME),然後在Google Analytics中顯示相關信息時,我想檢索這些商店名稱(SHOP NAME)。我已經嘗試了GTM中的幾件事,但沒有任何運氣。

任何幫助真的很感激。

的代碼如下:

<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> 
+0

你能否發佈有問題頁面的鏈接? – nyuen

+0

進入調試模式並點擊您選擇的元素。現在在GTM調試控制檯中應該有你的列表中的點擊。選擇點擊並查找變量的值。點擊元素變量包含您可能正在查找的值。 – michaelsinner

+0

@nyuen有問題的頁面是https://www.skoringen.dk/butikker.aspx – PeterEistrup

回答

0

您可以用自定義JavaScript變量做到這一點。這將取決於你的情況,特別是你想代碼觸發該元素的「點擊元素」標識的點,但我會用一個類似於:

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

有一些很好的例子自定義JavaScript變量在這裏: http://www.apasters.com/blog/google-tag-manager-custom-javascript-variable-examples/

還有由廝磨艾哈佛這裏良好的總體概述: http://www.simoahava.com/analytics/variable-guide-google-tag-manager/#6

0

既然你已經啓用了jQuery,你可以用下面的自定義JS變量來啓用它(請修改爲需要):

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){ 
    } 
}