Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZRZ-1321 add support to eu endpoint #14

Merged
merged 2 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ This Managed Component (MC) uses [Amplitude’s HTTP API v2](https://www.docs.de

`api_key` Used to pass your Amplitude's Project API key. See [Find your Amplitude Project API Credentials](https://www.docs.developers.amplitude.com/analytics/find-api-credentials/) for help locating your credentials.

#### EU Data Residency `boolean` _optional_

`eu_data` For EU data residency, the project must first be set up inside [Amplitude EU](https://analytics.eu.amplitude.com/signup). Toggle on this field to change the standard endpoint with the EU residency endpoint: `https://api.eu.amplitude.com/2/httpapi`.

#### Minimun Id Length `Integer`, _optional_

`min_id_length` Use this field to override the Device IDs and User IDs minimum length. For more information, see Amplitude's docs for [Options](https://www.docs.developers.amplitude.com/analytics/apis/http-v2-api/#options).
Expand Down
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
const getEventData = (
event: MCEvent,
pageview: boolean,
ecomPayload?: any

Check warning on line 48 in src/index.ts

View workflow job for this annotation

GitHub Actions / build-test (20.x)

Unexpected any. Specify a different type
) => {
const { client } = event
const parsedUserAgent = UAParser(client.userAgent)
Expand Down Expand Up @@ -104,10 +104,10 @@
if (type === 'ecommerce') {
payload.event_type = name
payload.productId = payload.products
.map((product: any) => product.product_id)

Check warning on line 107 in src/index.ts

View workflow job for this annotation

GitHub Actions / build-test (20.x)

Unexpected any. Specify a different type
.join()
payload.quantity ??= payload.products.reduce(
(sum: any, product: any) => sum + parseInt(product.quantity, 10),

Check warning on line 110 in src/index.ts

View workflow job for this annotation

GitHub Actions / build-test (20.x)

Unexpected any. Specify a different type

Check warning on line 110 in src/index.ts

View workflow job for this annotation

GitHub Actions / build-test (20.x)

Unexpected any. Specify a different type
0
)
payload.revenue = payload.revenue || payload.total || payload.value
Expand All @@ -134,7 +134,7 @@
})

// sendEvent function is the main functions to send a server side request
const sendEvent = async (eventData: any) => {

Check warning on line 137 in src/index.ts

View workflow job for this annotation

GitHub Actions / build-test (20.x)

Unexpected any. Specify a different type
const requestBody = {
api_key: settings.api_key,
...(settings.min_id_length && {
Expand All @@ -143,8 +143,11 @@
events: [eventData],
}

const amplitudeEndpoint = 'https://api2.amplitude.com/2/httpapi'
manager.fetch(amplitudeEndpoint, {
const endpoint = settings.eu_data
? 'https://api.eu.amplitude.com/2/httpapi'
: 'https://api2.amplitude.com/2/httpapi'

manager.fetch(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down
Loading