权限没有,则隐藏 function forum_list_access_filter($forumlist, $gid, $allow = 'allowread') { global $grouplist; if (empty($forumlist)) return array(); if (1 == $gid) return $forumlist; $forumlist_filter = $forumlist; $group = $grouplist[$gid]; foreach ($forumlist_filter as $fid => $forum) { if (empty($forum['accesson']) && empty($group[$allow]) || !empty($forum['accesson']) && empty($forum['accesslist'][$gid][$allow])) { unset($forumlist_filter[$fid]); } unset($forumlist_filter[$fid]['accesslist']); } return $forumlist_filter; } function forum_filter_moduid($moduids) { $moduids = trim($moduids); if (empty($moduids)) return ''; $arr = explode(',', $moduids); $r = array(); foreach ($arr as $_uid) { $_uid = intval($_uid); $_user = user_read($_uid); if (empty($_user)) continue; if ($_user['gid'] > 4) continue; $r[] = $_uid; } return implode(',', $r); } function forum_safe_info($forum) { //unset($forum['moduids']); return $forum; } function forum_filter($forumlist) { foreach ($forumlist as &$val) { unset($val['brief'], $val['announcement'], $val['seo_title'], $val['seo_keywords'], $val['create_date_fmt'], $val['icon_url'], $val['modlist']); } return $forumlist; } function forum_format_url($forum) { global $conf; if (0 == $forum['category']) { // 列表URL $url = url('list-' . $forum['fid'], '', FALSE); } elseif (1 == $forum['category']) { // 频道 $url = url('category-' . $forum['fid'], '', FALSE); } elseif (2 == $forum['category']) { // 单页 $url = url('read-' . trim($forum['brief']), '', FALSE); } if ($conf['url_rewrite_on'] > 1 && $forum['well_alias']) { if (0 == $forum['category'] || 1 == $forum['category']) { $url = url($forum['well_alias'], '', FALSE); } elseif (2 == $forum['category']) { // 单页 $url = ($forum['threads'] && $forum['brief']) ? url($forum['well_alias'] . '-' . trim($forum['brief']), '', FALSE) : url($forum['well_alias'], '', FALSE); } } return $url; } function well_forum_alias() { $forumlist = forum_list_cache(); if (empty($forumlist)) return ''; $key = 'forum-alias'; static $cache = array(); if (isset($cache[$key])) return $cache[$key]; $cache[$key] = array(); foreach ($forumlist as $val) { if ($val['well_alias']) $cache[$key][$val['fid']] = $val['well_alias']; } return array_flip($cache[$key]); } function well_forum_alias_cache() { global $conf; $key = 'forum-alias-cache'; static $cache = array(); // 用静态变量只能在当前 request 生命周期缓存,跨进程需要再加一层缓存:redis/memcached/xcache/apc if (isset($cache[$key])) return $cache[$key]; if ('mysql' == $conf['cache']['type']) { $arr = well_forum_alias(); } else { $arr = cache_get($key); if (NULL === $arr) { $arr = well_forum_alias(); !empty($arr) AND cache_set($key, $arr); } } $cache[$key] = empty($arr) ? '' : $arr; return $cache[$key]; } ?>javascript - New Google Analytics event tracking wont work on mailto - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - New Google Analytics event tracking wont work on mailto - Stack Overflow

programmeradmin11浏览0评论

I'm using the latest Google Analytics code:

(function(i,s,o,g,r,a,m){  
    i['GoogleAnalyticsObject']=r;
    i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();
         a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;
         a.src=g;m.parentNode.insertBefore(a,m) })
      (window,document,'script','//www.google-analytics/analytics.js','ga');

      ga('create', 'XXXXXXXXX', 'XXXXXXXX');   
      ga('send', 'pageview');

I've got event tracking to work on a download link using the following:

<a href="#" onclick="ga('send', 'event', 'Download', 'PDF', 'FILE NAME');">

However, it's not working on a mailto link - when I look in the console it says the request has been cancelled. This is what I'm using:

<a href="mailto:[email protected]" onclick="ga('send', 'event', 'Contact', 'Email', 'Name here');">

When I remove the "mailto" it will then track.

Am I setting it up wrong?

EDIT: It appears if I put a target="_blank" it will work - however it then opens up another window which isn't ideal.

Second Edit: It appears it's something to do with Chrome - I tested it in Firefox and IE and it worked when I did that - anyone else experienced this?

I'm using the latest Google Analytics code:

(function(i,s,o,g,r,a,m){  
    i['GoogleAnalyticsObject']=r;
    i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();
         a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;
         a.src=g;m.parentNode.insertBefore(a,m) })
      (window,document,'script','//www.google-analytics./analytics.js','ga');

      ga('create', 'XXXXXXXXX', 'XXXXXXXX');   
      ga('send', 'pageview');

I've got event tracking to work on a download link using the following:

<a href="#" onclick="ga('send', 'event', 'Download', 'PDF', 'FILE NAME');">

However, it's not working on a mailto link - when I look in the console it says the request has been cancelled. This is what I'm using:

<a href="mailto:[email protected]" onclick="ga('send', 'event', 'Contact', 'Email', 'Name here');">

When I remove the "mailto" it will then track.

Am I setting it up wrong?

EDIT: It appears if I put a target="_blank" it will work - however it then opens up another window which isn't ideal.

Second Edit: It appears it's something to do with Chrome - I tested it in Firefox and IE and it worked when I did that - anyone else experienced this?

Share Improve this question edited Jan 8, 2020 at 7:42 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Feb 17, 2014 at 16:33 user1788364user1788364 1,1513 gold badges19 silver badges33 bronze badges 2
  • 1 have you tried using onmousedown instead of onclick? – Eduardo Commented Feb 17, 2014 at 17:26
  • 1 Hi Eduardo - I tried onmousedown and it worked - thank you! This seems like the best solution to me as you don't need the extra markup! – user1788364 Commented Feb 18, 2014 at 9:26
Add a ment  | 

2 Answers 2

Reset to default 8

I found a relevant thread here: Google Analytics Event Tracking not firing for multiple accounts on Chrome ONLY

So in the end I got it working with chrome - this is how it looks now for those interested:

<a onclick="setTimeout(function(){ga('send', 'event', 'Email', 'Person Name');}, 1500);" href="mailto:[email protected]" >

A timeout function had to be added.

As Eduardo pointed out above another option that worked was having a mousedown function:

<a onmousedown="ga('send', 'event', 'Email', 'Person Name');" href="mailto:[email protected]" >

Universal Analytics has built-in functionality for delaying sends called hitCallback.

ga('send', 'event', 'Contact', 'Email', 'Name here', {
  'hitCallback': function() {
    document.location.href = this.href
  }
});

Haven't tested it, but should be pretty close to working. Google-around for other ideas.

发布评论

评论列表(0)

  1. 暂无评论