WEB担当ツール・ハウツー

【解説】Googleアナリティクス、EC-CUBEのGA4設定方法(eコマーストラッキング対応)

投稿日:2023年2月10日 更新日:

Googleアナリティクス、EC-CUBEのGA4設定方法(eコマーストラッキング対応)の解説です。

【2023年7月にGA4へ】

2023年7月に、既存バージョン「ユニバーサルアナリティクス」から、新規バージョン「GA4」に完全移行することがGoogleで発表されました。

今回、ECサイト(EC-CUBE)で「GA4」をGoogleタグマネージャー(
GTM )経由で設定する方法を解説します。
eコマーストラッキングも設定します。

【GA4初期設定の手順資料がほしい方】
Googleアナリティクス(GA4) Web担当者がしている初期設定の全手順の解説

※資料はGoogle docsです。購入後に送付する資料に閲覧URLを共有してますので、適宜、閲覧もしくはダウンロードしてください。
※加工編集も可能です。個人、社内、クライアントへの共有、資料作成の元資料としてもご活用ください。

Googleアナリティクス(GA4) Web担当者がしている初期設定の全手順の解説

【レクチャーしてほしい方】
設定がうまくできない、よく分からない、という方はレクチャーサポートしております。

Googleアナリティクス(GA4)個別講座
-GA4の使い方、初期設定、施策立案まで対応

【設定代行してほしい方】
設定出来ない、設定する時間がない、という方は代行サポートしております。

Googleアナリティクス(GA4)まとめて設定代行サービス

Web365とは

Web365は、外部Web担当者として、クライアントのWebサイトの集客力を高める施策を運用代行しています。

Web365について詳しく知りたい方は「Web365とは」ご覧ください。

GA4とGTMの設定

GA4のプロパティ発行と、GTMのアカウント発行、グローバルサイトタグの場所などは、下記に記載しておりますのでご確認ください。

【解説】googleアナリティクス、GA4の設定方法がうまくできないときの複数設定方法

まずは、GTMのグローバルサイトタグがコピペできる状態まで進めてください。

EC-CUBEのGA4設定

本題、まず、ECーCUBEの設定箇所は大きく2つです。

  1. レイアウト管理
  2. ブロック管理

ブロック管理

まずブロック管理で、必要なコードをつくります。

ブロック管理でGTMのグローバルサイトタグのブロックを作成する

まずは、GTMのグローバルサイトタグのブロック作成をします。

ブロック作成、ブロックをレイアウト管理で該当箇所に挿入、というイメージです。

ec-cube_ga4設定06

GTMのグローバルサイトタグは2つ

  1. head用のブロック
  2. body用のブロック

head用のブロック

ec-cube_ga4設定05

ブロック名:Google Analytics (GA4) トラッキングタグ_head
ファイル名:gtag_ga4_head

GTMのグローバルサイトタグのコード:

自身のGTM内のからコピーして貼る。下記コード例

<!-- 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-〇〇');</script>
<!-- End Google Tag Manager -->

body用のブロック

ec-cube_ga4設定04

ブロック名:Google Analytics (GA4) トラッキングタグ_body
ファイル名:gtag_ga4_body

GTMのグローバルサイトタグのコード:

自身のGTM内のからコピーして貼る。下記コード例

<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-〇〇"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->

レイアウト管理で先のブロックを挿入

先に作成したブロックを該当箇所に挿入します。

ec-cube_ga4設定03

トップページレイアウト

  1. 画像、右のブロック一覧からドラッグドロップで、
  2. <head></head>タグ内に
  3. ブロック「Google Analytics (GA4) トラッキングタグ_head」をドロップ
  4. <body>タグ直後に
  5. ブロック「Google Analytics (GA4) トラッキングタグ_body」をドロップ
  6. 登録をクリック
ec-cube_ga4設定02

下層ページレイアウト

  1. 画像、右のブロック一覧からドラッグドロップで、
  2. <head></head>タグ内に
  3. ブロック「Google Analytics (GA4) トラッキングタグ_head」をドロップ
  4. <body>タグ直後に
  5. ブロック「Google Analytics (GA4) トラッキングタグ_body」をドロップ
  6. 登録をクリック
