GTM4WP – A Google Tag Manager (GTM) plugin for WordPress

説明

Google タグ マネージャー (GTM) は、直感的な Web UI で、どなたでもアナリティクスやマーケティングのタグ、その他のコードスニペットの管理とデプロイができる Google の無料ツールです。このツールの詳細は公式ウェブサイトをご覧ください。

プラグインが GTM コンテナのコードスニペットを WordPress サイトに設置するので、もう手動で追加する必要はありません。
複数コンテナにも対応しています !

このプラグインは、ページのメタデータとユーザー情報を「データレイヤー」にプッシュすることで、GTM 設定を補完します。
Google の公式ヘルプページにデータレイヤーの詳細があります。

PHP 7.4 is required to use this plugin.

GTM コンテナコードの置き換え

オリジナルのGTMコンテナコードは2つのパートに分かれます:

前半は、サイト全ページの <head> セクションに追加される JavaScript コードスニペットです。
これは GTM のすべての機能を有効化する重要な部分です。本プラグインは、この部分をサイトに正しく設置するのに役立ちます。

後半は、ユーザーの JavaScript が無効な場合にフォールバックとして機能する iframe スニペットです。
Google は最高のパフォーマンスを得るために、このコードスニペットを各ページの <body> タグの直後に設置することを推奨しています。

理想的ではありませんが、これはコードのより下のほうに設置しても機能します。本プラグインは2番目のコード スニペットのコード配置オプションを提供します。

使用中の WordPress テーマが WordPress 5.2の追加機能と互換性がある場合、本プラグインはこの2番目のコードを適切な場所に配置します。
Genisis テーマ、GeneratePress テーマ、Elementor、Oxygen Builder および Beaver Builder テーマのユーザーも、これを正しく配置できます。
これを利用するには、プラグインオプションの互換モードをオフに設定してください。

その他のサイトでは、カスタム PHP コード (「手動コード」オプション) を使用してこの2番目のコードスニペットを設置するか、いわゆる「フッター」オプションを選択して、コードの下部にコードを追加できます (これは推奨される方法ではありませんが、機能します)

基本データに含まれるもの

  • 投稿 / 固定ページのタイトル
  • 投稿 / 固定ページの日付
  • 投稿 / 固定ページのカテゴリー名
  • 投稿 / 固定ページのタグ名
  • 投稿 / 固定ページの投稿者 ID 名と名前
  • 投稿 / 固定ページの ID
  • 投稿タイプ
  • post format
  • 現在のページを含む、現在のカテゴリー / タグ / タクソノミー内の投稿数
  • 任意の投稿タイプに紐づくカスタムターム
  • ログイン状態
  • ログイン中ユーザーの権限グループ
  • ログイン中ユーザー ID (Google アナリティクスでクロスデバイス行動を追跡するため)
  • logged in user email address (both unhashed and SHA256 hased values to be used with tracking)
  • ログイン中ユーザーの作成日
  • サイト検索データ
  • サイト名と ID (WordPress マルチサイトインスタンス向け)
  • 訪問者の IP アドレス (使用する際は、訪問者の明示的な同意を得てください)

ブラウザー / OS / 端末データ

  • ブラウザーデータ (名前、バージョン、エンジン)
  • OS データ (名前、バージョン)
  • 端末データ (種類、製造元、モデル)

WhichBrowser ライブラリの提供データを使用します: http://whichbrowser.net/

気象データ

(ベータ)

ユーザーの現在の気象条件に関するデータを dataLayer にプッシュします。これは、広告プラットフォームで天気関連のオーディエンス/リマーケティングリストを生成するために使用でき、Web 分析ソリューションでユーザー セグメンテーションを可能にします。

  • 気象カテゴリー (曇り、雨、晴れなど)
  • 気象の説明: より招待なデータ
  • 摂氏または華氏の温度
  • 気圧
  • 風速と気温

気象データは Open Weather Map からクエリされます。サイトのトラフィックによっては、追加料金が適用される場合があります。
http://openweathermap.org/price

機能を利用するには、OpenWeatherMap の (無料の) API キーが必要です。

ipstack.com は、サイト訪問者の位置を特定するために使用されます。この機能を動作させるには、IPStack.com の (無料の) API キーが必要です。
https://ipstack.com/product

メディア再生イベント

(試験中)

あらゆる埋め込みメディアのユーザーインタラクションを追跡します。

  • YouTube
  • Vimeo
  • Soundcloud

DataLayer イベントは、メディアプレイヤーの読み込み、メディアの再生中、一時停止 / 停止、およびオプションでユーザーがメディア再生時間の10、20、30、…、90、100% に達したときに発火するよう選択できます。

