简体   繁体   English

使用GTAG事件将下拉列表中的选定项目发送到Google Analytics(分析)

[英]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.

相关问题 如何将下拉列表中所选项目的值作为参数传递给Controller(Google图表)? - How to pass the value of the selected item from the drop down list as an argument to the Controller (Google charts)? Google Analytics(分析)使用gtag发送两个自定义维度 - Google Analytics send two custom dimensions with gtag 从数据库中警报选定的循环下拉列表项 - Alert selected drop-down list item of looping from database 如何检查是否从 HTML 下拉列表中选择了一个项目? - How to check if an item is selected from an HTML drop down list? 如何设置变量或存储下拉列表中的选定项目 - how to set a variable or store selected item from drop down list 获取所选下拉列表项的值 - Get value of selected drop down list item 下拉列表以保留所选项目 - Drop down list to stay on selected item 使用jQuery /纯jscript从HTML下拉列表(选择下拉列表时下拉列表)中获取事件数据 - Get event data from an HTML drop down list (the list that drops down when a drop down list is selected) using jQuery / plain jscript 仅打印下拉列表中选定的项目 - Print only selected item from drop down 如何将下拉列表中选定项的值替换为jQuery中文本框的更改事件的某个值? - how to replace value of drop down list selected item to some value on change event of text box in jquery?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM