簡體   English   中英

使用GTAG事件將下拉列表中的選定項目發送到Google Analytics(分析)

[英]Send the Selected Item From Drop Down List To Google Analytics With a GTAG Event

我希望能夠使用gtag事件代碼將所選項目從下拉列表發送到GA。 我在下面添加了onclick gtag代碼,但我只需要能夠將所選項目添加到事件標簽中。 有人可以幫我嗎? 謝謝。

<div class="col-sm-4">
<div data-elementID="12"></div>
<div data-elementID="13" class="pb-3"></div>
<select id="selectCountry" class="form-control mb-3"></select>
<a href="#" class="button btn" target="" id="element-14" onclick="gtag('event','someevent', {'event_category':'somecategory','event_label':'theselecteditem'});">Contact Us</a>
</div>

您可以使用此:

$("#dropdownList").val();

因此,您的鏈接變為:

onclick="gtag('event','someevent', {'event_category':'somecategory','event_label':$("#dropdownList").val()});">Contact Us</a>

請注意,此處沒有驗證,因此,如果用戶未選擇任何內容並單擊鏈接,則該鏈接為空。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM