UAの拡張eコマース計測をそのままにGA4のeコマース計測をする方法

eコマース

 and,a株式会社 デジタルマーケティングエンジニア 佐藤洋太

UAで拡張eコマース計測を既にサイトに導入していて、GA4でも同じように計測したいと思ったことはありませんか?

今回はサイト側(バックエンド)の調整は一切せず極力少ない工数でUAのデータをそのままにGA4でもeコマース計測を実現してみます。

この記事の対象

  • UAで既に拡張eコマース計測をお使いの方
  • eコマース計測でサイトの調整に工数をかけたくない方

事前知識

公式のアナウンスではUAからGA4にeコマース計測をする際の手順がアナウンスされています

https://support.google.com/analytics/answer/10119380?hl=ja

しかしながら、変更点が多く直感的にわかるとは言い難いです。
これらをイチから読み解いて実装するにはなかなかに骨が折れます。。


そこで今回はサクッとGTMからカスタムHTMLを配信してGA4向けに変換してしまいましょう。

UAのeコマースイベント名の対応表

GA4ではUAで使われていたデータレイヤー上でadd/remove/detailなどのイベント名はほぼ使えません。またcheckoutステップ(actionField)などもなくなったため、これらをGA4仕様に変更します。

内容UA のイベント名リファレンスGA4 のイベント名リファレンス
購入完了/払い戻しpurchaserefundpurchaserefund
チェックアウト(支払情報設定)checkout_option*add_payment_info
チェックアウト(送付先情報設定)checkout_option*add_shipping_info
チェックアウトcheckout*begin_checkout
カートの追加/削除addToCart該当なしremoveFromCart該当なし*add_to_cart
*add_to_wishlist
*remove_from_cart
*view_cart
商品閲覧pageview*view_item(ビューのデフォルト)
商品一覧閲覧/商品クリックpageviewproductClick*view_item_list(マーケティング ビュー)
*select_item
プロモーション閲覧/プロモーションクリックpageviewpromotionClick*view_promotion
*select_promotion

引用元:https://support.google.com/analytics/answer/10119380?hl=ja

UAのディメンション名の対応表

GA4ではUAで使われていたディメンション名が廃止されたり、新たに追加されたりと少々変更が入っていますので、これらを調整します

大きなところでいくと、商品情報のproductsのディメンションがitemsというパラメーターに変更され、詳細は以下のようになります

詳細GA4 のパラメータ対応する UA のディメンション
**アイテム / 商品の詳細リソース数
item_id
item_name
item_brand
item_category
item_category2
item_category3
item_category4
item_category5
item_variant
affiliation
discount
coupon
price
quantity
products
id
name
brand
category
該当なし – 存在しない
該当なし – 存在しない
該当なし – 存在しない
該当なし – 存在しない
variant
該当なし – 存在しない
該当なし – 存在しない
coupon
price
quantity

引用元:https://support.google.com/analytics/answer/10119380?hl=ja

実践

では、以上の情報を踏まえて実ページでソースを紹介しながら変換してみましょう

準備

商品詳細ページを実例に、GTMがロードされた際に既にデータレイヤーにeコマース情報が格納されている状態です

HTML

<!DOCTYPE html>
<html lang="ja" dir="ltr">
  <head>
    <script type="text/javascript">
      window.dataLayer = [];
      dataLayer.push( {
        "ecommerce":{
          "detail":{
            "products":[
              {
                "id":"99999",
                "name":"商品名商品名商品名商品名商品名",
                "brand":"ブランド名ブランド名",
                "category":"特大/大カテゴリ/中カテゴリ/小カテゴリ"                "price":"999"
              }
            ]
          }
        }
      });
    </script>

    <meta charset="utf-8">
    <title>商品詳細ページテスト</title>
    <!-- Google Tag Manager -->
    <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
    new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
    j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
    'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
    })(window,document,'script','dataLayer','GTM-xxxxx');</script>
    <!-- End Google Tag Manager -->
  </head>
  <body>
    <h1>商品詳細ページテスト</h1>
  </body>
</html>

このページをロードするとデータレイヤーの以下のような状態になります

では次からGTMを設定していきます。

GTMの設定

1:eコマースデータを読み込むためのデータレイヤー変数を用意

変数名:GA_DLVAR_ecommerce

2:イベント名を読み込むためのデータレイヤー変数を用意

変数名:GA_DLVAR_ga4_eCom_eventName

3:GA4用のeコマースデータを読み込むためのデータレイヤー変数を用意

変数名:GA4_DLVAR_ecommerce

4:変換用のJavaScriptを実行するカスタムHTMLを用意

