次のコードで私はしようとしています:-
- ページでグーグルアナリティクスを定義する
- ページのドメインに特定のクエリ文字列と文字がある場合は、jqueryクリックイベントを追加します
- クリックイベントは、Googleアナリティクスの追跡イベントを呼び出します
- ドメイン内のクエリ文字列と値をチェックするコードもあります
動作していないもの:-
- グーグルアナリティクストラッキングイベントを呼び出す3番目のアイテムは、私はそれを打っているようですが、私のGAアカウントには何も返されていません。
私が試したこと:-
_gaq_.push
の情報が正しいアカウントに正しくリンクされていることをトリプルチェックしました。- firebugとIE9開発者ツールを使用してjavascriptを追跡し、何が起こっているかを分析しました。これは、私のシナリオが真実であるときにイベント追跡をヒットしていることを私が知る方法です。
- jsfiddleのような隔離された環境で試してみましたが、実際に会社の情報を提供することはできないため、その環境へのリンクは提供されません。jsフィドルでは動作しません。(主にjsfiddleが私のgaアカウントで認証できないためです(ドメインは異なります)。
関連するドメイン内の分離されたファイルで試しましたが、まだうまくいきません。
var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-XXXXX-X']); _gaq.push(['_setDomainName', 'mydomain.co.uk']); _gaq.push(['_setAllowLinker', true]); _gaq.push(['_setSiteSpeedSampleRate', 100]); // this is a new line, allowing us to see how fast all pages load _gaq.push(['_trackPageview']); // we’ve moved this line down, as ‘setdomain’ (etc) should appear before it (function () { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); $(document).ready(function () { var querystring = (function (a) { if (a == "") return {}; var b = {}; for (var i = 0; i < a.length; ++i) { var p = a[i].split('='); if (p.length != 2) continue; b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " ")); } return b; })(window.location.search.substr(1).split('&')); if (querystring["utm_expid"] != null) { $('a').click(function () { if ($(this).attr("href") != 'undefined' && $(this).attr("href") != null) { if ($(this).attr("href").toLowerCase().indexOf("keyword") >= 0 && $(this).attr("href").toLowerCase().indexOf("keyword2") >= 0) { _gaq.push(['_trackEvent', 'eventCategories', 'eventAction', 'eventLabel']); } else if (($(this).attr("href").toLowerCase().indexOf("keyword") >= 0 && $(this).attr("href").toLowerCase().indexOf("keyword2") >= 0 && $(this).attr("href").toLowerCase().indexOf("keyword3") >= 0) || ($(this).attr("href").toLowerCase().indexOf("keyword4") >= 0)) { _gaq.push(['_trackEvent', 'eventCategories', 'eventAction', 'eventLabel']); } } }); } });