埋め込みメディアの追跡は、WordPress 組み込みの oEmbed 機能はもちろん、他のほとんどのメディアプラグインやコピー & ペーストコードで設置するものに対応しています。ページ読み込み後にサイトに挿入されるプレイヤーには、現在非対応です。

スクロールトラッキング

訪問者がページトップから下までを、どのようにスクロールしたかを基準にタグを発火します。
例えば、「読者」(一定時間ページで過ごす) と「スクロールだけする人」(数秒以内にスクロールする人) を分けることが考えられます。これらのイベントを使用して、アナリティクスタグやリマーケティング / コンバージョンタグ (マイクロ コンバージョン用) を発火できます。

スクロールトラッキングは、以下の方々が開発したものを元にしています。

  • Nick Mihailovski
  • Thomas Baekdal
  • Avinash Kaushik
  • Joost de Valk
  • Eivind Savio
  • Justin Cutroni

オリジナルスクリプト:
http://cutroni.com/blog/2012/02/21/advanced-content-tracking-with-google-analytics-part-1/

タグ マネージャーのタグ、トリガー、変数のブラックリストとホワイトリスト

サイトのセキュリティ強化のため、タグ / トリガー / 変数をホワイトリストおよびブラックリスト登録するオプションがあります。
GTM の設定に関係なく、特定タグの発火や、特定の種類の変数の使用を防止できます。

GTM アカウントに関連付けられた Google アカウントがハッキングされると、攻撃者はホスティング サーバー上のコードにアクセスしなくても、サイト上でマルウェアを簡単に実行できてしまいます。カスタム HTML タグやカスタム JavaScript 変数をブラックリストに登録することで、タグ マネージャーコンテナを保護できます。

機能連携

複数の人気プラグインとの機能連携があります。今後さらに追加予定です !

  • Contact Form 7: フォームが何らかの結果 (メール送信、メール失敗、スパム検出、無効な入力)での送信時にイベントを発火
  • WooCommerce:
    • GA4 e コマースの実装
    • プロモーションには非対応、なぜなら WooCommerce 本体にその機能は (まだ) ないので
    • 返金は非対応
    • Compatibility with High Performance Order Storage (HPOS)
  • AMP: ページの AMP バージョンに AMP コンテナを読み込む
  • Cookiebot: use automatic cookie blocking mode if needed
  • Google Consent Mode v2: fire the “default” command with specific consent flags to integrat with non-certified Consent Management Platforms (CMPs) and plugins.

サーバーコンテナ

サーバーコンテナを使用している場合、カスタムドメイン名とカスタムパスを入力し、そこから gtm.js を読み込むことができます。

Exclude specific user roles from being tracked

You can set which user roles needs to be excluded from tracking when a user with that role visits the frontend. This will completely disable the container code for that user.

スクリーンショット

  • 管理画面
  • 基本設定
  • イベント
  • 機能連携パネル
  • 高度な設定
  • スクロールトラッキング

インストール

  1. Upload duracelltomi-google-tag-manager-for-wordpress to the /wp-content/plugins/ directory
  2. WordPress の「プラグイン」メニューからプラグインを有効化してください
  3. Go to Settings / Google Tag Manager and enter your Google Tag Manager container ID and set additional options

FAQ

○○ するには、どうすればいいですか

さまざまな Google タグ マネージャーの設定と実装のチュートリアルは、私のウェブサイトで入手できます:
https://gtm4wp.com/setup-gtm4wp-features

WooCommerce で、PayPal やサードパーティの決済サービスのトランザクションが Google アナリティクスで追跡できません

PayPal やその他サードパーティの決済代行サービスは、デフォルトで決済が成功してもユーザーをサイトにリダイレクトしません。
お客様をサイトに戻すようにしても、サンキューページに到達する前にブラウザを閉じる場合があります。これは、Google アナリティクスやその他のタグが呼び出されない可能性があることを意味します。

決済代行サービスの設定で、サイトへ戻る設定を有効化してください。これにより、お支払い後に簡単な情報ページを表示し、ユーザーをサイトにリダイレクトするようになり、トランザクション追跡の精度と頻度が向上します。

Purchase event is not tracked with WooCommerce

If you are using a 3rd party plugin that alters the default order received page in a way that does not utilize the integration hooks
of WooCommerce then this can happen. Either stop using this 3rd party plugin or ask them to better mimic the behavior of the
default order received page by supporting the woocommerce is_order_received_page and the woocommerce_thankyou actions and filters.

