This is a Google Analytics 4 extension for Spree Commerce - the open-source eCommerce platform for Rails.
This Google Analytics 4 integration for Spree Commerce allows you to track user behavior, sales performance, and marketing effectiveness across your store.
With minimal setup required, you can gain valuable insights into how visitors interact with your site, which can help you make informed decisions to improve conversions, user experience, and overall business strategy.
Note
To set up the Google Analytics integration, you must have a Google Analytics account and an associated property.
By default, the following events will be tracked in Google Analytics 4:
- page_view
- first_visit
- session_start
- user_engagement
- search
- add_payment_info
- add_shipping_info
- add_to_cart
- add_to_wishlist
- begin_checkout
- purchase
- remove_from_cart
- view_cart
- view_item
-
Add this extension to your Gemfile with this line:
bundle add spree_google_analytics
-
Run the install generator
bundle exec rails g spree_google_analytics:install
-
Restart your server
If your server was running, restart it so that it can find the assets properly.
Please follow our setup guide to start tracking all events in Google Analytics dashboard.
-
Create a dummy app
bundle update bundle exec rake test_app
-
Add your new code
-
Run tests
bundle exec rspec
When testing your applications integration with this extension you may use it's factories. Simply add this require statement to your spec_helper:
require 'spree_google_analytics/factories'
bundle exec gem bump -p -t
bundle exec gem release
For more options please see gem-release README
If you'd like to contribute, please take a look at the instructions for installing dependencies and crafting a good pull request.
Copyright (c) 2025 [name of extension creator], released under the New BSD License
Join our Slack to meet other 6k+ community members and get some support.
Contact us for enterprise support and custom development services. We offer:
- migrations and upgrades,
- delivering your Spree application,
- optimizing your Spree stack.