Use the Data Manager API to send Google Analytics [recommended](https://developers.google.com/data-manager/api/reference/analytics/recommended-events) and
[custom events](https://support.google.com/analytics/answer/12229021).

[Send recommended and custom events](https://developers.google.com/data-manager/api/devguides/events/analytics/recommended-custom-events/send-events)

If you're upgrading from the [Google Analytics Measurement Protocol](https://developers.google.com/analytics/devguides/collection/protocol/ga4)
check out
[Upgrade from Measurement Protocol to the Data Manager API](https://developers.google.com/data-manager/api/devguides/events/analytics/measurement-protocol/upgrade) for
instructions.

## Workflow overview

To send event data with the Data Manager API, complete the following steps:

1. **Prepare destinations:** Define the
   [`Destination`](https://developers.google.com/data-manager/api/reference/rest/v1/Destination) objects for the `destinations`
   field of the ingestion request to specify the target account and conversion
   or event destination. See
   [Prepare destinations](https://developers.google.com/data-manager/api/devguides/events/analytics/recommended-custom-events/send-events#prepare_destinations) for
   details.

2. **Prepare event data and identifiers:** Construct each
   [`Event`](https://developers.google.com/data-manager/api/reference/rest/v1/events/ingest#event) and include any
   [required fields and identifiers](https://developers.google.com/data-manager/api/devguides/events/analytics/recommended-custom-events/send-events#event_field_requirements).
   Normalize and SHA-256 hash any user contact information
   in [`userData`](https://developers.google.com/data-manager/api/reference/rest/v1/events/ingest#Event.FIELDS.user_data)
   according to the

   [formatting guidelines](https://developers.google.com/data-manager/api/devguides/concepts/formatting), and optionally
   [encrypt](https://developers.google.com/data-manager/api/devguides/concepts/encryption) it. See

   [Prepare event data](https://developers.google.com/data-manager/api/devguides/events/analytics/recommended-custom-events/send-events#prepare_event_data) for details.

3. **Build and send the ingestion request:** Submit an
   [`events.ingest`](https://developers.google.com/data-manager/api/reference/rest/v1/events/ingest) request containing your

   `destinations`, [`Event`](https://developers.google.com/data-manager/api/reference/rest/v1/events/ingest#event) records, and
   [`encryptionInfo`](https://developers.google.com/data-manager/api/reference/rest/v1/EncryptionInfo) if you encrypted
   `userData`.

   Use `validateOnly: true` to test your payload for
   [fast-fail errors](https://developers.google.com/data-manager/api/devguides/concepts/understand-errors#fast-fail)
   before sending production data. See [Send events](https://developers.google.com/data-manager/api/devguides/events/analytics/recommended-custom-events/send-events) for
   field requirements and code samples.

4. **Check request status and diagnostics:** Check
   asynchronous processing status and review diagnostics with
   [`requestStatus.retrieve`](https://developers.google.com/data-manager/api/devguides/diagnostics).

## Use cases

> [!IMPORTANT]
> **Key Point:** The intent of the Data Manager API is to augment automatic collection through gtag, Tag Manager, and Google Analytics for Firebase, not to replace it.

Here are some use cases for sending recommended and custom events with the
Data Manager API:

- Tie online to offline behavior.

- Measure client-side and server-side interactions.

- Send events that happen outside standard user interaction, like offline
  conversions.

- Send events from devices and apps where automatic collection isn't
  available, like kiosks and watches.

## User-provided data

You can send first-party customer data, such as hashed email addresses, phone
numbers, and physical addresses, in the [`userData`](https://developers.google.com/data-manager/api/reference/rest/v1/events/ingest#Event.FIELDS.user_data) field of an `Event`. This
helps improve conversion measurement, attribution, and audience building in
Google Analytics.

Keep the following in mind when sending user-provided data:

- **Sent with events** : In the Data Manager API, user-provided data must be sent
  as part of an `Event`. Standalone uploads without an event aren't
  supported.

- **Formatting and hashing** : Personal identifiers (such as email address,
  phone number, name, and street address) must be normalized and hashed using
  SHA-256 before upload. Other fields (such as city, state or province,
  postal code, and country code) are normalized but not hashed. Follow the
  [Format user data](https://developers.google.com/data-manager/api/devguides/concepts/formatting#userdata_format) guide
  for specific requirements.

- **Encryption** : You can optionally
  [encrypt](https://developers.google.com/data-manager/api/devguides/concepts/encryption) hashed user data.

- **User-ID** : We recommend providing the [`userId`](https://developers.google.com/data-manager/api/reference/rest/v1/events/ingest#Event.FIELDS.user_id) alongside [`userData`](https://developers.google.com/data-manager/api/reference/rest/v1/events/ingest#Event.FIELDS.user_data)
  whenever a consistent user identifier is available.

- **Implementation** : See [Add user-provided data](https://developers.google.com/data-manager/api/devguides/events/analytics/recommended-custom-events/send-events#add_user_data) for
  instructions on constructing requests.

## Integration considerations

Keep the following considerations in mind when using the Data Manager API.

### Remarketing

Google Analytics supports same-device remarketing when you turn on [Google signals](https://support.google.com/analytics/answer/9445345). For
cross-device remarketing, [`userId`](https://developers.google.com/data-manager/api/reference/rest/v1/events/ingest#Event.FIELDS.user_id) is required.

In addition, you can send [user-provided data](https://developers.google.com/data-manager/api/devguides/events/analytics/recommended-custom-events#user_provided_data) to enable
first-party audience matching.

### Advertising identifiers

Google Analytics automatically joins advertising identifiers (such as GBRAID or WBRAID)
collected during online interactions with Data Manager API events using
[`clientId`](https://developers.google.com/data-manager/api/reference/rest/v1/events/ingest#Event.FIELDS.client_id) or [`appInstanceId`](https://developers.google.com/data-manager/api/reference/rest/v1/events/ingest#Event.FIELDS.app_instance_id).

### Privacy settings

Google Analytics joins Data Manager API events with online interactions using
[`clientId`](https://developers.google.com/data-manager/api/reference/rest/v1/events/ingest#Event.FIELDS.client_id) or [`appInstanceId`](https://developers.google.com/data-manager/api/reference/rest/v1/events/ingest#Event.FIELDS.app_instance_id) to adopt user privacy settings such as
"non-personalized ads" and "limit ad tracking".

You can also specify user consent settings directly on each event using the
[`consent`](https://developers.google.com/data-manager/api/reference/rest/v1/Consent) object.

### Geographic and device information

Google Analytics automatically joins the most recent geographic and device information
from tagging with Data Manager API events using [`clientId`](https://developers.google.com/data-manager/api/reference/rest/v1/events/ingest#Event.FIELDS.client_id) or [`appInstanceId`](https://developers.google.com/data-manager/api/reference/rest/v1/events/ingest#Event.FIELDS.app_instance_id).
This ensures that your Data Manager API events are reflected in reports that include
geographic and device dimensions.

If you want a Data Manager API event to reflect geographic and device information
from a *specific* session instead of the latest information for the
[`clientId`](https://developers.google.com/data-manager/api/reference/rest/v1/events/ingest#Event.FIELDS.client_id) or [`appInstanceId`](https://developers.google.com/data-manager/api/reference/rest/v1/events/ingest#Event.FIELDS.app_instance_id), include an entry in
[`additionalEventParameters`](https://developers.google.com/data-manager/api/reference/rest/v1/events/ingest#Event.FIELDS.additional_event_parameters) with `parameterName` set to `session_id` and
`value` set to the ID of the specific session, and send the event within
24 hours of the start of the session.

You can provide [geographic information](https://developers.google.com/data-manager/api/reference/rest/v1/events/ingest#Event.FIELDS.event_location) and [device information](https://developers.google.com/data-manager/api/reference/rest/v1/events/ingest#Event.FIELDS.event_device_info) for events
using the Data Manager API.

### Full server-to-server

While it's possible to send events to Google Analytics solely with the
Data Manager API, only partial reporting might be available. The purpose of the
Data Manager API is to augment existing events collected using gtag, Tag Manager,
or Firebase. Some event and parameter names are [reserved](https://support.google.com/analytics/answer/13316687#reserved) for use through
automatic collection and can't be sent through the Data Manager API.

### Generate or rename events

Events sent with the Data Manager API don't trigger rules for
[generating or renaming events](https://support.google.com/analytics/answer/10085872). Your application should
implement the logic to send custom events through the Data Manager API, similar
to the rules configured in the Google Analytics UI.