javascript-Google Analytics(分析)事件跟踪:跟踪下拉列表中的链接
作者:互联网
我正在尝试跟踪表单中下拉菜单中包含的链接,但是我不确定如何将动态值返回给事件跟踪代码.
我的代码是:
<form class="form" action="">
<select name="ddmenu_name" id="ddmenu_name" style="width: 80% !important;">
<option value="" selected>Select option</option>
<optgroup label="Other">
<option value="link1" name="name1">Option 1</option>
<option value="link2" name="name2">Option 2</option>
</optgroup>
</select>
<input type="button" name="Submit" value="Go!" onClick="window.open(ddmenu_name.value,'newtab'); _gaq.push(['_trackEvent', 'Link', 'Join', ddmenu_name.name]);">
</form>
事件跟踪程序仅将标签返回为ddmenu_menu.name
有人可以帮忙吗?
解决方法:
ddmenu_name.value可作为所选值的快捷方式,因为select标记没有其他值.但是,由于选择标记本身具有名称属性,因此ddmenu_name.name是预期的“ ddmenu_name”.因此,为了获取所选选项的名称属性,必须获取当前所选选项的索引并获取其名称属性:
<form class="form" action="">
<select name="ddmenu_name" id="ddmenu_name" style="width: 80% !important;">
<option value="" selected>Select option</option>
<optgroup label="Other">
<option value="link1" name="name1">Option 1</option>
<option value="link2" name="name2">Option 2</option>
</optgroup>
</select>
<input type="button" name="Submit" value="Go!" onClick="window.open(ddmenu_name.value,'newtab'); _gaq.push(['_trackEvent', 'Link', 'Join', ddmenu_name.options[ddmenu_name.selectedIndex].getAttribute('name')]);">
</form>
标签:forms,google-analytics,event-tracking,javascript 来源: https://codeday.me/bug/20191123/2066741.html