dataLayer解説 window.dataLayer = window.dataLayer || [];

解説記事

下記は、第3回セミナーのイベント「purchase」で使用したデータレイヤーです。

<script>
  window.dataLayer = window.dataLayer || [];
  dataLayer.push({
    event: "purchase",
    ecommerce: {
      transaction_id: "100-02", 	        
      affiliation: "GA4 Quick", 		
      value: 10000, 			
      tax: 1000, 			
      shipping: 500, 			
      currency: "JPY", 			
      coupon: "2022_SPRING_SEMINAR", 	
      items: [{
        item_name: "2022_SPRING_SEMINAR_04",	
        item_id: "22ss04", 			
        price: 10000, 			
        item_brand: "and,a", 		
        item_category: "Online_Seminar", 	
        item_variant: "ZOOM", 		
        quantity: 1			
      }]
   }
  });
</script>

上記の2行目、

  window.dataLayer = window.dataLayer || [];

について解説します。

dataLayerはJavaScriptで「配列」と呼ばれるものになります。
「配列」は中にいろいろな要素をリスト形式で保有することができるもので、
そして「配列」はその要素を追加・削除・検索など行うことが可能です。

dataLayerは「継ぎ足し継ぎ足ししていく」のが本来的な使い方です。

 window.dataLayer = window.dataLayer || [];

は、「dataLayerという名前で配列を新規作成する」というものになります。
GTMはページ上にdataLayerという配列が存在したらそちらを利用する形です。
(存在しない場合はGTMが勝手に作成します)

そして、dataLayer.push()というのは上で触れた「配列に要素を追加する」ものとなり、
()の中身をdataLayerに追加する、という文法になっています。

これによって、「作成した配列に対してpurchase用のデータを追加する」形になります。


これが「継ぎ足し継ぎ足し」できる、という意味になります。追加されるデータに関して、「{ }で囲んだ範囲」はご存知かと思いますが、「event」パラメータに関しては「データの第一階層に配置する必要がある」形です。


関連記事

特集記事

コメント

  1. I really liked your article.Really thank you! Fantastic.

  2. I really liked your article post.Really looking forward to read more. Awesome.

  3. Im grateful for the blog article.Really thank you! Want more.

  4. Fantastic article post. Will read on…

  5. Awesome post.Much thanks again. Much obliged.

  6. Fantastic blog.Much thanks again. Fantastic.

  7. This is one awesome article.Really looking forward to read more. Really Cool.

  8. Thanks a lot for the blog post. Fantastic.

  9. Hey, thanks for the article post.Really looking forward to read more. Keep writing.

  10. I really enjoy the blog article. Want more.

  11. A big thank you for your blog.Thanks Again. Want more.

  12. Thanks so much for the blog article.Much thanks again. Awesome.

  13. Very neat article.Much thanks again. Much obliged.

  14. I really enjoy the article post.Thanks Again. Much obliged.

  15. Great, thanks for sharing this article post.Really thank you! Much obliged.

  16. Great, thanks for sharing this article post.Really thank you! Cool.

  17. wow, awesome article.Thanks Again. Much obliged.

  18. Greate article. Keep writing such kind of info on your page.
    Im really impressed by it.
    Hey there, You have done an excellent job.
    I’ll certainly digg it and for my part recommend
    to my friends. I am confident they will be benefited
    from this site.

  19. Wonderful beat ! I would like to apprentice while you amend your website, how
    can i subscribe for a weblog website? The account helped me a applicable deal.
    I have been tiny bit familiar of this your broadcast offered bright transparent idea

  20. Hi there, after reading this amazing piece of writing i am
    too happy to share my knowledge here with colleagues.

  21. Hello, this weekend is nice in support of
    me, for the reason that this time i am reading this impressive informative paragraph here at my home.

    Also visit my page … vpn special code

  22. I’m truly enjoying the design and layout of your website.
    It’s a very easy on the eyes which makes it much more enjoyable for me to
    come here and visit more often. Did you hire out a designer to
    create your theme? Great work!

    My homepage – vpn coupon 2024

  23. After I originally left a comment I appear to have clicked
    on the -Notify me when new comments are added- checkbox and from
    now on each time a comment is added I get 4 emails with the same comment.
    Is there a means you are able to remove me from that service?
    Thanks!

  24. Wow, that’s what I was exploring for, what a stuff!
    existing here at this web site, thanks admin of this web page.

  25. I truly appreciate this blog article.Thanks Again. Really Great.

  26. Very neat blog post.Much thanks again. Will read on…

  27. wow, awesome article.Thanks Again. Will read on…

    • pia socks5 proxy
    • 2024.04.21 12:41am

    I appreciate you sharing this blog article.Thanks Again. Cool.

  28. Hey, thanks for the blog article.Much thanks again. Awesome.

  29. Im grateful for the post.Much thanks again. Much obliged.

  30. Very good article post. Really Cool.

  31. Major thankies for the article post.Really looking forward to read more. Will read on…

  32. Really appreciate you sharing this article.Much thanks again. Awesome.

  33. Thank you for your article post. Great.

  34. I think this is a real great post. Fantastic.

  35. Really informative blog post.Really looking forward to read more. Really Cool.

  36. I loved your article.Much thanks again.

  37. Say, you got a nice blog post.Thanks Again. Fantastic.

  38. Major thankies for the article post.Really looking forward to read more. Will read on…

  39. Looking forward to reading more. Great blog.Much thanks again. Keep writing.

  40. Im obliged for the article.Thanks Again. Really Great.

  41. Hey, thanks for the blog post.Really thank you! Really Great.

  42. Thanks for sharing, this is a fantastic article post.Thanks Again. Want more.

  43. Major thanks for the blog.Really thank you!

  44. Appreciate you sharing, great blog. Keep writing.

  45. I really liked your blog article.Really looking forward to read more. Much obliged.

  46. Really appreciate you sharing this blog post.Thanks Again. Fantastic.

  47. Enjoyed every bit of your blog post.Really looking forward to read more. Awesome.

  48. A round of applause for your post.Thanks Again.

  49. Thanks-a-mundo for the post.Really looking forward to read more. Awesome.

  50. I loved your blog post.Really thank you! Want more.

  51. Thanks so much for the article.Thanks Again. Keep writing.

  52. Great, thanks for sharing this article. Keep writing.

  53. I really like and appreciate your blog post.Really thank you! Much obliged.

  54. Thanks a lot for the blog. Keep writing.

  55. Enjoyed every bit of your article post.Really looking forward to read more.

  56. Really enjoyed this blog article.Much thanks again. Want more.

  57. I really enjoy the article post.Really thank you! Much obliged.

  58. A big thank you for your article post.Really looking forward to read more.

  59. Really enjoyed this article.Really thank you! Much obliged.

  60. Enjoyed every bit of your blog.Thanks Again. Keep writing.

  61. Really enjoyed this blog. Great.

  62. Hey, thanks for the blog.Really looking forward to read more. Keep writing.

ランキング(週間)

  1. 1

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

  2. 2

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

  3. 3

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

  4. 4

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

  5. 5

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

  6. 6

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

  7. 7

    YouTubeの概要欄に貼られたリンクをクリックしてサイトを訪れたユーザーを計測するために

  8. 8

    ECサイトのゴールデンルートを発見する方法 – Google Analytics 4とPythonを活用して(第1回)

  9. 9

    GA4 「ユーザー コンバージョン率」「セッションのコンバージョン率」の算出方法は?(2022年8月23日更新)

  10. 10

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

最近の記事

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

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

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

カテゴリー

 
TOP