# Custom events examples for subscription management

Suggested events for subscription management, each with recommended attributes and code samples. To send an event from your app, see [Send custom events from your app](/developer/guides/audience-and-segmentation/events/custom-events-examples/). To use these events in segments and journeys, see [industry playbooks](/tutorials/industry-playbooks/).

<Aside type="caution">
Create `price` as `decimal (price)` in the Control Panel before the first send. Otherwise a first value of `1` sent from the Web or Android SDK sets its type to `integer`, and every later `49.99` is stored as `49`. The iOS SDK sends numbers as strings, so a `price` first created from iOS becomes `string`. If the attribute already exists as `integer`, change its type in the Control Panel.
</Aside>

## Paid subscription purchase

Send this event when a user has bought a paid subscription plan.

Recommended attributes:

* subscription\_plan\_name: String
* price: decimal (price)
* currency:String
* expiry\_date:Date

<Tabs>
<TabItem label="JavaScript">
```javascript
// To use with Web Push SDK, you can integrate this code:

const Pushwoosh = window.Pushwoosh || [];
Pushwoosh.push(function(api) {
    api.postEvent("Paid subscription purchase", {
    "subscription_plan_name": "string value",
    "price": 49.99,
    "currency": "string value",
    "expiry_date": new Date()
  });
});
```
</TabItem>

<TabItem label="Swift">
```swift
// To use with iOS SDK, you can integrate this code:

let attributes: [String : Any] = [
   "subscription_plan_name" : "string value",
   "price" : 49.99,
   "currency" : "string value",
   "expiry_date" : NSDate()
]
Pushwoosh.configure.postEvent("Paid subscription purchase", withAttributes: attributes)
```
</TabItem>

<TabItem label="Objective-C">
```objective-c
// To use with iOS SDK, you can integrate this code:

NSDictionary *attributes = @{
   @"subscription_plan_name" : @"string value",
   @"price" : @(49.99),
   @"currency" : @"string value",
   @"expiry_date" : [NSDate date]
};
[[Pushwoosh configure] postEvent:@"Paid subscription purchase" withAttributes:attributes];
```
</TabItem>

<TabItem label="Java">
```java
// To use with Android SDK, you can integrate this code:

TagsBundle attributes = new TagsBundle.Builder()
    .putString("subscription_plan_name", "string value")
    .putAll(new JSONObject(Collections.singletonMap("price", 49.99))) // TagsBundle has no decimal setter
    .putString("currency", "string value")
    .putDate("expiry_date", new Date())
    .build();

InAppManager.getInstance().postEvent("Paid subscription purchase", attributes);
```
</TabItem>
</Tabs>

## Subscription renewal

Trigger this event once a user renews their subscription plan.

Recommended attributes:

* subscription\_plan\_name: String
* price: decimal (price)
* currency: String
* renewal\_count: Integer

<Tabs>
<TabItem label="JavaScript">
```javascript
// To use with Web Push SDK, you can integrate this code:

const Pushwoosh = window.Pushwoosh || [];
Pushwoosh.push(function(api) {
    api.postEvent("Subscription renewal", {
    "subscription_plan_name": "string value",
    "price": 49.99,
    "currency": "string value",
    "renewal_count": 1
  });
});
```
</TabItem>

<TabItem label="Swift">
```swift
// To use with iOS SDK, you can integrate this code:

let attributes: [String : Any] = [
   "subscription_plan_name" : "string value",
   "price" : 49.99,
   "currency" : "string value",
   "renewal_count" : 1
]
Pushwoosh.configure.postEvent("Subscription renewal", withAttributes: attributes)
```
</TabItem>

<TabItem label="Objective-C">
```objective-c
// To use with iOS SDK, you can integrate this code:

NSDictionary *attributes = @{
   @"subscription_plan_name" : @"string value",
   @"price" : @(49.99),
   @"currency" : @"string value",
   @"renewal_count" : @(1)
};
[[Pushwoosh configure] postEvent:@"Subscription renewal" withAttributes:attributes];
```
</TabItem>

<TabItem label="Java">
```java
// To use with Android SDK, you can integrate this code:

TagsBundle attributes = new TagsBundle.Builder()
    .putString("subscription_plan_name", "string value")
    .putAll(new JSONObject(Collections.singletonMap("price", 49.99))) // TagsBundle has no decimal setter
    .putString("currency", "string value")
    .putInt("renewal_count", 1)
    .build();

InAppManager.getInstance().postEvent("Subscription renewal", attributes);
```
</TabItem>
</Tabs>

