GraphCommerce integrates with Google Analytics and Google Tagmanager and offers a generic Datalayer solution that can be used for other analytics tools.
The @graphcommerce/googletagmanager package makes it easy to add Google Tag
Manager (GTM) to your GraphCommerce webshop.
Install the Package: Ensure you have installed the
@graphcommerce/googleanalytics package.
Configuration: Add the following configuration values in your
graphcommerce.config.js:
// graphcommerce.config.js
const config = {
googleTagmanagerId: 'GTM-X1X1X1X',
storefront: [
{ locale: 'en', magentoStoreCode: 'en_US', defaultLocale: true },
{
locale: 'nl',
magentoStoreCode: 'nl_NL',
googleTagmanagerId: 'GTM-X2X2X2X', // Optionally override per storeview
},
],
}
GTM Setup: Ensure you have set up your GTM account and container:
The @graphcommerce/googleanalytics package makes it easy to add Google
Analytics GA4 to your GraphCommerce webshop.
❗️ You probably want to use GTM instead of Google Analytics directly through the datalayer. You should probably never use Google Analytics AND GTM at the same time.
To use this package, follow these steps:
Install the Package: Ensure you have installed the
@graphcommerce/googleanalytics package.
Configuration: Add the following configuration values in your
graphcommerce.config.js:
// graphcommerce.config.js
const config = {
googleAnalyticsId: 'GTM-X1X1X1X',
storefront: [
{ locale: 'en', magentoStoreCode: 'en_US', defaultLocale: true },
{
locale: 'nl',
magentoStoreCode: 'nl_NL',
googleAnalyticsId: 'GTM-X2X2X2X', // Optionally override per storeview
},
],
}
Configure the Page changes based on browser history events. in Google
Analytics. Refer to the
official documentation
for more details.
The following events are supported by default in GraphCommerce:
add_to_cartadd_to_cart_error (custom)view_cartbegin_checkoutadd_payment_infopurchaseview_item_listselect_itemremove_from_cartadd_shipping_inforemove_from_cartview_itemcwv_* metricsEnable core web vitals tracking.
const config = {
dataLayer: { coreWebVitals: true },
}
Install the Package: Ensure you have installed the
@graphcommerce/googleanalytics package.
Configuration: Add the following configuration values in your
graphcommerce.config.js:
// graphcommerce.config.js
const config = {
googleRecaptchaKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
storefront: [
{ locale: 'en', magentoStoreCode: 'en_US', defaultLocale: true },
{
locale: 'nl',
magentoStoreCode: 'nl_NL',
googleRecaptchaKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', // Optionally override per storeview
},
],
}