タグ / 変数クラスをブラックリスト登録するオプションがないのはなぜですか

Although Google recommends to blacklist tags and variables using classes, people struggle to know
which tags/variables gets affected. Therefore I opted for individual tags and variables rather than classes
on the blacklist tabs.

Regarding variables; ensure they are not part of any critical tags as blacklisting such variables will render said tags useless.

Google タグ マネージャーでスクロールイベントを追跡するには

Google タグ マネージャーは、パーセンテージまたはピクセルに基づく基本的なスクロール深度の追跡を標準でサポートしています。本プラグインでは、スクロールトラッキングイベントを追加し、ユーザーの意図やエンゲージメントを捉えることにより重点を置いています。

ルール定義で使用できるデータレイヤーイベントは5種類あります。

  • gtm4wp.reading.articleLoaded: コンテンツが読み込まれました
  • gtm4wp.reading.startReading: the visitor started to scroll. The timeToScroll dataLayer variable stores duration since the article loaded (in seconds)
  • gtm4wp.reading.contentBottom: 訪問者はコンテンツの最後 (ページではありません!) に到達しました。timeToScroll dataLayer 変数を更新
  • gtm4wp.reading.pagebottom: 訪問者がページの最後に到達しました。timeToScroll データレイヤー変数を更新
  • gtm4wp.reading.readerType: based on time spent since article loaded we determine whether the user is a ‘scanner’ or ‘reader’ and store this in the readerType dataLayer variable

Example use cases: using these events as triggers, you can fire Google Universal Analytics and/or Google Ads remarketing/conversion tags
to report micro conversions and/or to serve ads only to visitors who spend more time reading your content.

評価

2025年10月29日
We’ve been using GTM4WP for all of our clients websites and it’s been super reliable. The eCommerce tracking integration has been a huge time saver for us. Huge thank you for this plugin Thomas Geiger!
2025年8月13日 1 reply
I am writing this review to save other developers and site owners the immense amount of time I have just lost. I needed to implement standard GA4 e-commerce tracking on a professional WordPress/WooCommerce site. Based on its popularity and countless recommendations, I chose GTM4WP as the solution to generate the required dataLayer. Unfortunately, after days of intensive, professional-level debugging, I discovered that the plugin was completely non-functional in my specific—yet very common—environment. The plugin failed at its two most essential tasks: GTM Snippet Injection: The plugin’s most basic feature—injecting the GTM container script into the website’s <head> and <body>—did not work at all. The script was simply not present. I had to bypass this functionality entirely and inject the code manually using another method (Code Snippets) just to get our GTM container to load. E-commerce dataLayer Generation (The Deal-Breaker): This is the primary reason anyone uses this plugin. After successfully loading our GTM container manually, I ran a full test purchase. By analyzing the GTM debug mode and the site’s dataLayer object, I can confirm that GTM4WP completely failed to generate the purchase event and its corresponding ecommerce object on the WooCommerce order confirmation page. It produced absolutely nothing. My Technical Environment (Please read this before you install):To help others, here is the stack where the plugin failed. This is likely the source of the conflict: CMS: WordPress E-commerce: WooCommerce Theme: Hello Elementor (using a child theme) Page Builder: Elementor Pro Key Detail: I am using Elementor Pro to customize the WooCommerce page templates, including the “Thank You” / “Order Received” page. Conclusion: My conclusion is that GTM4WP is fundamentally incompatible with themes or page builders that override default WooCommerce templates—a standard practice for virtually any custom-designed website today. Because it cannot handle this common scenario, the plugin proved to be entirely useless for my project. While it may work on simple sites with basic, unmodified themes, it is not a reliable solution for professional, customized builds. The time and effort wasted diagnosing this incompatibility were substantial. I cannot recommend this plugin and strongly advise users with a similar tech stack to seek a manual implementation from the start.
2025年3月10日
Em vários sites que o plugin está instalado, após alguma atualização, o menu mobile de alguns sites não abre.
2024年12月2日
I’m disappointed with the support for this plugin. I submitted a question over a week ago, but I have yet to receive any response from the support team. While the plugin itself may work fine, having reliable support is critical, especially when issues arise. Unfortunately, the lack of responsiveness has made it difficult to trust this plugin for long-term use. I hope the team improves their support response time in the future.
154件のレビューをすべて表示

貢献者と開発者

GTM4WP – A Google Tag Manager (GTM) plugin for WordPress はオープンソースソフトウェアです。以下の人々がこのプラグインに貢献しています。

貢献者