## Free trial started

Trigger this event when a user chooses to start a free trial before getting a subscription.

Recommended attributes:

* free\_trial\_name: String
* expiry\_date: Date

<Tabs>
<TabItem label="JavaScript">
```javascript
// To use with Web Push SDK, you can integrate this code:

const Pushwoosh = window.Pushwoosh || [];
Pushwoosh.push(function(api) {
    api.postEvent("Free trial started", {
    "free_trial_name": "string value",
    "expiry_date": new Date()
  });
});
```
</TabItem>

<TabItem label="Swift">
```swift
// To use with iOS SDK, you can integrate this code:

let attributes: [String : Any] = [
   "free_trial_name" : "string value",
   "expiry_date" : NSDate()
]
Pushwoosh.configure.postEvent("Free trial started", withAttributes: attributes)
```
</TabItem>

<TabItem label="Objective-C">
```objective-c
// To use with iOS SDK, you can integrate this code:

NSDictionary *attributes = @{
   @"free_trial_name" : @"string value",
   @"expiry_date" : [NSDate date]
};
[[Pushwoosh configure] postEvent:@"Free trial started" withAttributes:attributes];
```
</TabItem>

<TabItem label="Java">
```java
// To use with Android SDK, you can integrate this code:

TagsBundle attributes = new TagsBundle.Builder()
    .putString("free_trial_name", "string value")
    .putDate("expiry_date", new Date())
    .build();

InAppManager.getInstance().postEvent("Free trial started", attributes);
```
</TabItem>
</Tabs>

## Subscription canceled

Use this event to track in-app subscription cancelations.

<Tabs>
<TabItem label="JavaScript">
```javascript
// To use with Web Push SDK, you can integrate this code:

const Pushwoosh = window.Pushwoosh || [];
Pushwoosh.push(function(api) {
    api.postEvent("Subscription canceled", {});
});
```
</TabItem>

<TabItem label="Swift">
```swift
// To use with iOS SDK, you can integrate this code:

Pushwoosh.configure.postEvent("Subscription canceled", withAttributes: nil)
```
</TabItem>

<TabItem label="Objective-C">
```objective-c
// To use with iOS SDK, you can integrate this code:

[[Pushwoosh configure] postEvent:@"Subscription canceled" withAttributes:@{}];
```
</TabItem>

<TabItem label="Java">
```java
// To use with Android SDK, you can integrate this code:

InAppManager.getInstance().postEvent("Subscription canceled");
```
</TabItem>
</Tabs>

## Conversion from Free to Paid

Trigger this event once a user converts from using your app for free to a paid subscription plan.

Recommended attributes:

* subscription\_plan\_name: String
* price: decimal (price)
* currency: String
* date: Date

<Tabs>
<TabItem label="JavaScript">
```javascript
// To use with Web Push SDK, you can integrate this code:

const Pushwoosh = window.Pushwoosh || [];
Pushwoosh.push(function(api) {
    api.postEvent("Conversion from Free to Paid", {
    "subscription_plan_name": "string value",
    "price": 49.99,
    "currency": "string value",
    "date": new Date()
  });
});
```
</TabItem>

<TabItem label="Swift">
```swift
// To use with iOS SDK, you can integrate this code:

let attributes: [String : Any] = [
   "plan_name" : "string value",
   "price" : 49.99,
   "currency" : "string value",
   "date" : NSDate()
]
Pushwoosh.configure.postEvent("Conversion from Free to Paid", withAttributes: attributes)
```
</TabItem>

<TabItem label="Objective-C">
```objective-c
// To use with iOS SDK, you can integrate this code:

NSDictionary *attributes = @{
   @"subscription_plan_name" : @"string value",
   @"price" : @(49.99),
   @"currency" : @"string value",
   @"date" : [NSDate date]
};
[[Pushwoosh configure] postEvent:@"Conversion from Free to Paid" withAttributes:attributes];
```
</TabItem>

<TabItem label="Java">
```java
// To use with Android SDK, you can integrate this code:

TagsBundle attributes = new TagsBundle.Builder()
    .putString("subscription_plan_name", "string value")
    .putAll(new JSONObject(Collections.singletonMap("price", 49.99))) // TagsBundle has no decimal setter
    .putString("currency", "string value")
    .putDate("date", new Date())
    .build();

InAppManager.getInstance().postEvent("Conversion from Free to Paid", attributes);
```
</TabItem>
</Tabs>