# Amplitude

Purchasely can send all your transactional events to Amplitude to enrich your users data.

## Events

The following events will be sent. You can set the event name of your choice in the console.

You can find the full list of events [here](/purchasely/3.4/analytics/events/webhook-events/subscription-events.md).

| Event                     | Description                                                                                                             |
| ------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| `SUBSCRIPTION_STARTED`    | Sent when the user purchased a product wether it is the start of a trial or a regular purchase of a consumable product. |
| `RENEWAL_DISABLED`        | Sent when the user deactivates the renewal of a subscription wether it is in trial period or not.                       |
| `RENEWAL_ENABLED`         | Sent when the user reactivates                                                                                          |
| `SUBSCRIPTION_TERMINATED` | Sent when the subscription actually ends                                                                                |
| `SUBSCRIPTION_RENEWED`    | Sent when a subscription renews                                                                                         |
| `TRIAL_STARTED`           | Sent when a trial starts                                                                                                |
| `TRIAL_CONVERTED`         | Sent when a user converts from a free trial to a normal paid-period                                                     |
| `TRIAL_NOT_CONVERTED`     | Sent when a user finishes it's trial period without renewing to a paid-period                                           |

## Associate users and devices to events

{% tabs %}
{% tab title="Swift" %}

```swift
let amplitudeUserId = Amplitude.instance().getUserId()
Purchasely.setAttribute(.amplitudeUserId, value: String(amplitudeUserId))

let amplitudeDeviceId = Amplitude.instance().getDeviceId()
Purchasely.setAttribute(.amplitudeDeviceId, value: String(amplitudeDeviceId))
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Purchasely.setAttribute(
    Attribute.AMPLITUDE_USER_ID,
    Amplitude.getInstance().userId.toString()
)

Purchasely.setAttribute(
    Attribute.AMPLITUDE_DEVICE_ID,
    Amplitude.getInstance().deviceId.toString()
)
```

{% endtab %}

{% tab title="Java" %}

```java
Purchasely.setAttribute(
    Attribute.AMPLITUDE_USER_ID,
    String.valueOf(Amplitude.getInstance().getUserId())
);

Purchasely.setAttribute(
    Attribute.AMPLITUDE_DEVICE_ID,
    String.valueOf(Amplitude.getInstance().getDeviceId())
);
```

{% endtab %}

{% tab title="React Native" %}

```javascript
Purchasely.setAttribute(Attributes.AMPLITUDE_USER_ID, Amplitude.getInstance().getUserId());
Purchasely.setAttribute(Attributes.AMPLITUDE_DEVICE_ID, Amplitude.getInstance().getDeviceId());
```

{% endtab %}

{% tab title="Cordova" %}

```javascript
Purchasely.setAttribute(Purchasely.Attribute.AMPLITUDE_USER_ID, Amplitude.getInstance().getUserId());
Purchasely.setAttribute(Purchasely.Attribute.AMPLITUDE_DEVICE_ID, Amplitude.getInstance().getDeviceId());
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://purchasely.gitbook.io/purchasely/3.4/integrations/amplitude.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