“GTM4WP – A Google Tag Manager (GTM) plugin for WordPress” は11ロケールに翻訳されています。 翻訳者のみなさん、翻訳へのご協力ありがとうございます。

“GTM4WP – A Google Tag Manager (GTM) plugin for WordPress” をあなたの言語に翻訳しましょう。

開発に興味がありますか ?

コードを閲覧するか、SVN リポジトリをチェックするか、開発ログRSS で購読してみてください。

変更履歴

1.22.3

  • Fixed: when timeout for the select_item event with WooCommerce is set to 0, plugin does not halt the browser from loading the product page
  • Fixed: properly reading timeout for select_item eventCallback

1.22.2

  • Fixed: purchase event was not fired when is_order_received_page() WooCommerce tag was not supported by the template and the fallback method had to activate.

1.22.1

  • Fixed: yet another fix to the purchase tracking. Thanks Khnaz35

1.22

  • Added: new WooCommerce option to change the event timeout of the select_item event. Could help some UX issues when a user has an ad blocker installed.
  • Added: new WordPress filter GTM4WP_WPFILTER_OVERWRITE_COMO_FLAG / gtm4wp_overwrite_consent_mode_flag to overwrite Consent Mode flags in the default command. Can be used by consent banner plugins to mitigate support issues.
  • Fixed: Unwanted content on frontend when container placement set to off and gtm4wp_the_gtm_tag() called manually. Thanks Michael Bourne
  • Fixed: Add to cart tracking broken with Bricks template and WooCommerce
  • Updated: bundled WhichBrowser library updated to the latest version. This is a short term solution to solve PHP erros, on the long term, the plan is to switch to Matomo Device Detector
  • Updated: allow the / character in GTM container path to support same tag gateway
  • Updated / Fixed: I reverted back the purchase tracking with WooCommerce to the logic present in v1.20- as the new way caused more headache than it resolved. Sorry for everyone who was affected by this.

1.21.1

  • Fix: undefined product_qty variable prevents add_to_cart in some cases. Thanks diegoarda
  • Fix: clarified that WebToffee integartion is only needed with the legacy 2.x product line
  • Fix: Reflected Cross-Site Scripting (XSS) with site search tracking. Thanks godzeo!

1.21

!!! WARNING !!!
Significant change in WooCommerce integration!
Check your template whether it supports must have hook: woocommerce_thankyou

  • Added: new WooCommerce option that allows you to fire the view_item event during page load of a variable product using parent product data.
  • Added: item_group_id parameter includes the parent ID of a variable product in WooCommerce
  • Added: GTM4WP_WPFILTER_GET_CSP_NONCE (PHP constant) / gtm4wp_get_csp_nonce WordPress filter to add nonce to script tags supporting Content Security Policy (CSP) setups
  • Updated: purchase event is now fired on the woocommerce_thankyou event. This will move execution time behind consent state checks in most cases making the purchase event working in more cases
  • Updated: GTM4WP_WPFILTER_EEC_ORDER_DATA / gtm4wp_eec_order_data WordPress filter now has a second parameter passing the whole WC_Order object to the filter after the $order_data parameter
  • Updated: no view_cart or begin_checkout events will be triggered from the backend if there are no products in the cart. This prevents wrong data collection with themes not properly supporting WooCommerce hooks
  • Fix: load_plugin_textdomain() related PHP notice on admin page

1.20.3

  • Fix: notice “_load_textdomain_just_in_time was called incorrectly” – WordPress 6.7 compatibility

1.20.2

  • Fix: Wrong ID parameter used tracking product variations (id instead of item_id). Thanks micmaf
  • Fix: do not track add_to_cart in product lists when ‘Select options’ or ‘View products’ buttons are clicked
  • Fix: JavaScript reference error while updating cart count in WooCommerce. Thanks Sakuk3
  • Fix: hash customerBillingEmailHash just like orderData.customer.billing.email_hash (for enhanced conversions, use the value in orderData)
  • Added: minimum required WooCommerce version (currently 5.0+) is displayed now on GTM4WP admin

1.20.1

  • Fix: do not load GTM container when OFF and console.log OFF. Thanks morvy
  • Fix: reverted a change where item_id in ecommerce data layer was converted to numeric type when the value was a numeric value. It will be kept as a string to preserve compatibility with other integrations.
  • Fix: JavaScript error when element ID not set correctly in scroll tracking
  • Changed: better normalize and hash user data with WooCommerce + orderData variable for enhanced conventions
  • Changed: PHP code optimization by hans2103
  • Added: New filter to be able to modify data in the orderData variable on a WooCommerce order received page. Filter can be accessed either using the GTM4WP_WPFILTER_EEC_ORDER_DATA constant or the gtm4wp_eec_order_data string.

