如何使用Google Analytics(分析)动态跟踪链接点击?

时间:2019-09-25 06:40:30

标签: javascript jquery google-analytics

我的html代码如下:

<ul id="sticky-tab" class="hide-on-med-and-down">
    @foreach (Sitecore.Data.Items.Item item in _stickyMenu.Children)
    {
        <li class="content accent-4  z-depth-2 @item.Fields[Templates.Navigable.Fields.CustomClass]" data-color="@item.Fields[Templates.Navigable.Fields.CustomClass]">
            <a class="@classTriger" href="@(popupID==string.Empty?item.LinkFieldUrl(Templates.Link.Fields.Link).ToString():popupID)">
                <div class="text">@item.Fields[Templates.Navigable.Fields.NavigationTitle]</div>
            </a>
        </li>
    }
</ul>

如果生成,则结果如下:

<ul id="sticky-tab" class="hide-on-med-and-down">
    <li class="content accent-4  z-depth-2 red" data-color="red">
        <a class="" href="/Specialties/menu1">
            <div class="icon"><img src="" /></div>
            <div class="text">menu 1</div>
        </a>
    </li>
    <li class="content accent-4  z-depth-2 " data-color="">
        <a class="" href="/Contents/menu2">
            <div class="icon"><img src="" /></div>
            <div class="text">menu 2</div>
        </a>
    </li>
    <li class="content accent-4  z-depth-2 " data-color="">
        <a class="" href="/Contents/menu3">
            <div class="icon"><img src=""/> </div>
            <div class="text">menu 3</div>
        </a>
    </li>
</ul>

我想使用Google Analytics(分析)跟踪链接点击。我这样尝试:

  <a class="@classTriger" href="@(popupID==string.Empty?item.LinkFieldUrl(Templates.Link.Fields.Link).ToString():popupID)" onclick="ga('send', 'event', 'a', 'click');">
        <div class="text">@item.Fields[Templates.Navigable.Fields.NavigationTitle]</div>
    </a>

但是,它不起作用。我该如何解决这个问题?

0 个答案:

没有答案