星の数ほどあるGoogleアナリティクスのカスタム設定。「いつかやってみよう!」と思いながら忘れてはいませんか?
今回はそんな方のために、今すぐ使えるGoogle Analyticsカスタム設定のチートシートをご紹介。困った時にもサッと使えるよう印刷して持っておくのもアリです!
ga('create', 'UA-XXXX-Y', 'yourdomains);
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
ga('send', 'pageview');
_gaq.push(['_trackPageview']);
ga('create', 'UA-XXXX-Y'); ga('create', 'UA-XXXX-Y', { 'name' : 'newTracker'}); ga('send', 'pageview'); ga('newTracker.send', 'pageview');
ga('set', 'anonymizeIP', true);
window['ga-disable-UA-XXXX-Y'] = true;※falseにすると有効になりtrueだと無効になる(制御はphpなどで別途設定)
Introduction to Analytics.js
Tracking Basics (Asynchronous Syntax)
ga('send', 'pageview', { 'page' : '/my-overridden-page?id=1', 'title' : my overridden page' });
<a href="URL" onclick="_gaq.push(['_trackPageview', '/downloads/pdfs/corporateBrief.pdf']);">計測対象オブジェクト</a>
<a href="URL" onclick="ga('send', 'event', 'category', 'action', 'opt_label', opt_value);">計測対象オブジェクト</a>
<a href="URL" onclick="_gaq.push(['_trackEvent', 'category', 'action', 'opt_label', opt_value]);">計測対象オブジェクト</a>
<a href="URL" onclick="ga('send', 'event', 'category', 'action', {nonInteraction' : 1});">計測対象オブジェクト</a>
<a href="URL" onclick="_gaq.push(['_trackEvent', 'category', 'action', 'opt_label', opt_value, opt_noninteraction]);">計測対象オブジェクト</a>
Page Tracking – Web Tracking (analytics.js)
Event Tracking – Web Tracking (analytics.js)
Event Tracking – Web Tracking (ga.js)
<script> ga('ecommerce:addTransaction', { id: '$オーダー/決済ID$', // Transaction ID - this is normally generated by your system. affiliation: '$ショップ名$', // Affiliation or store name revenue: '$オーダー金額総計$', // Grand Total shipping: '$送料$' , // Shipping cost tax: '$税金$' }); // Tax. ga('ecommerce:addItem', { id: '$オーダー/決済ID$', // Transaction ID. sku: '$商品ID$', // SKU/code. name: '$商品名$', // Product name. category: '$商品カテゴリーorブランド$', // Category or variation. price: '$商品単価$', // Unit price. quantity: '$個数$'}); // Quantity. ga('ecommerce:send'); </script>
<script type=”text/javascript”> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-xxxxxxxx-1']); _gaq.push(['_trackPageview']); _gaq.push(['_addTrans', '$オーダーID$', // order ID - required '$ショップ名$', // affiliation or store name '$オーダー金額総計$', // total - required '$税金$', // tax '$送料$', // shipping '$市区町村$', // city '$県$', // state or province '$日本$' // country ]); // add item might be called for every item in the shopping cart // where your ecommerce engine loops through each item in the cart and // prints out _addItem for each _gaq.push(['_addItem', '$オーダーID$', // order ID - required '$商品ID$', // SKU/code - required '$商品名$', // product name '$商品カテゴリーorブランド$', // category or variation '$商品単価$', // unit price - required '$個数$' // quantity - required ]); _gaq.push(['_trackTrans']); //submits transaction to the Analytics servers (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); })(); </script>
ga('send', 'social', 'socialNetwork', 'socialAction', 'socialtarget');
_gaq.push(['_trackSocial', network, socialAction, opt_target, opt_pagePath]);
Ecommerce Tracking – Web Tracking (analytics.js)
Social Interactions – Web Tracking (analytics.js)
Ecommerce Tracking – Web Tracking (ga.js)
Social Interactions – Web Tracking (ga.js)
(執筆/編集 中村健太)