1.20

THE BIG CLEANUP RELEASE!

Lots of deprecated features removed.
The code of WooCommerce integration was cleaned and restructured, if you have any custom code that relies on GTM4WP internal data structure,
please update the plugin on a test version of your website before updating your live site!

  • Removed: deprecated Universal Analytics events for WooCommerce
  • Removed: deprecated filter GTM4WP_WPFILTER_AFTER_DATALAYER/gtm4wp_after_datalayer
  • Removed: deprecated filter GTM4WP_WPFILTER_ADDGLOBALVARS/gtm4wp_add_global_vars
  • Removed: deprecated feature that puts the ‘Do not track’ option of the browser into the data layer. It is a deprecated browser feature therefore removed from this plugin.
  • Removed: deprecated Google Optimize integration
  • Removed: deprecated constants GTM4WP_OPTION_BLACKLIST_MACRO_* and GTM4WP_OPTION_BLACKLIST_
  • Removed: deprecated WordPress filter GTM4WP_WPFILTER_GETTHEGTMTAG (deprecated in v1.16)
  • Changed: lots of internal function names and variable names changed, although is not recommended to depend on them, if you did, check your code
  • Changed: renamed WP filter gtm4wp_datalayer_on_pageload to gtm4wp_woocommerce_datalayer_on_pageload to better reflect when it is called.
  • Changed: orderData data layer variable in WooCommerce integration now includes keys to better support enhanced conversions setup:
    • orderData.customer.billing.first_name_hash
    • orderData.customer.billing.last_name_hash
    • orderData.customer.billing.phone_hash
  • Deprecated: orderData.customer.billing.emailhash, please update to use orderData.customer.billing.email_hash (with an underscore)
  • Added: stockstatus key into the product array of every ecommerce action. Returns the value of WP_Product->get_stock_status(). Thanks hans2103.
  • Added: integration with WebToffee GDPR Cookie Consent plugin. GTM4WP can not fire a GTM event when user consent changes or when a previously stored consent has been loaded.
  • Fixed: add_payment_info and add_shipping_info events were not fired during checkout submit when not fired before on the page.
  • Fixed: GTM4WP will only look for the user’s IP address in the REMOTE_ADDR server variable. You may enter a custom HTTP header instead in plugin settings.

1.19.1

  • Fixed: run additional checks when determing product category to prevent PHP errors in certain cases
  • Fixed: corrected Consent Mode flag names in admin page description texts

1.19

WARNING!
Universal Analytics / GA3 ecommerce events deprecated!
Please update your GTM setup so that it does not rely on any of the following GTM4WP events and the old ecommerce data layer:
* gtm4wp.productClickEEC
* gtm4wp.addProductToCartEEC
* gtm4wp.removeFromCartEEC
* gtm4wp.checkoutOptionEEC
* gtm4wp.checkoutStepEEC
* gtm4wp.changeDetailViewEEC
* gtm4wp.orderCompletedEEC

Instead of the above events, you can use the new GA4 ecommerce events (add_to_cart, purchase, etc.)
In the Universal Analytics GTM tag now you have an option to use the GA4 ecommerce data in the data layer.
If you are on GA360 and still collecting ecommerce data, you need to update your GTM setup to use that option firing on the GA4 ecommerce events.

  • Updated: WooCommerce integration now accepts the primary category selection of Yoast SEO and Rank Math SEO
  • Updated: use the gtm4wp_admin_page_capability filter to modify the capability needed to use the admin page (thanks emreerkan)
  • Fixed: price did not include the .00 postfix for integers in the add_to_cart event
  • Added: if needed, you can turn on clearing the ecommerce object before a new GA4 event is being pushed.
  • Added: support for Google Consent Mode default command for use cases where the consent management tool does not support it already

1.18.1

  • Fixed: PHP notice about Undefined variable: blocking_cookie

1.18

  • Fixed: error while checking the new customer status in WooCommerce on the order received page (thanks morvy)
  • Fixed: Call to a member function get_meta() on null error on WooCommerce order received page (thanks Dekadinious)
  • Updated: WordPress and WooCommerce compatibility
  • Updated: Deprecated Google Optimize integration as the tool is sunsetting in September 2023
  • Added: Create a cookie named block_gtm4wp_geoip after a specific user selected cookie preferences. Set the value to either “yes”, “true”, “on” or “1” and the GeoIP (and weather API) feature will be disabled for that particular user