Google アナリティクスでウェブサイトの e コマース アクティビティに関するレポートを作成するには、ウェブサイトのビュー(プロファイル)設定ページで e コマース トラッキングを有効にする必要があります。その後、ショッピング カート ページに、または e コマースのソフトウェアを使用して、ga.js e コマース トラッキング メソッドを実装する必要があります。e コマース メソッドの集合は、連動して各ユーザーのトランザクション情報を Google アナリティクス データベースに送信します。これにより、特定の参照ソースをコンバージョンや購入にリンクすることができます。通常、一般的なテンプレート型の e コマース エンジンであれば、注文確認ページにこれらの情報を非表示で追加することは可能です。
一般的なプロセス
Google アナリティクスを使用して e コマース トラッキングを行うための基本的なプロセスは、サイトの e コマース トランザクションのトラッキングに必要な 3 つの方法をまとめることで説明できます。ショッピング カート ページまたは e コマース ソフトウェアで呼び出す順序に従って、これらのメソッドについて説明します。
トランザクション オブジェクトを作成します。
_addTrans() メソッドを使用して、トランザクション オブジェクトを初期化します。トランザクション オブジェクトには、1 つのトランザクションに関連するすべての情報(トランザクション ID、送料、請求先住所など)が保存されます。トランザクション オブジェクトの情報は、トランザクションのトランザクション ID とすべてのアイテム(同じ ID である必要があります)によって、そのアイテムに関連付けられます。
次の例は、3 つの方法すべてを使用して、領収書ページでの e コマース トラッキングの設定例を示しています。_trackPageview() は、「Acme 衣料品からのレシート購入」というページと取引に関連付けます。
非同期構文(推奨)
<html>
<head>
<title>Receipt for your clothing purchase from Acme Clothing</title>
<script type="text/javascript">
var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-XXXXX-X']); _gaq.push(['_trackPageview']); _gaq.push(['_addTrans', '1234', // transaction ID - required 'Acme Clothing', // affiliation or store name '11.99', // total - required '1.29', // tax '5', // shipping 'San Jose', // city 'California', // state or province 'USA' // 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', '1234', // transaction ID - required 'DD44', // SKU/code - required 'T-Shirt', // product name 'Green Medium', // category or variation '11.99', // unit price - required '1' // 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>
</head>
<body>
Thank you for your order. You will receive an email containing all your order details.
</body>
</html>
従来の構文
<html>
<head>
<title>Receipt for your clothing purchase from Acme Clothing</title>
</head>
<body>
Thank you for your order. You will receive an email containing all your order details.
<script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol ) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script> <script type="text/javascript"> try{ var pageTracker = _gat._getTracker("UA-xxxxx-x");
pageTracker._trackPageview(); pageTracker._addTrans( "1234", // transaction ID - required "Womens Apparel", // affiliation or store name "11.99", // total - required "1.29", // tax "15.00", // shipping "San Jose", // city "California", // state or province "USA" // 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 pageTracker._addItem( "1234", // transaction ID - necessary to associate item with transaction "DD44", // SKU/code - required "T-Shirt", // product name "Olive Medium", // category or variation "11.99", // unit price - required "1" // quantity - required );
pageTracker._trackTrans(); //submits transaction to the Analytics servers } catch(err) {} </script>
</body>
</html>