• Интеграции и плагины
  • Сообщество
  • Связаться с нами
Документация

Нужна помощь в разработке плагина интеграции для Medusa?

Написать намНайти плагины

Gorgo снижает затраты на адаптацию Medusa к локальным рынкам.

Мы разрабатываем плагины интеграции, осуществляем поддержку и развиваем сообщество разработчиков на Medusa в Telegram.

  • Ресурсы
  • Интеграции и плагины
  • Сообщество
  • Medusa Чат в Telegram
  • Medusa Новости в Telegram
  • Документация
  • Контакты
  • head@gorgojs.com
  • TelegramGitHub
MedusaПлагиныGoogle analytics medusa
G

Google analytics medusa

A Medusa plugin for sending ecommerce spec events to Google Analytics using the Measurement Protocol.

Нужна доработка этого плагина?

Связаться с нами
npm install @variablevic/google-analytics-medusa
Категория
Аналитика
Создано
Variable Vic
Версия
0.1.1
Последнее обновление
4 месяца назад
Ежемесячные загрузки
635
Звезды на Github
0
npmNPM
MedusaПлагиныGoogle analytics medusa

Medusa GA4 Plugin

A Google Analytics 4 plugin for Medusa that automatically tracks ecommerce events on your backend using Measurement Protocol. This plugin implements server-side tracking for key ecommerce events in your Medusa store.

Features

The plugin automatically tracks the following GA4 ecommerce events:

  • - When items are added to a cart
  • - When items are removed from a cart
  • - When shipping information is added to a cart
  • - When payment information is added
  • - When an order is placed

Prerequisites

  • Medusa backend
  • Google Analytics 4 property
  • GA4 Measurement ID
  • GA4 API Secret

Installation

yarn add @variablevic/google-analytics-medusa

Configuration

Add the plugin to your :

import { defineConfig } from "@medusajs/utils";
// ... other imports and environment variables
export default defineConfig({
// ... other configurations
plugins: [
// ... other plugins
{
resolve: "@variablevic/google-analytics-medusa",
options: {
measurementId: "G-XXXXXXXX", // Your GA4 Measurement ID
apiSecret: "XXXXXXXXXX", // Your GA4 API Secret
debug: false, // Optional, enables debug mode - no events will be sent to your property when debug is active!
},
},
],
});

Client-Side Setup

This plugin handles server-side events, but some GA4 ecommerce events need to be implemented on the client side due to their nature:

  • - Product views
  • - Checkout initiation
  • - User registration
  • - User login

Additionally, to properly associate events with users, you need to set the GA client ID as metadata when creating a cart. Here's how to do it in the Next.js Starter:

  1. Get the GA client ID from the cookie:
export const getGaClientId = async (): Promise<string | null> => {
const cookies = await nextCookies();
const gaClientIdCookie = cookies.get("_ga")?.value;
const gaClientId = (gaClientIdCookie as string)
.split(".")
.slice(-2)
.join(".");
return gaClientId;
};
  1. Set the client ID as cart metadata during cart creation:
const gaClientId = await getGaClientId();
const body = {
region_id: region.id,
} as Record<string, any>;
if (gaClientId) {
body.metadata = {
ga_client_id: gaClientId,
};
}
const cartResp = await sdk.store.cart.create(body, {}, headers);

Events Data Format

The plugin automatically formats cart and order data according to GA4's ecommerce event specifications. Each event includes:

  • Currency code
  • Transaction value
  • Item-level details (name, variant, quantity, price)
  • Customer information when available

Development

  1. Clone this repository
  2. Install dependencies:
  3. Build the project:
  4. Test the plugin:

For local development and testing:

npx medusa plugin:develop

Contributing

Contributions are welcome! Please read our contributing guidelines before submitting a pull request.

License

MIT

Еще в этой категории

Посмотреть все
Аналитика
V

V2 bloomreach

От Igor Ludgero Miura

Bloomreach integration for Medusa V2 for customers, catalog, and search. It can also be used for transactional emails.

GitHubnpm

Еще от этого автора

Посмотреть все
Платежи
M

Mollie payments medusa

От Variable Vic

A Medusa plugin for Mollie payments.

GitHubnpm
Уведомления
K

Klaviyo medusa

От Variable Vic

A Klaviyo plugin for Medusa.

npm