【发布时间】:2015-02-26 01:49:22
【问题描述】:
我的 Wordpress page.php 模板中有以下内容:
<a role="button" onclick="<?php echo $link['analytics']; ?>" href="<?php echo $link['link']; ?>" target="<?php echo $link['target']; ?>" class="btn btn-large btn-<?php echo $link['color']; ?>">
<i class="icon-white icon-<?php echo $link['icon']; ?>"></i>
<?php echo $link['link_text']; ?>
</a>
生成的源代码如下所示:
<a role="button" onclick="ga('send', 'event', 'button', 'click', ‘itunes')" href="http://itunes.apple.com/us/app/rescue-field-guide/id426955029?mt=8&ls=1" target="_blank" class="btn btn-large btn-primary">
<i class="icon-white icon-download"></i>
Download from the App Store </a>
<a role="button" onclick="ga('send', 'event', 'button', 'click', 'google-play’)" href="https://market.android.com/details?id=com.cmc_rescue.rescue_field_guide&feature=search_result" target="_blank" class="btn btn-large btn-success">
<i class="icon-white icon-download"></i>
Download from Google Play </a>
由于我想要的样式,链接看起来像按钮,并且它们成功重定向到各自的页面,但它们不在我的 GA 帐户中注册为点击。
我怎样才能让这个功能的两个部分都工作;重定向和点击?
根据我对这些其他问题的评论:
Html anchor tag onclick() and href execute simultaneously
HTML anchor link - href and onclick both?
似乎有多种方法可以解决这个问题。为我的场景完成此任务的最简单方法是什么?我可以在不使用单独的 javascript 函数的情况下执行此操作吗?或者我的 google 分析函数有问题吗?
谢谢!
【问题讨论】:
-
不确定是否是复制粘贴错误,但使用的单引号必须都是直引号。看起来你对“iTunes”和“google-play”有不同的看法。
-
我不知道为什么会这样,但在我的代码中单引号没问题,谢谢!
标签: wordpress redirect google-analytics onclick anchor