ソース

<script>
(function (o) {
var key = Object.keys(o)[0];
var itemArr = [];
var eventType = { // イベント名の変換リスト。調整する場合はここを変更
  "detail": "view_item",
  "add": "add_to_cart",
  "remove": "remove_from_cart",
  "checkout": {
    1: "begin_checkout",
    2: "add_payment_info",
    3: "add_shipping_info"
  },
  "purchase":"purchase"
};

var option = {
  "id": "transaction_id",
  "revenue": "value"
};

var eCom = { "ecommerce": {} };
var products = o[key]["products"] || [];
var actionField = o[key]["actionField"] || [];

// productsのディメンションをGA4のパラメーターに変換
products.forEach(function (product) {
  var item = {}
  Object.keys(product).forEach(function (name) {
    var n = name;

    if (!name.match(/price|dimension|index|quantity/)) {

      if (name.match("category")) {
        product[name].split("/").forEach(function (cat, i) {
          item["item_" + name + (i || "")] = cat;
        });
      } else {
        n = "item_" + name
        item[n] = product[name]
      }
    } else if (name.match(/dimension/)) {
      dim = product[name];
      delete product[name];
    } else {

      item[n] = product[name]
    }

  });

  itemArr.push(item);
})
eCom["ecommerce"]["items"] = itemArr;

// actionFieldの変換
if (key === "checkout" || key === "purchase") {
  Object.keys(actionField).forEach(function (name) {
    var n = name;

    if (option[n]) {
      n = option[n]
    }

    eCom["ecommerce"][n] = actionField[name];
  });
  eCom["ecommerce"]["currency"] = "JPY";
}

dataLayer.push({
  event: "convertGA4eCom",
  ga4_eventName: key === "checkout" ? eventType[key][actionField["step"]] : eventType[key],
  ga4_ecommerce: eCom,
});

}({{GA_DLVAR_ecommerce}}));
</script>

トリガーはAll Pagesを設定します。

この変換が成功するとdataLayerにconvertGA4eComというイベントを通知する仕組みです

※今回はview_item、add_to_cart、remove_from_cart、begin_checkout、add_payment_info、add_shipping_info、purchaseのイベントに対応しています。他のイベントでも使用する際はevetTypeを適宜変更ください。

5:GA4に送信するためのトリガー設定

トリガー名:GA4_eCom_EVENT

6:GA4のイベント設定

  • イベント名に{{GA_DLVAR_ga4_eCom_eventName}}を設定
  • eコマースデータを送信にチェックし、{{GA4_DLVAR_ecommerce}}を設定
  • トリガーにGA4_eCom_EVENTを設定

UAから変換したeコマースデータを読み込むことで、工数のかかる面倒な設定を全て省けます

以上で設定は終わりです

結果

GTMの設定が全て終わったら公開をします。

すると、正常な状態だとdataLayerにカスタムHTMLから生成されたGA4用のeコマースデータが格納されます

ネットワークタブでペイロードの中を見るとpr1というパラメータに商品情報が格納されているのがわかります。

以上でUAの拡張eコマースを変換してGA4で計測する手順は終わりです。

いかがでしたでしょうか?

今回は一部のイベントだけの紹介でしたが、eコマースイベントとカスタムディメンションを組み合わせるなどかなりの応用が効くと思います。

是非お試しください。

関連記事

特集記事

