Skip to main content
Google Tag Manager is a flexible tag management tool that lets you deploy and manage analytics, SEO, and marketing scripts across your store without editing code. You can connect services like Google Analytics 4, Google Ads, Meta Pixel, Microsoft Clarity, LinkedIn Insights, and Hotjar from one central workspace. Spree makes it easy to connect your store to GTM and uses its ecommerce dataLayer to automatically push rich event data to your GTM container - no custom code required.
This integration allows you to use either Google Tag Manager or Google Analytics 4 - but not both at the same time. Only one key (GTM or GA4) should be active in the integration settings. If you plan to use GA4 with GTM, you must set up GA4 inside of your GTM workspace manually.

Requirements

To use this integration, you’ll need:
  • An active Google Tag Manager account
  • A GTM container set up for your store
  • Any additional tools (e.g., Google Analytics 4, conversion tracking, custom tags) configured within GTM
Spree will automatically push ecommerce events to the dataLayer, but it’s up to you to configure tags and triggers in your GTM workspace.

Installation

Before you can enable Google Tag Manager, it must be installed. To do so, you need to run the following command:
bundle add spree_google_analytics && bundle exec rails g spree_google_analytics:install
After that, make sure to restart your server if it was running.

Connect Google Tag Manager

Sign in to your Spree admin dashboard and navigate to the Integrations tab. Locate the Google Analytics tile under Analytics and click Connect Google Analytics. This will redirect you to the setup page for Google Tag Manager integration. Ignore the GA4 Measurement ID field. Paste your GTM Container ID (e.g., GTM-XXXXXXX) into the Google Tag Manager ID field. Finally, click Create to activate the integration.

Event Tracking

Spree sends a full suite of ecommerce events to the GTM dataLayer. This allows you to create triggers and tags based on:
  • Product views
  • Cart actions (add/remove)
  • Checkout progress
  • Payment info added
  • Purchase confirmation
  • Search activity
  • Wishlist adds
  • Newsletter signups
  • User engagement (sessions, first visits, etc.)
To make use of these events, you’ll need to configure appropriate tags and triggers inside your GTM container.

Manage Your Integration

To remove the integration or switch between GTM and GA4: Return to the integration setup page in Spree and either:
  • Clear the GTM field and enter a GA4 Measurement ID, or
  • Click Delete in the lower-right corner to remove the integration completely
Only one analytics key should be set at a time (GA4 or GTM).
I