# Google Analytics

> Connecting the community's Google Analytics 4, the events Memberfy sends (visits, showcase, checkout, purchase, refund, sign-up, login and waitlist), the Measurement Protocol API secret for paid purchases with the page closed, and what is never sent.

With the community's **Google Analytics ID**, Memberfy sends **your** Google Analytics 4 the visits and the buyer's path, from the showcase to the purchase. In GA4 you see where sales come from, which plan converts best and where people drop out of checkout.

It's in **Administration › Settings › Search and discovery**, in the **Google Analytics** card.

## Who can

**Owner** and **admin**, the same people who open **Settings**.

## How it works

### What goes to your GA4

Only with the ID filled in. The names are GA4's recommended events, so Google's **Monetization** and **Funnel** reports work without any setup:

| Event | When |
|---|---|
| `page_view` | Each page opened, once, with the clean address (no parameters and no invite or offer codes) |
| `view_item_list` and `select_item` | The person sees the list of products or plans (catalog, [Store](/espacos/loja), plans) and clicks one of them |
| `view_item` | The person opens a product page |
| `begin_checkout` | Starts [checkout](/pagamentos/checkout) |
| `add_payment_info` | Chooses the payment method (PIX, boleto or card) |
| `purchase` | The purchase was paid: with the order number, the amount, the currency, the coupon and the items (product, plan or add-on). It also applies to add-ons, plan changes, [downsell](/monetizacao/downsell) offers and free products (amount 0) |
| `refund` | A [refund](/pagamentos/reembolsos-e-contestacoes) |
| `sign_up` and `login` | Someone creates an account or signs in |
| `generate_lead` | Someone joins a waitlist |

Each order counts **only once**: reloading the confirmation page, opening another tab or paying the PIX later doesn't repeat the purchase.

### What never goes

No personal data: no name, no email, no document, no phone, no person id. The events carry only what was seen or bought and how much it cost.

### The cookie notice

In a community with the Google Analytics ID filled in, whoever comes in for the first time sees the **Cookies in this community** notice: *"We use the cookies this community needs to work. With your permission, Running Club also measures visits with Google Analytics, which stores Google cookies in this browser."* The buttons are **Reject**, **Accept** and **Customize**.

- **Customize** shows **Necessary** (*"Sign-in, language and your cookie choice. Always on."*), which cannot be turned off, and **Measurement (Google Analytics)**, which the person turns on or off and confirms with **Save choice**.
- **Nothing from Google loads before Accept.** On Reject, measurement stops and the Google cookies are deleted from this browser.
- The choice lasts **12 months**, per community. **Cookies**, at the foot of the side menu and in the avatar panel, opens the notice again to change it.
- A community without a Google Analytics ID shows no notice.

**For the team: measurement drops.** GA4 now counts visits and browser events only for those who accept, so the numbers are lower than before the notice. With the [API secret](#the-api-secret-measurement-protocol), paid purchases still arrive, but those of people who refused are not tied to their visit.

### The API secret (Measurement Protocol)

Without the secret, the purchase only reaches GA4 if the person still has the page open when the payment is confirmed. A PIX or boleto paid later with the page closed, a card that was held for review and subscription renewals are left out.

With the **API secret (Measurement Protocol)**, Memberfy itself sends your GA4 the purchase of every paid order and every refund, even with nobody on the page. GA4 recognizes the same order coming from the browser and from Memberfy and **doesn't count the purchase twice**.

- It's optional.
- Once saved, the secret **never shows again**: the screen shows only **Configured** and the last 4 characters, with **Replace** and **Remove**.
- It has 8 to 100 characters: letters, numbers, `_` and `-`.

## Step by step: connect Google Analytics

*Role: owner or admin.*

1. In Google Analytics, create a GA4 property with a web stream and copy the **Measurement ID** (`G-…`).
2. In Memberfy, **Administration › Settings › Search and discovery**, paste it into **Google Analytics ID**.
3. **Save Changes**. Visits and the purchase path start showing up in your GA4.

## Step by step: the API secret

*Role: owner or admin.*

1. In GA4: **Admin › Data streams ›** your web stream **› Measurement Protocol API secrets › Create**. Give it a name (for example, *Memberfy*) and copy the **Secret value**.
2. In Memberfy, **Administration › Settings › Search and discovery**, paste it into **API secret (Measurement Protocol)**.
3. **Save secret**. The screen now shows **Configured ••••** and the last 4 characters.

To change it, **Replace**; to stop sending from the server, **Remove**.

## Example

**A course sold through PIX.** Bia sells the course *Excel from Scratch* for R$ 297. A buyer generates the PIX, closes the page and pays on their phone an hour later. Without the secret, this sale doesn't show up in GA4. With the secret, the `purchase` arrives with the order, the amount and the item *Excel from Scratch*, and GA4's **Monetization** report matches Memberfy's sales.

## Common errors and how to fix them

| Situation | What to do |
|---|---|
| *The secret has 8 to 100 characters: letters, numbers, _ and -.* | Copy the **Secret value** from GA4 again, without spaces |
| Purchases don't show up | Check the **Google Analytics ID** (`G-…`, from the same stream as the secret). In GA4, purchases take up to 24 hours to reach the reports; in **Realtime**, they show up within minutes |
| I lost the secret | It never shows again. Create another one in GA4 and use **Replace** |

## Frequently asked questions

**Why does GA4 show fewer visits now?**
Because measurement only starts after the person accepts the [cookie notice](#the-cookie-notice). Whoever refuses or has not answered yet is not counted.

**Do I need the secret?**
No. Without it, GA4 receives visits and purchases made with the page open. With it, it receives all of them.

**Does the Google Analytics ID measure the whole community?**
It measures the community's app: the showcase, the spaces, checkout and product pages.

**Can I use another tracker?**
From the screen, only Google Analytics.

## Through the assistant and the API

- Through the AI assistant: [`update_community_settings`](/mcp/ferramentas-comunidade#update-community-settings) with `ga_api_secret` saves the secret; the assistant never repeats it, it only says it's configured and gives the last 4 characters.
- Through the API: `PATCH /api/communities/{id}/settings` with `gaApiSecret` (`null` deletes it). `GET /api/communities/settings` returns `googleAnalyticsId`, `gaApiSecretConfigured` and `gaApiSecretLast4`, never the secret.

## Related

- [General settings](/configuracoes/configuracoes-gerais)
- [Checkout](/pagamentos/checkout)
- [Sales](/pagamentos/vendas)
