[英]Send the Selected Item From Drop Down List To Google Analytics With a GTAG Event
I want to to be able to send the selected item from a drop down list to GA using the gtag event code. 我希望能够使用gtag事件代码将所选项目从下拉列表发送到GA。 I added the onclick gtag code below but I just need to be able to add the selected item into the event label. 我在下面添加了onclick gtag代码,但我只需要能够将所选项目添加到事件标签中。 could someone help me with that? 有人可以帮我吗? Thanks. 谢谢。
<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>
You can use this: 您可以使用此:
$("#dropdownList").val();
So your link becomes: 因此,您的链接变为:
onclick="gtag('event','someevent', {'event_category':'somecategory','event_label':$("#dropdownList").val()});">Contact Us</a>
Note there is no validation here, so if a user doesn't select anything and click on the link, it will be empty. 请注意,此处没有验证,因此,如果用户未选择任何内容并单击链接,则该链接为空。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.