> ## Documentation Index
> Fetch the complete documentation index at: https://docs.segmentstream.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to track ad platform lead forms in analytics and CRM

> Create synthetic landing pages and virtual sessions to track and attribute leads generated on ad platforms like Meta, LinkedIn, Google Ads, and TikTok.

When users submit lead forms directly on ad platforms (Meta, LinkedIn, Google Ads, TikTok, etc.), they never reach your website -- meaning you lose the UTMs and client IDs that traditional analytics systems rely on.

This guide explains how to recreate synthetic landing pages, generate a Google-style Client ID (UUID), and send both to your CRM and Google Analytics 4 (GA4) for unified attribution -- even when no site visit occurs.

***

## Overview of the process

For each incoming lead (from any ad platform):

1. Capture ad metadata (campaign, ad, platform).
2. Build a **synthetic landing page URL** using UTMs.
3. Generate a **Google Client ID (UUID)**.
4. Send both fields (`landing_page`, `google_client_id`) to your **CRM**.
5. Send a synthetic **lead event** to **GA4** using the same client ID.
6. Once implemented, **SegmentStream** can automatically stitch GA4 events, CRM leads, and campaign costs -- even for leads collected inside the platforms without website visits.

***

## Why this works

Even though the user never lands on your site, the synthetic landing page and UUID create a virtual session. This lets analytics systems register a visit with proper UTMs and connect it to your CRM record, providing a unified, channel-attributed view of lead generation performance.

***

## Step 1: Generate a Google Client ID (UUID)

Instead of simulating GA4's native client ID, simply use a UUID for clarity. This makes it evident that the session was artificially generated.

```javascript theme={null}
function generateCID() {
  return crypto.randomUUID();
}
```

Example output:

```
1d52c3ab-bb40-4b23-b7a2-9266a1c89d4b
```

Store this in your CRM as `google_client_id`, and reuse the same value when sending the GA4 event.

***

## Step 2: Create synthetic landing pages

For each lead, construct a synthetic landing page URL in this format:

```
https://yourdomain.com/leadgen?utm_source={platform}&utm_medium=leadform&utm_campaign={campaign_name}&utm_content={ad_name}&cid={google_client_id}
```

This URL will never actually load; it simply represents where the lead *would* have landed if they visited your website.

### Example

```
https://yourdomain.com/leadgen?utm_source=facebook&utm_medium=leadform&utm_campaign=Summer_Sale&utm_content=Ad_1&cid=1d52c3ab-bb40-4b23-b7a2-9266a1c89d4b
```

Store this in your CRM as the field `landing_page`.

***

## Step 3: Send synthetic event to GA4

Use the GA4 Measurement Protocol endpoint:

```
https://www.google-analytics.com/mp/collect?measurement_id=G-XXXXXXX&api_secret=YOUR_SECRET
```

**Payload example:**

```json theme={null}
{
  "client_id": "1d52c3ab-bb40-4b23-b7a2-9266a1c89d4b",
  "events": [{
    "name": "lead_submission",
    "params": {
      "page_location": "https://yourdomain.com/leadgen?utm_source=facebook&utm_medium=leadform&utm_campaign=summer_sale&utm_content=ad_1",
      "source_platform": "facebook",
      "form_type": "lead_form"
    }
  }]
}
```

***

## Step 4: Send data to CRM

Your CRM (HubSpot, Pipedrive, Salesforce, etc.) should include at least the following custom fields:

| Field              | Description                                    |
| ------------------ | ---------------------------------------------- |
| `landing_page`     | Synthetic URL with UTMs                        |
| `google_client_id` | UUID shared with GA4                           |
| `source_platform`  | Platform name (Meta, LinkedIn, TikTok, Google) |
| `campaign_name`    | From ad metadata                               |
| `ad_name`          | From ad metadata                               |

***

## Step 5: Platform-specific implementation

### Meta (Facebook and Instagram Lead Ads)

**Metadata available:** `ad_id`, `ad_name`, `adset_name`, `campaign_name`, `platform`

**UTM formula:**

```
utm_source=facebook&utm_medium=leadform&utm_campaign={{campaign_name}}&utm_content={{ad_name}}
```

**Automation flow:**

1. Trigger: New Lead in Facebook Lead Ads
2. Generate `google_client_id` (UUID)
3. Build `landing_page` URL
4. Send both to CRM
5. Post synthetic `lead_submission` event to GA4 via webhook

***

### LinkedIn Lead Gen Forms

**Metadata available:** `campaignName`, `adGroupName`, `creativeId`, `leadGenFormName`, `platform`

**UTM formula:**

```
utm_source=linkedin&utm_medium=leadform&utm_campaign={{campaignName}}&utm_content={{creativeId}}
```

**Automation flow:**

1. Trigger: New LinkedIn Lead
2. Generate `google_client_id`
3. Construct `landing_page` URL
4. Push to CRM
5. Send event to GA4

***

### Google Ads Lead Form Extensions

**Metadata available:** `campaign_name`, `ad_group_name`, `form_id`

**UTM formula:**

```
utm_source=google&utm_medium=leadform&utm_campaign={{campaign_name}}&utm_content={{ad_group_name}}
```

**Automation flow:**

1. Trigger: New Google Lead Form Submission
2. Generate `google_client_id`
3. Build synthetic `landing_page` URL
4. Send to CRM
5. Push to GA4

***

### TikTok Instant Forms

**Metadata available:** `campaign_name`, `adgroup_name`, `ad_name`, `platform`

**UTM formula:**

```
utm_source=tiktok&utm_medium=leadform&utm_campaign={{campaign_name}}&utm_content={{ad_name}}
```

**Automation flow:**

1. Trigger: New TikTok Lead
2. Generate `google_client_id`
3. Build synthetic `landing_page` URL
4. Send both to CRM
5. Send GA4 event via webhook

***

## Summary

| Step | Action                                            |
| ---- | ------------------------------------------------- |
| 1    | Capture ad metadata                               |
| 2    | Generate UUID as `google_client_id`               |
| 3    | Construct synthetic `landing_page` with UTMs      |
| 4    | Send to CRM                                       |
| 5    | Send synthetic GA4 event via Measurement Protocol |

Once implemented, SegmentStream will automatically stitch these leads -- aligning GA4 events, CRM leads, and ad spend data -- allowing full visibility into campaign performance even when the user never visited your website.