ec-cube_ga4設定01

eコマーストラッキングの設定

eコマーストラッキングタグのブロックを作成します。

ブロック名:Google Ecommerce Tag
ファイル名:ecommerce_gatag

GTMのグローバルサイトタグのコード:

下記コード例(参考:

{% if app.request.get('_route') == 'product_list' %}
    {# 商品一覧 #}
    <script>
        dataLayer.push({ecommerce: null});
        // GA4
        dataLayer.push({
            'event': 'view_item_list',
            'ecommerce': {
                'items': [
                    {% for Product in pagination %}
                    {
                        'item_name': '{{ Product.name }}',
                        'item_id': '{{ Product.getCodeMin ? Product.getCodeMin : Product.id }}',
                        'price': '{{ Product.getPrice02IncTaxMin }}',
                        'item_category': '{% for ProductCategory in Product.ProductCategories %}{% for Category in ProductCategory.Category.path %}{% if ( Category.parent is not null ) %}{{ Category.Parent.name }}:{{ Category.name }}{% endif %}{% endfor %}{% endfor %}',
                    }{% if not loop.last %},{% endif %}
                    {% endfor %}
                ]
            }
        });

        // UA
        dataLayer.push({
            'ecommerce': {
                'currencyCode': 'JPY',
                'impressions': [
                    {% for Product in pagination %}
                    {
                        'name': '{{ Product.name }}',
                        'id': '{{ Product.getCodeMin ? Product.getCodeMin : Product.id }}',
                        'price': '{{ Product.getPrice02IncTaxMin }}',
                        'category': '{% for ProductCategory in Product.ProductCategories %}{% for Category in ProductCategory.Category.path %}{% if ( Category.parent is not null ) %}{{ Category.Parent.name }}:{{ Category.name }}{% endif %}{% endfor %}{% endfor %}',
                    }{% if not loop.last %},{% endif %}
                    {% endfor %}
                ]
            }
        });

    </script>

{% elseif app.request.get('_route') == 'product_detail' %}
    {# 商品詳細 #}
    <script>
        // Measure a view of product details. This example assumes the detail view occurs on pageload,
        dataLayer.push({ecommerce: null});  // Clear the previous ecommerce object.
        // GA4
        dataLayer.push({
            'event': 'view_item',
            'ecommerce': {
                'items': [{
                    'item_name': '{{ Product.name }}',
                    'item_id': '{{ Product.getCodeMin ? Product.getCodeMin : Product.id }}',
                    'price': '{{ Product.getPrice02IncTaxMin }}',
                    'item_category': '{% for ProductCategory in Product.ProductCategories %}{% for Category in ProductCategory.Category.path %}{% if ( Category.parent is not null ) %}{{ Category.Parent.name }}:{{ Category.name }}{% endif %}{% endfor %}{% endfor %}',
                    'quantity': '1'
                }]
            }
        });

        // UA
        dataLayer.push({
            'ecommerce': {
                'detail': {
                    'products': [{
                        'name': '{{ Product.name }}',         // Name or ID is required.
                        'id': '{{ Product.getCodeMin ? Product.getCodeMin : Product.id }}',
                        'price': '{{ Product.getPrice02IncTaxMin }}',
                        'category': '{% for ProductCategory in Product.ProductCategories %}{% for Category in ProductCategory.Category.path %}{% if ( Category.parent is not null ) %}{{ Category.Parent.name }}:{{ Category.name }}{% endif %}{% endfor %}{% endfor %}',
                    }]
                }
            }
        });
    </script>

{% elseif app.request.get('_route') == 'cart' %}
    {# カートに追加 #}
    <script>
        // Measure when a product is added to a shopping cart
        dataLayer.push({ecommerce: null});  // Clear the previous ecommerce object.
        // GA4
        dataLayer.push({
            'event': 'add_to_cart',
            'ecommerce': {
                'items': [
                    {% for CartIndex,Cart in Carts %}
                    {% for CartItem in Cart.CartItems %}
                    {% set ProductClass = CartItem.ProductClass %}
                    {% set Product = ProductClass.Product %}
                    {
                        'item_name': '{{ Product.name }}',
                        'item_id': '{{ Product.getCodeMin ? Product.getCodeMin : Product.id }}',
                        'price': '{{ Product.getPrice02IncTaxMin }}'
                    }{% if not loop.last %},{% endif %}
                    {% endfor %}
                    {% endfor %}
                ]
            }
        });

        // UA
        dataLayer.push({
            'event': 'addToCart',
            'ecommerce': {
                'currencyCode': 'JPY',
                'add': {
                    'products': [
                        {% for CartIndex,Cart in Carts %}
                        {% for CartItem in Cart.CartItems %}
                        {% set ProductClass = CartItem.ProductClass %}
                        {% set Product = ProductClass.Product %}
                        {
                            'name': '{{ Product.name }}',
                            'id': '{{ Product.getCodeMin ? Product.getCodeMin : Product.id }}',
                            'price': '{{ Product.getPrice02IncTaxMin }}',
                            'quantity': {{ CartItem.quantity }}
                        }{% if not loop.last %},{% endif %}
                        {% endfor %}
                        {% endfor %}
                    ]
                }
            }
        });

    </script>

{% elseif app.request.get('_route') == 'shopping_complete' %}
    {# 購入完了 #}

    {% if Order.id %}
        <script>
            dataLayer.push({ecommerce: null});
            // GA4
            dataLayer.push({
                'event': 'purchase',
                'ecommerce': {
                    'transaction_id': '{{ Order.order_no }}',
                    'affiliation': '{{ BaseInfo.shop_name }}',
                    'value': '{{ Order.subtotal }}',
                    'tax': '{{ Order.tax }}',
                    'shipping': '{{ Order.delivery_fee_total }}',
                    'currency': 'JPY',
                    'items': [
                        {% for OrderItem in Order.MergedProductOrderItems %}
                        {
                            'item_name': '{{ OrderItem.product_name }}',
                            'item_id': '{{ OrderItem.product_code ? OrderItem.product_code : OrderItem.product.id }}',
                            'price': '{{ OrderItem.price_inc_tax }}',
                            'item_category': '{% for ProductCategory in OrderItem.Product.ProductCategories %}{% for Category in ProductCategory.Category.path %}{% if ( Category.parent is not null ) %}{{ Category.Parent.name }}:{{ Category.name }}{% endif %}{% endfor %}{% endfor %}',
                            'quantity': {{ OrderItem.quantity }}
                        }{% if not loop.last %},{% endif %}
                        {% endfor %}
                    ]
                }
            });

            // UA
            dataLayer.push({
                'ecommerce': {
                    'purchase': {
                        'actionField': {
                            'id': '{{ Order.order_no }}',
                            'affiliation': '{{ BaseInfo.shop_name }}',
                            'revenue': '{{ Order.subtotal }}',
                            'tax': '{{ Order.tax }}',
                            'shipping': '{{ Order.delivery_fee_total }}'
                        },
                        'products': [
                            {% for OrderItem in Order.MergedProductOrderItems %}
                            {
                                'name': '{{ OrderItem.product_name }}',
                                'id': '{{ OrderItem.product_code ? OrderItem.product_code : OrderItem.product.id }}',
                                'price': '{{ OrderItem.price_inc_tax }}',
                                'category': '{% for ProductCategory in OrderItem.Product.ProductCategories %}{% for Category in ProductCategory.Category.path %}{% if ( Category.parent is not null ) %}{{ Category.Parent.name }}:{{ Category.name }}{% endif %}{% endfor %}{% endfor %}',
                                'quantity': {{ OrderItem.quantity }}
                            }{% if not loop.last %},{% endif %}
                            {% endfor %}
                        ]
                    }
                }
            });
        </script>
    {% endif %}

{% endif %}

レイアウト管理で先のブロックを挿入

先に作成したブロックを該当箇所に挿入します。

ec-cube_ga4設定03

トップページレイアウト

  1. 画像、右のブロック一覧からドラッグドロップで、
  2. <head></head>タグ内に
  3. ブロック「 Google Ecommerce Tag 」をドロップ
  4. 登録をクリック

下層ページレイアウト

  1. 画像、右のブロック一覧からドラッグドロップで、
  2. <head></head>タグ内に
  3. ブロック「Google Ecommerce Tag」をドロップ
  4. 登録をクリック

以上です。

テストのチェック方法は、

  1. GTMのプレビューで確認
  2. GA4内のdebug Viewで確認
  3. GA4内のレポート>リアルタイムでの確認

があります。

3については、下記記事に記載してますので、ご確認ください。

【解説】googleアナリティクス、GA4の設定方法がうまくできないときの複数設定方法

【手順や見方、個別課題について受講したい方】
GA4の初期設定や見方、考え方、個別の課題について課題解決型の講座です。

Googleアナリティクス(GA4)個別講座
-GA4の使い方、初期設定、施策立案まで対応

 

【設定代行してほしい方】
設定出来ない、設定する時間がない、という方は代行サポートしております。

Googleアナリティクス(GA4)まとめて設定代行サービス

サイト計測・分析で相談したい方、そもそものWebサイトの分析提案や改善実行など相談したい方はこちらよりお気軽にご連絡ください。

必須お名前
必須メールアドレス
必須メッセージ本文






Web制作+Webマーケティングの個別講座開講中

Web365はWeb担当者のスキルセットである
サイトを変更する「提案力」と「技術力」について個別指導しております


・Webで集客するための「考え方」を知りたい方
・サイトの制作改善のセオリーを知りたい方
・自身のサイトでケーススタディをしたい方
・サイトの制作改善の「技術的なスキル」を習得したい方
・分析から改善運用まで自身でしたい方


どうぞWeb365の「自社のWebサイトを自身で作りたい、改善したい人のオーダーメイド個別講座」をご覧ください。






外注のWeb担当者として「制作」と「マーケティング」で単発/継続でサポートします。

Web365は貴社のWeb担当者として、制作改善運用をワンストップサポートしています

・成果にこだわるサイト制作改善をお望みの方
・良いweb制作会社、コンサル会社がいないとお困りの方
・分析から改善運用まで一括で依頼したい方


是非Web365までご相談ください。

WEB担当ツール・ハウツー

執筆者:

関連記事

Googleカレンダーと連携した日程予約カレンダーをつくりました

日程予約カレンダーを作成しました。 アポ前の社内調整をGoogleカレンダーでカンタンにできます。 カレンダーの対応可能日程のみをフォームに表示させ、第3希望まで選択できるフォームです。 カレンダーは …

【簡単】サイトマップを自作するときのリンク抽出ツールの紹介

サイトマップを自作するときに、リンクをひとつひとつコピペするのは大変です。抽出ツールをいくつか探してみて、おすすめを紹介します。 まず、ここでのサイトマップの定義は、サイトのページのタイトルとリンクを …

文字起こしは音声データを口頭でGoogleドキュメントに音声入力するがなんだかんだ一番かもです

文字起こしは音声データを口頭でGoogleドキュメントに音声入力するがなんだかんだ一番かもです。 クライアントさんの話を聞き書きし、記事化する業務をしています。 その際に、音声データを文字起こしする必 …

テキストメールのリンクパラメータ

【Webマーケティング】テキストメールのメルマガ効果測定はリンクパラメータがおすすめ

テキストメールでのメルマガ送付の効果測定をどうしようか試行錯誤していませんか? そんなときは、リンクパラメータの付与がおすすめです。 リンクパラメータでメールのリンクがクリックされたかがGoogleア …

【コピペ】Googleスプレッドシートでアポ調整シートをつくりました

        Googleスプレッドシートでアポ調整シートをつくりました。 アポ前のご自身の候補日を先方にメールする際に、日程候補をコピペできるシートです。 …

【体験】オンラインビジネスチャットサポートってなに?無料体験の流れと機能を解説

Webサイトの閲覧ユーザーの満足度をあげる機能「オンラインビジネスチャットサポート」、つまりチャットってどんなものなの?いちサービスを無料体験してみた流れと機能解説などしてみたいと思います。 Web3 …

検索上位へのSEO対策、記事をGoogleサーチコンソールにフェッチしよう

サイトを検索上位に上げたいときのSEO対策です。 まずは、書いた記事を公開したらGoogleサーチコンソールにフェッチしましょう。 その理由と方法を解説します。   この記事でわかることGo …