> For the complete documentation index, see [llms.txt](https://help.littledata.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.littledata.io/integrations/shopify-to-segment/send-data-from-segment-to-google-analytics.md).

# How to send data from Segment to Google Analytics

Littledata's Segment app for Shopify stores makes it easy to track your site events and send the data to Segment. But how do you connect that data to GA?

Littledata's [Shopify source for Segment](https://help.littledata.io/integrations/shopify-to-segment/how-it-works) sends your store's events to Segment. This page shows you the two ways to get that data into Google Analytics 4 (GA4), and how to map events in Segment's GA4 destination.

### Choose how to connect GA4

You can send data to GA4 in two ways:

1. **Connect GA4 directly in the Littledata app.** Littledata's [Shopify to GA4 connection](https://help.littledata.io/integrations/shopify-to-google-analytics/how-it-works-shopify-to-ga4) works alongside the Segment connection.
2. **Connect GA4 through Segment.** Add Segment's Google Analytics 4 web destination and cloud destination, then map each event.

#### Option 1: Connect GA4 through Littledata

The Littledata GA4 connection is a complete tracking setup for GA4. It uses server-side tracking to capture every order, and it links orders back to the user's session. This gives you better channel reporting and marketing attribution. It also adds custom dimensions such as customer lifetime revenue, purchase count and Shopify customer ID.

You add it from the Littledata app, the same way as any other connection. Read more about [what you can track in GA4](https://help.littledata.io/integrations/shopify-to-google-analytics/how-it-works-shopify-to-ga4).

#### Option 2: Connect GA4 through Segment

If you prefer to send data from Segment, you need two Segment destinations:

1. [**Google Analytics 4 Web**](https://segment.com/docs/connections/destinations/catalog/actions-google-analytics-4-web): loads the `gtag` library in the browser and collects pageviews and sessions.
2. [**Google Analytics 4 Cloud**](https://segment.com/docs/connections/destinations/catalog/actions-google-analytics-4): sends Littledata's server-side events, such as orders, to GA4.

{% hint style="info" %}
Littledata adds the GA client ID and session ID to events (`integrations.Google Analytics.clientId` and `integrations.Google Analytics.sessionId`) only when GA4 is loaded on your store. Add the web destination so server-side events can be linked to the right user and session in GA4.
{% endhint %}

### Map events in the GA4 cloud destination

After you add the Google Analytics 4 Cloud destination, enter your **Measurement ID** and **API secret** in its settings. Then map each Segment event to a GA4 event.

Segment has preset GA4 actions for the common ecommerce events. You need to set up a mapping for each event you want to send. Here are the usual pairs:

| Littledata event (Segment) | GA4 action in Segment | Sent from |
| -------------------------- | --------------------- | --------- |
| Product Viewed             | View Item             | Browser   |
| Product List Viewed        | View Item List        | Browser   |
| Product Clicked            | Select Item           | Browser   |
| Cart Viewed                | View Cart             | Browser   |
| Product Added              | Add to Cart           | Server    |
| Product Removed            | Remove from Cart      | Server    |
| Checkout Started           | Begin Checkout        | Server    |
| Payment Info Entered       | Add Payment Info      | Server    |
| Order Completed            | Purchase              | Server    |
| Order Refunded             | Refund                | Server    |

See the full lists of [server-side events](https://help.littledata.io/integrations/shopify-to-segment/how-it-works#server-side-events) and [device-mode events](https://help.littledata.io/integrations/shopify-to-segment/how-it-works#device-mode-events).

The steps below use the Purchase event as an example. Repeat them for each event.

{% stepper %}
{% step %}

### Add a new mapping

In your GA4 Cloud destination, open the **Mappings** tab and click **New Mapping**. Search for the GA4 action (here, **Purchase**) and select it.

![](https://3956158252-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1QhTbrMraNWciQeDvu1b%2Fuploads%2Fgit-blob-35812e10b6ad293b1e6622504ce38a8841198318%2Fscreenshot-2023-08-02-at-11.35.16-pm.png?alt=media\&token=997f6ab0-550e-48e7-90f8-fef78b715e93)
{% endstep %}

{% step %}

### Keep the event trigger

Leave the **Select events to map and send** section as it is. For Purchase, the trigger is **Event Type is Track** and **Event Name is Order Completed**.

![](https://3956158252-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1QhTbrMraNWciQeDvu1b%2Fuploads%2Fgit-blob-77ba9d231bf03cba3b77d40dd985b650408dc491%2Fscreenshot-2023-08-02-at-11.43.14-pm.png?alt=media\&token=33977e5b-0e3e-44c7-ad55-70a5619e0ba4)
{% endstep %}

{% step %}

### Load a test event

In the test event section, click **Load Test Event from Source** to use a real event from your store. If you don't have one yet, paste the sample event below.

```
{
  "anonymousId": "7d2f31cf-12cd-4fe7-8b61-796b082f792d",
  "context": {
    "externalIds": [
      {
        "collection": "users",
        "encoding": "none",
        "id": "5451621433524",
        "type": "shopify_customer_id"
      }
    ],
    "integration": {
      "name": "shopify_littledata",
      "version": "9.1"
    },
    "ip": "109.166.139.0",
    "library": {
      "name": "analytics-node",
      "version": "6.2.0"
    },
    "page": {
      "url": "https://george-littledata.myshopify.com/57897812148/orders/b07de23de195ff866426b18bd8e6a95c/authenticate?key=edebaf51b8746e8b44714c6c9649209e"
    },
    "traits": {
      "address": {
        "city": "Bucharest",
        "country": "Romania",
        "postalCode": "030333",
        "state": "București"
      },
      "email": "mockEmail@littledata.io",
      "firstName": "John",
      "lastName": "Doe"
    },
    "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36",
    "userConsent": {
      "analytics": "no",
      "marketing": "no",
      "preferences": "no",
      "sale_of_data": ""
    }
  },
  "event": "Order Completed",
  "id": 5190210224308,
  "integrations": {
    "Google Analytics": {
      "clientId": "635000679.1691589098",
      "sessionId": "1691589165"
    }
  },
  "messageId": "node-e9241c5a0bfe61b173cae1fa1f13e1ff-b97ef265-0df8-42f3-9825-79ca1420b6b1",
  "originalTimestamp": "2023-08-09T13:55:11.696Z",
  "properties": {
    "action_source": "system_generated",
    "affiliation": "Shopify",
    "app_id": 580111,
    "cart_id": "ed496915e493c6f840aa326d3ebc546d",
    "category": "Shopify (Littledata)",
    "checkout_id": 30049366999220,
    "currency": "GBP",
    "email": "johndoe@littledata.io",
    "fbp": "fb.1.1691589233972.1542748812",
    "lifetime_revenue_littledata": "0.00",
    "order_id": "#1332",
    "presentment_amount": "1248.99",
    "presentment_currency": "GBP",
    "products": [
      {
        "brand": "george-littledata",
        "category": "Metallica",
        "compare_at_price": "1346.00",
        "image_url": "https://cdn.shopify.com/s/files/1/0578/9781/2148/products/NewFourHorsementTshirt.jpg?v=1667494039",
        "name": "Tricou cu Metallica",
        "presentment_amount": "1234.00",
        "presentment_currency": "GBP",
        "price": 1234,
        "product_id": "7306213753012",
        "quantity": 1,
        "shopify_product_id": "7306213753012",
        "shopify_variant_id": "42003742982324",
        "sku": "",
        "url": "https://george-littledata.myshopify.com/products/tricou-cu-metallica",
        "variant": "Default Title"
      }
    ],
    "purchase_count_littledata": 0,
    "sent_from": "Littledata app",
    "shipping": 14.99,
    "shopify_customer_id_littledata": 5451621433524,
    "source_name": "web",
    "subtotal": 1234,
    "tax": 0,
    "total": 1248.99
  },
  "receivedAt": "2023-08-09T13:55:11.967Z",
  "receivedDate": "2023-08-09T13:55:11.144Z",
  "sentAt": "2023-08-09T13:55:11.698Z",
  "shopID": "qZMKeB4Y6HRRgKkxs",
  "timestamp": "2023-08-09T13:55:11.965Z",
  "transaction": true,
  "type": "track",
  "userId": "5451621433524",
  "writeKey": "SbjsudVDtq96preF33MZ6UzxSttXrtRZ"
}
```

{% endstep %}

{% step %}

### Map the client ID and user ID

In the **Select Mappings** section, set these fields:

* **Client ID**: select `integrations.Google Analytics.clientId`
* **User ID**: select `userId`

Then click **Show all fields**.

![](https://3956158252-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1QhTbrMraNWciQeDvu1b%2Fuploads%2Fgit-blob-c8f2166bac3b1306b85c20940efc5d10ca37757a%2Fscreenshot-2023-08-03-at-12.06.25-am.png?alt=media\&token=674cc4ae-4277-4f8d-a47d-40f20470becd)
{% endstep %}

{% step %}

### Add the session ID

Under event parameters, search for and select `integrations.Google Analytics.sessionId`.

![](https://3956158252-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1QhTbrMraNWciQeDvu1b%2Fuploads%2Fgit-blob-ed84ca8635e85fc80c9995094102a7fee46b1900%2Fscreenshot-2023-08-03-at-12.12.47-am.png?alt=media\&token=a327237f-0032-4ebc-ae64-c813146ff0ff)

Enter `session_id` as the key name.

![](https://3956158252-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1QhTbrMraNWciQeDvu1b%2Fuploads%2Fgit-blob-4c55fa35e4fdc43740b50fd0dde1bf38534b4e6b%2Fscreenshot-2023-08-03-at-12.13.06-am.png?alt=media\&token=7cf77a92-bd3f-41d6-9eb2-37f81c2f0f7a)

{% hint style="info" %}
The key name must be exactly `session_id`. GA4 uses this parameter to link the event to the user's session.
{% endhint %}
{% endstep %}

{% step %}

### Test the mapping

In the **Send test event** section, check how the event will look, then click **Test Mapping**. You should see **Test succeeded!**

![](https://3956158252-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1QhTbrMraNWciQeDvu1b%2Fuploads%2Fgit-blob-09fcc5ec501ad3a50c46c6b19119dc124cc66dfc%2Fscreenshot-2023-08-03-at-12.17.10-am.png?alt=media\&token=de11edb8-a071-45ef-baba-0d2ce382a796)
{% endstep %}

{% step %}

### Save and enable the mapping

Click **Save**. New mappings are disabled by default, so turn the mapping on in the **Mappings** list.
{% endstep %}
{% endstepper %}

{% hint style="info" %}
After you finish all your mappings, check the **Mappings** list again and make sure every mapping is enabled.
{% endhint %}

### Related articles

* [How it works: Shopify source for Segment](https://help.littledata.io/integrations/shopify-to-segment/how-it-works)
* [How it works: Shopify to Google Analytics](https://help.littledata.io/integrations/shopify-to-google-analytics/how-it-works-shopify-to-ga4)
* [Shopify to Segment installation guide](https://help.littledata.io/integrations/shopify-to-segment/installation)
* [FAQ: Shopify to Segment connection](https://help.littledata.io/integrations/shopify-to-segment/segment-faq)
