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

データ レイヤー(data layer)

下記は、第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…

ランキング(週間)

  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で異なるドメイン(サブドメイン)の同一ページパスをドメイン付きで表示する

  10. 10

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

最近の記事

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

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

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

カテゴリー

 
TOP