コメント

  1. I truly appreciate this blog post.Much thanks again. Really Great.

  2. I cannot thank you enough for the post.Really thank you! Really Great.

  3. Major thankies for the blog. Great.

  4. Very neat article post. Much obliged.

  5. Excellent way of explaining, and nice post to take information about my presentation topic, which i am going to convey in academy.

  6. anafilaxia de caramelo vs sensibilidad a los dulces: divergencia y enfermedad

  7. Thank you ever so for you article post.Much thanks again. Awesome.

  8. I really liked your post.Much thanks again. Really Cool.

  9. What’s Taking place i am new to this, I stumbled upon this I’ve discovered It absolutely useful and it has helped me out loads. I’m hoping to give a contribution & aid different customers like its aided me. Good job.

  10. Really appreciate you sharing this article.Much thanks again. Really Great.

  11. Very good blog article.Much thanks again. Cool.

  12. I do not even understand how I finished up right here, but I thought this publish was once great. I don’t recognise who you’re however definitely you’re going to a well-known blogger if you aren’t already 😉 Cheers!

  13. Hi mates, its great post regarding educationand fully explained, keep it up all the time.

  14. Really appreciate you sharing this post. Cool.

  15. Awesome article.Thanks Again. Keep writing.

  16. Thank you ever so for you article post.Really looking forward to read more. Cool.

  17. medications that cause erectile dysfunction – erectile dysfunction doctor free ed pills

  18. Hi friends, how is all, and what you want to say regarding this paragraph, in my view its actually remarkable designed forme.

  19. Thank you for your post.Really thank you! Keep writing.

  20. Major thanks for the blog post. Cool.

  21. Thanks again for the article.Much thanks again. Cool.

  22. up to date with coming near near post. Thank you one million and please continue the enjoyable work.

  23. south tampa apartments duplex for rent ventura apartments for rent

  24. Remarkable! Its in fact awesome piece of writing, I have got much clear idea about from this post.

  25. Hello, its good paragraph regarding media print, we all understandmedia is a enormous source of data.

  26. An intriguing discussion is definitely worth comment. I do think that you should publish more about this topic, it might not be a taboo matter but typically people do not discuss such topics. To the next! Many thanks!

  27. Thanks for the blog article.Thanks Again. Fantastic.

  28. Greetings! Very helpful advice on this article! It is the little changes that make the biggest changes. Thanks a lot for sharing!มด21/9

  29. get very far as we ended up of even any very confidential data

  30. I cannot thank you enough for the blog article.Really looking forward to read more. Fantastic.

  31. I will immediately grab your rss feed as I can not find your email subscription link or newsletter service. Do you’ve any? Please let me know in order that I could subscribe. Thanks.

  32. You might add a related video or a related picture or two to grab readers excited about

  33. hello!,I like your writing so so much! share we keep up a correspondence more about your post on AOL? I need an expert on this area to unravel my problem. Maybe that is you! Taking a look ahead to see you.

  34. I do accept as true with all of the ideas you have introduced to your post. They are really convincing and can certainly work. Still, the posts are very quick for beginners. Could you please extend them a bit from next time? Thanks for the post.

  35. ivermectin for heartworms in dogs ivermectin over the counter

  36. Hi, after reading this remarkable post i am too glad to share my know-how here with friends.Here is my blog post :: Bionic Ultrasonic Pest Repeller

  37. Good day! I know this is kinda off topic but I was wondering if you knew where I could find a captcha plugin for my comment form? I’m using the same blog platform as yours and I’m having problems finding one? Thanks a lot!

  38. provigil medication modafinil weight loss – modalert online

  39. I needed to thank you for this wonderful read!! I certainly enjoyed every little bit of it. I’ve got you book-marked to check out new things you postÖ

  40. Hiya, I am really glad I have found this information. Today bloggers publish only about gossips and net and this is really annoying. A good site with exciting content, this is what I need. Thanks for keeping this web site, I will be visiting it. Do you do newsletters? Cant find it.

  41. Thanks on your marvelous posting! I seriously enjoyed reading it,you’re a great author.I will remember tobookmark your blog and will eventually come back in the future.I want to encourage you to ultimately continue your greatposts, have a nice day!

  42. Thanks on your marvelous posting! I seriously enjoyed reading it, you could be a great author. I will make sure to bookmark your blog and may come back at some point. I want to encourage that you continue your great job, have a nice evening!

  43. Thanks for the good writeup. It actually used to be a leisure account it. Look complex to far added agreeable from you! By the way, how can we be in contact?

  44. ivermectin shampoo for head lice ivermectin injectable for horses

  45. Hello my loved one! I wish to say that this article is amazing, nice written and come with almost all vital infos. I’d like to peer extra posts like this .

  46. I appreciate you sharing this article post.Much thanks again. Great.

  47. I don’t even know the way I stopped up right here, but I believed this publish used to be great.I do not recognise who you might be however certainlyyou’re going to a well-known blogger in case youare not already. Cheers!

  48. Great, thanks for sharing this blog post.Much thanks again. Cool.

  49. I’ve been absent for a while, but now I remember why I used to love this web site. Thank you, I will try and check back more frequently. How frequently you update your web site?

  50. I think this is a real great blog article.Really thank you! Want more.

  51. I do agree with all of the ideas you’ve presented in your post. They are really convincing and will certainly work. Still, the posts are too short for novices. Could you please extend them a bit from next time? Thanks for the post.

  52. Thanks for your posting. I also think that laptop computers are becoming more and more popular nowadays, and now are usually the only sort of computer employed in a household. The reason is that at the same time potentially they are becoming more and more reasonably priced, their processing power keeps growing to the point where they may be as highly effective as personal computers through just a few in years past.

  53. Im grateful for the blog article.Thanks Again. Cool.

  54. Normally I do not learn post on blogs, however I wish to say that this write-up very pressured me to take a look at and do so! Your writing style has been amazed me. Thanks, quite nice post.

  55. Your mode of telling all in this paragraph is genuinely fastidious, allbe able to simply know it, Thanks a lot.

  56. i’m fond of using vending machines because you can instantly get a drink or a snack..

  57. isn’t ,using a beauty filter also called appling a digital fainess cream.OR are they just a medium to express mood .will wait for your view

  58. I think this is a real great blog article. Really Great.

  59. hi!,I like your writing very a lot! share we be in contact more about your article on AOL? I need a specialist in this area to resolve my problem. May be that is you! Taking a look forward to peer you.

  60. An intriguing discussion is worth comment. I do think that you need to publish more about this topic, it might not be a taboo matter but usually folks don’t speak about these subjects. To the next! Many thanks!!

  61. Oh my goodness! an incredible article dude. Thanks Nevertheless I’m experiencing situation with ur rss . Don’t know why Unable to subscribe to it. Is there anybody getting identical rss problem? Anyone who knows kindly respond. Thnkx

  62. Hi, I do believe this is an excellent blog. I stumbledupon it 😉 I will return once again since i have bookmarked it. Money and freedom is the greatest way to change, may you be rich and continue to guide others.

  63. What’s up friends, how is everything, and what you wish for to say concerning this piece of writing, in my view its actually amazing in favor of me.

  64. Looking forward to reading more. Great blog article.Really looking forward to read more. Much obliged.

  65. Key deviations from those occasions may perhaps suggest you are dealingwith a scam bookmaker.

  66. plate suculente

  67. Good information. Lucky me I recently found your blog by chance (stumbleupon).I have bookmarked it for later!

  68. obviously like your web site however you need to take a look at the spelling on quite a few of your posts. Several of them are rife with spelling issues and I find it very bothersome to inform the truth then again I will certainly come again again.

  69. What’s up mates, good article and good urging commented here, I am actually enjoying by these.

  70. Information effectively utilized!!writing outlines for essays writing research essay best cv writing services

  71. Spot on with this write-up, I really suppose this web site wants far more consideration. I?ll probably be again to learn much more, thanks for that info.

  72. Thank you for sharing superb informations. Your web-site is so cool. I am impressed by the details that you?ve on this website. It reveals how nicely you understand this subject. Bookmarked this website page, will come back for more articles. You, my friend, ROCK! I found simply the info I already searched all over the place and just could not come across. What a perfect website.

  73. I really like and appreciate your blog article.Really looking forward to read more. Keep writing.

  74. Thank you ever so for you post.Thanks Again. Really Cool.

  75. Fantastic blog article.Really thank you! Will read on…

  76. Say, you got a nice blog.Thanks Again. Will read on…

  77. deer ridge apartments apartments for rent in chesapeake va diamond bar apartments

  78. Hey there, You have performed an incredible job. I will certainly digg it and individually suggest to my friends. I am sure they will be benefited from this web site.

  79. Good answers in return of this difficulty with firm arguments and explaining the whole thing on the topic of that.

  80. You can certainly see your enthusiasm in the work you write The sector hopes for even more passionate writers like you who aren’t afraid to say how they believe Always go after your heart

  81. This betters your chances of finding open spots on the field and increases the amount of space for you to execute a plan.

  82. Thank you for your article post. Cool.Loading…

  83. Wonderful blog! I found it while surfing around on Yahoo News. Do you have any suggestions on how to get listed in Yahoo News? I’ve been trying for a while but I never seem to get there! Cheers

  84. I savour, cause I found just what I used to be lookingfor. You’ve ended my 4 day long hunt! God Bless you man. Have agreat day. Bye

  85. In this grand design of things you actually secure a B+ just for hard work. Where exactly you actually confused us was on the facts. You know, it is said, details make or break the argument.. And it couldn’t be more accurate at this point. Having said that, permit me reveal to you what did work. Your article (parts of it) is definitely highly engaging which is most likely the reason why I am taking the effort to opine. I do not make it a regular habit of doing that. 2nd, even though I can easily notice the jumps in reason you come up with, I am definitely not confident of how you seem to connect your details that help to make the actual final result. For now I shall subscribe to your point however wish in the near future you link the dots better.

  86. I figured out more something totally new on this weight loss issue. 1 issue is that good nutrition is vital while dieting. An enormous reduction in bad foods, sugary food items, fried foods, sugary foods, beef, and white flour products may be necessary. Possessing wastes bloodsuckers, and harmful toxins may prevent goals for fat-loss. While a number of drugs momentarily solve the problem, the unpleasant side effects are not worth it, and they also never give more than a short lived solution. It can be a known undeniable fact that 95 of celebrity diets fail. Many thanks sharing your opinions on this blog site.

  87. Wonderful work! This is the type of info that should be shared around the web. Shame on the search engines for not positioning this post higher! Come on over and visit my website . Thanks =)

  88. Looking forward to reading more. Great article.Much thanks again. Keep writing.

  89. i hope and pray na lahat po ay mabigyan. Godbless usall

  90. I truly appreciate this blog post.Really looking forward to read more. Will read on…

  91. Thanks again for the blog.Thanks Again. Great.

  92. how does lexapro make you feel how to pronounce escitalopram

  93. It’s an remarkable article in favor of all the internet people; they will getbenefit from it I am sure.

  94. Almanya’nın en iyi medyumu haluk hoca sayesinde sizlerde güven içerisinde çalışmalar yaptırabilirsiniz, 40 yıllık uzmanlık ve tecrübesi ile sizlere en iyi medyumluk hizmeti sunuyoruz.

  95. erectile herbserectile creams for menerectile gel

  96. Awesome article post.Thanks Again. Will read on…

  97. Thanks for the auspicious writeup. It in truth was once a amusement account it. Look complicated to far added agreeable from you! By the way, how could we be in contact?

  98. It’s really a nice and helpful piece of info. I’m glad that you shared this helpful information with us. Please keep us up to date like this. Thanks for sharing.

  99. Hey. Very nice site!! Man .. Beautiful .. Amazing .. I will bookmark your site and take the feeds also…I am glad to locate numerous useful information here within the article. Thanks for sharing.

  100. Heya i’m for the primary time here. I found this board and I in finding It truly useful & it helped me out much.
    I am hoping to provide something again and aid others like you aided
    me.

  101. These providers are only required to comply with US sweepstakes laws in each and every state they’re accessible.

    my web page: https://runoved.ru/baccarat-web-page-the-ultimate-guide-to-winning-big/

  102. Cheers, Very good information!

    my web site … https://Biowiki.Clinomics.com/index.php/Las_Vegas_Baccarat_Minimum_Bet_By_Casino_In_2023

  103. When playing an on the internet https://spiesmagazine.com/%EB%B2%B338%EC%9D%98-%EC%84%B8%EA%B3%84%EB%A1%9C%EC%9D%98-%EC%B4%88%EB%8C%80-%EB%AA%A8%EB%93%A0-%EA%B2%83%EC%9D%84-%EC%95%8C%EB%A0%A4%EB%93%9C%EB%A6%BD%EB%8B%88%EB%8B%A4/, the random number generator (RNG) determines the outcome of the game.

  104. The player will drop a lot, regardless of what game the player is participating in.

    Feel free to visit my web blog https://sparize.com/%EA%B3%A8%EB%93%A0%EC%95%84%EB%A8%B8%EC%B9%B4%EC%A7%80%EB%85%B8%EC%9D%98-%EC%88%A8%EC%9D%80-%EB%B9%84%EB%B0%80-%ED%95%9C-%EB%88%88%EC%97%90-%EB%B3%B4%EA%B8%B0/

