Skip to main content
Version: next

Google Analytics

Implement server-side events with Google Analytics Measurement Protocol.

Introduction

Google Analytics provides a JS SDK to push events to their servers. To do server-to-server communication, you need to use Google Analytics Measurement Protocol.

Prerequisites

To use Google Analytics Measurement Protocol, you need to get your API Secret and your measurement ID.

  • Measurement ID
  • Measurement Protocol API Secret
info

Please follow the Google Analytics Measurement Protocol Documentation to learn how to get them.

Setup Front-Commerce

Update your app/config/serverEvents.ts file:

app/config/serverEvents.ts
import {
ConsoleIntegration,
AnalyticsIntegration,
} from "@front-commerce/core/server-events/integrations";
// higlihjt-next-line
import analytics from "@front-commerce/core/analytics";

export default {
//...
integrations: [
// ...
new AnalyticsIntegration("front-commerce", [
analytics.GA4MeasurementProtocol(
"G-XXXXXXXX", // Your Analytics Measurement ID
"XXXXXXXXXXXXXXXXXXXXXX" // Your Analytics Measurement Protocol Secret
),
]),
],
};

Then in analytics configuration, enable server tracking in analytics configuration:

app/config/analytics.ts
//...
export default {
analytics: {
enable: true,
debug: process.env.NODE_ENV !== "production",
serverTracking: {
enabled: true,
},
//..
} satisfies AnalyticsConfig,
};

And that's it! Now every event will be submitted to Google Analytics by your server!

Compatible events

Front-Commerce eventGoogle Analytics event
Products Searchedsearch
Product List Viewedview_item_list
Product Clickedselect_content
Product Viewedview_item
Product Addedadd_to_cart
Product Removedremove_from_cart
Cart Viewedview_cart
Checkout Startedbegin_checkout
Payment Info Enteredadd_payment_info
Order Completedpurchase
User Logged inlogin
User Createdsign_up
Product Added to Wishlistadd_to_wishlist