Amazonアソシエイトのクリックを測定(Google Analytics のイベントトラッキング)
WebサイトにAmazonアソシエイトを埋め込んでいて売り上げを閲覧したい場合、iPhoneなら A2R あたりを使えば簡単に見ることができます。
アフィリエイトアカウント全体でのクリック数でよければ A2R でもわかるのですが、できればページごと、リンクの種類ごとに数値を測定したいところ。
ちょっと調べたところ Google Anayltics 導入済みであれば簡単に設定できたので、備忘録がてらコードを残しておきます。
導入手順
WordPressの場合、functions.php に下のコードを埋め込むだけ。
/** * Amazonアソシエイトトラッキング */ add_filter('wp_footer', function () { ?> <script> (function() { var a = document.querySelectorAll('a'); for (i = 0; i < a.length; i++) { a[i].onclick = function(e) { if (!ga) { // console.log("Google Analytics 未設定") return true; } var href = this.href; if (href.indexOf("www.amazon.co.jp/") != -1 && href.indexOf("-22") != -1) { ga('send', 'event', 'affiliate', 'amazon_images', document.title); // console.log("ga send"); } else if (href.indexOf("amzn.to/") != -1) { ga('send', 'event', 'affiliate', 'amazon_link', document.title); // console.log("ga send"); } return true; } } }()); </script> <?php });
WordPress以外の場合でも、Google Analytics 導入済みであればこのコードを埋め込むだけでイベントとしてトラッキングできるようになります。
(function () { var a = document.querySelectorAll('a'); for (i = 0; i < a.length; i++) { a[i].onclick = function (e) { if (!ga) { // console.log("Google Analytics 未設定") return true; } var href = this.href; if (href.indexOf("www.amazon.co.jp/") != -1 && href.indexOf("-22") != -1) { ga('send', 'event', 'affiliate', 'amazon_images', document.title); // console.log("ga send"); } else if (href.indexOf("amzn.to/") != -1) { ga('send', 'event', 'affiliate', 'amazon_link', document.title); // console.log("ga send"); } return true; } } }());
どんな風に見えるか
例えば「リアルタイム」だとこんな感じ。
データがたまってくると「行動」→「イベント」での分析もできるようになります。