ランキング(週間)

  1. 1

    GA4 「ページ ロケーション」と「ページ パス と スクリーン クラス」何が違う?ドメインの有無以外にもパラメータの扱いに違いあり

  2. 2

    GA4の探索で「ページ別訪問数」を見ることは可能か?

  3. 3

    GA4 拡張計測機能の新顔「フォームの操作」 form_start, form_submit

  4. 4

    GA4のレポート画面の数値データは、イベント発生時から何時間後に確定するのか?

  5. 5

    【祝・GPT-4 が ChatGPT plus に登場記念!】アクセス解析コンサルタントが、GPT-4にCSVデータを渡して、データ解析結果のコメントを書いてもらう方法

  6. 6

    GA4の指標「総ユーザー数」VS「アクティブ ユーザー数」

  7. 7

    GA4 クロスドメイン設定では、リンク先に「_gl」パラメータが付く。勝手なパラメータを付けるとエラーになるページは要注意

  8. 8

    GA4 イベントタグの「詳細設定」に「e コマースデータを送信」が実装されました。

  9. 9

    GA4では、utm_term, utm_content はどうなったのか?

  10. 10

    GA4で異なるドメイン(サブドメイン)の同一ページパスをドメイン付きで表示する

最近の記事

  1. 生成AIを調整してABテストを実装したら想像以上に早かった

  2. 無料で使えるABテストツールのバージョンアップを行いました

  3. 無料ABテストツール(and,B)のマニュアルを作成しました

カテゴリー

 
TOP