1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MakeShop独自ドメイン利用でAnalyticsのCookieが途切れる問題

Last updated at Posted at 2019-08-22

やりたかったこと

MakeShopのECサイトを独自ドメインで運用しているショップでGoogleAdwordsの効果を確かめたい

問題点

MakeShopでは、かなりの高額プランのものでない限り、購入画面でmakeshopドメインに遷移してしまう。それ自体はいいのだが、その際に本来引き継がれるはずのCookieが切れてしまい、広告効果が測れない。

原因

MakeShop側のJavaScriptの記述順に問題ありの模様

view/asset/system-1-1-6-4...

if (pageData.attr('data-order-google-analytics-enabled') === 'Y') {
 ga('linker:decorate', document.getElementById('makeshop-form-common-order'));
   }
if (data.service_type == 'amazon') {
  $('#makeshop-form-common-order 
  input[name=amazon_login_type]').val('amazon_basket_order');
  }
       
 $('#makeshop-form-common-order').attr('action', data.order_url);
 $('#makeshop-form-common-order').submit();

本来はこの最初のif行が最後に来るべきところ。。。とはいえ、MakeShopに文句言っても仕方ないので、

###解決策
MakeShopの「アクセス解析用のタグ」という追加入力のところにこんな感じで入れとけばOK
「AW-XXXXXXXXX」部分は適宜差し替え。

<script async src="https://www.googletagmanager.com/gtag/js?id=AW-XXXXXXXXX"></script>
<script>
 window.dataLayer = window.dataLayer || [];
 function gtag(){dataLayer.push(arguments);}
 gtag('js', new Date());
 gtag('config', 'AW-XXXXXXXXX');
window.addEventListener('load', function(){
   var addToCartForm = document.getElementById('makeshop-form-common-order');
   if(!addToCartForm || !window.location.pathname.includes('\/cart'))return;
   addToCartForm.onsubmit = function(e){
      ga('linker:decorate', document.getElementById('makeshop-form-common-order'));
   };
});
</script>
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?