# Custom events examples for e-commerce

Suggested events for e-commerce, 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" title="Create price attributes before the first send">
Pushwoosh sets an attribute's type from the first value it receives, so a price can end up stored with the wrong type:

* The Web and Android SDKs: if the first price is `1`, the type becomes `integer`, and every later `49.99` is stored as `49`.
* The iOS SDK: it sends numbers as strings, so an attribute first created from iOS becomes `string`.

To avoid this, create price attributes as `decimal (price)` in the Control Panel before the first send. If the attribute already exists, change its type there.
</Aside>

## Product viewed

Fire this event when a user opens a product page. Use it for browse abandonment campaigns and to segment users by the products and categories they view.

Recommended attributes:

* product\_id: String
* product\_category: String
* price: decimal (price)
* source: String

<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("Product viewed", {
    "product_id": "string value",
    "product_category": "string value",
    "price": 49.99,
    "source": "string value"
  });
});
```
</TabItem>

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

let attributes: [String : Any] = [
   "product_id" : "string value",
   "product_category" : "string value",
   "price" : 49.99,
   "source" : "string value"
]
Pushwoosh.configure.postEvent("Product viewed", withAttributes: attributes)
```
</TabItem>

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

NSDictionary *attributes = @{
   @"product_id" : @"string value",
   @"product_category" : @"string value",
   @"price" : @(49.99),
   @"source" : @"string value"
};
[[Pushwoosh configure] postEvent:@"Product viewed" withAttributes:attributes];
```
</TabItem>

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

TagsBundle attributes = new TagsBundle.Builder()
    .putString("product_id", "string value")
    .putString("product_category", "string value")
    .putAll(new JSONObject(Collections.singletonMap("price", 49.99))) // TagsBundle has no decimal setter
    .putString("source", "string value")
    .build();

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

## Product added to cart

Fire this event once a user adds product to their cart to build Abandoned Cart campaigns, set user tags, or analyze the efficiency of your promotions.

Recommended attributes:

* product\_id: String
* price: decimal (price)
* source: String

<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("Product added to cart", {
    "product_id": "string value",
    "price": 49.99,
    "source": "string value"
  });
});
```
</TabItem>

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

let attributes: [String : Any] = [
   "price" : 49.99,
   "product_id" : "string value",
   "source" : "string value"
]
Pushwoosh.configure.postEvent("Product added to cart", withAttributes: attributes)
```
</TabItem>

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

NSDictionary *attributes = @{
   @"price" : @(49.99),
   @"product_id" : @"string value",
   @"source" : @"string value"
};
[[Pushwoosh configure] postEvent:@"Product added to cart" withAttributes:attributes];
```
</TabItem>

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

TagsBundle attributes = new TagsBundle.Builder()
    .putAll(new JSONObject(Collections.singletonMap("price", 49.99))) // TagsBundle has no decimal setter
    .putString("product_id", "string value")
    .putString("source", "string value")
    .build();

InAppManager.getInstance().postEvent("Product added to cart", attributes);
```
</TabItem>
</Tabs>

## Checkout started

Fire this event when a user starts checkout. A user who started checkout but didn't place an order is the audience for a checkout reminder.

Recommended attributes:

* cart\_id: String
* cart\_total: decimal (price)
* currency: String
* items\_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("Checkout started", {
    "cart_id": "string value",
    "cart_total": 49.99,
    "currency": "USD",
    "items_count": 2
  });
});
```
</TabItem>

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

let attributes: [String : Any] = [
   "cart_id" : "string value",
   "cart_total" : 49.99,
   "currency" : "USD",
   "items_count" : 2
]
Pushwoosh.configure.postEvent("Checkout started", withAttributes: attributes)
```
</TabItem>

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

NSDictionary *attributes = @{
   @"cart_id" : @"string value",
   @"cart_total" : @(49.99),
   @"currency" : @"USD",
   @"items_count" : @2
};
[[Pushwoosh configure] postEvent:@"Checkout started" withAttributes:attributes];
```
</TabItem>

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

TagsBundle attributes = new TagsBundle.Builder()
    .putString("cart_id", "string value")
    .putAll(new JSONObject(Collections.singletonMap("cart_total", 49.99))) // TagsBundle has no decimal setter
    .putString("currency", "USD")
    .putInt("items_count", 2)
    .build();

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

## Order placed

Fire this event when a user completes a purchase. Send it for every purchase as your main purchase event, together with Discounted purchase, Product category, or First purchase when they also apply.

Recommended attributes:

* order\_id: String
* \_\_amount: decimal (price)
* \_\_currency: String, a currency code such as `USD`
* product\_id: String
* coupon\_id: String

<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("Order placed", {
    "order_id": "string value",
    "__amount": 49.99,
    "__currency": "USD",
    "product_id": "string value",
    "coupon_id": "string value"
  });
});
```
</TabItem>

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

let attributes: [String : Any] = [
   "order_id" : "string value",
   "__amount" : 49.99,
   "__currency" : "USD",
   "product_id" : "string value",
   "coupon_id" : "string value"
]
Pushwoosh.configure.postEvent("Order placed", withAttributes: attributes)
```
</TabItem>

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

NSDictionary *attributes = @{
   @"order_id" : @"string value",
   @"__amount" : @(49.99),
   @"__currency" : @"USD",
   @"product_id" : @"string value",
   @"coupon_id" : @"string value"
};
[[Pushwoosh configure] postEvent:@"Order placed" withAttributes:attributes];
```
</TabItem>

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

TagsBundle attributes = new TagsBundle.Builder()
    .putString("order_id", "string value")
    .putAll(new JSONObject(Collections.singletonMap("__amount", 49.99))) // TagsBundle has no decimal setter
    .putString("__currency", "USD")
    .putString("product_id", "string value")
    .putString("coupon_id", "string value")
    .build();

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

With the `__amount` and `__currency` attributes, Pushwoosh starts tracking revenue for this event automatically the first time it arrives. See [Conversion events](/product/audience-data-and-segmentation/events/conversion-events/).

<Aside type="caution">
Don't add `__amount` and `__currency` to other events, for example Checkout started or Order refunded. Pushwoosh adds the amount of every event that carries them to revenue, so the same money gets counted twice, and a refund increases revenue instead of reducing it.
</Aside>

## Order refunded

Fire this event when an order is refunded, fully or partially. Use it to exclude these users from post-purchase campaigns or to ask why they returned the order.

Recommended attributes:

* order\_id: String
* refund\_amount: decimal (price)
* currency: String
* reason: String

<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("Order refunded", {
    "order_id": "string value",
    "refund_amount": 49.99,
    "currency": "USD",
    "reason": "string value"
  });
});
```
</TabItem>

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

let attributes: [String : Any] = [
   "order_id" : "string value",
   "refund_amount" : 49.99,
   "currency" : "USD",
   "reason" : "string value"
]
Pushwoosh.configure.postEvent("Order refunded", withAttributes: attributes)
```
</TabItem>

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

NSDictionary *attributes = @{
   @"order_id" : @"string value",
   @"refund_amount" : @(49.99),
   @"currency" : @"USD",
   @"reason" : @"string value"
};
[[Pushwoosh configure] postEvent:@"Order refunded" withAttributes:attributes];
```
</TabItem>

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

TagsBundle attributes = new TagsBundle.Builder()
    .putString("order_id", "string value")
    .putAll(new JSONObject(Collections.singletonMap("refund_amount", 49.99))) // TagsBundle has no decimal setter
    .putString("currency", "USD")
    .putString("reason", "string value")
    .build();

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

## Discounted purchase

Trigger this event once a user purchases any product using a discount coupon.

Recommended attributes:

* product\_id: String
* coupon\_id: String
* price: decimal (price)
* discount: String

<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("Discounted purchase", {
    "product_id": "string value",
    "coupon_id": "string value",
    "price": 49.99,
    "discount": "string value"
  });
});
```
</TabItem>

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

let attributes: [String : Any] = [
   "product_id" : "string value",
   "coupon_id" : "string value",
   "price" : 49.99,
   "discount" : "string value"
]
Pushwoosh.configure.postEvent("Discounted purchase", withAttributes: attributes)
```
</TabItem>

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

NSDictionary *attributes = @{
   @"product_id" : @"string value",
   @"coupon_id" : @"string value",
   @"price" : @(49.99),
   @"discount" : @"string value"
};
[[Pushwoosh configure] postEvent:@"Discounted purchase" withAttributes:attributes];
```
</TabItem>

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

TagsBundle attributes = new TagsBundle.Builder()
    .putString("product_id", "string value")
    .putString("coupon_id", "string value")
    .putAll(new JSONObject(Collections.singletonMap("price", 49.99))) // TagsBundle has no decimal setter
    .putString("discount", "string value")
    .build();

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

## Product page abandoned

Fire this event when a user leaves a product page without a conversion action.

Recommended attributes:

* product\_id: String
* price: decimal (price)
* source: String
* product\_page\_id: String

<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("Product Page abandoned", {
    "product_id": "string value",
    "price": 49.99,
    "source": "string value",
    "product_page_id": "string value"
  });
});
```
</TabItem>

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

let attributes: [String : Any] = [
   "product_id" : "string value",
   "price" : 49.99,
   "source" : "string value",
   "product_page_id" : "string value"
]
Pushwoosh.configure.postEvent("Product Page abandoned", withAttributes: attributes)
```
</TabItem>

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

NSDictionary *attributes = @{
   @"product_id" : @"string value",
   @"price" : @(49.99),
   @"source" : @"string value",
   @"product_page_id" : @"string value"
};
[[Pushwoosh configure] postEvent:@"Product Page abandoned" withAttributes:attributes];
```
</TabItem>

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

TagsBundle attributes = new TagsBundle.Builder()
    .putString("product_id", "string value")
    .putAll(new JSONObject(Collections.singletonMap("price", 49.99))) // TagsBundle has no decimal setter
    .putString("source", "string value")
    .putString("product_page_id", "string value")
    .build();

InAppManager.getInstance().postEvent("Product Page abandoned", attributes);
```
</TabItem>
</Tabs>

## Product added to wishlist

Stay informed of the products that users have saved to their wishlists and create personal offers and promo campaigns.

Recommended attributes:

* product\_id: String
* wishlist\_id: String
* product\_price: decimal (price)
* source: String
* user\_id: String

<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("Product added to wishlist", {
    "product_id": "string value",
    "wishlist_id": "string value",
    "product_price": 49.99,
    "source": "string value",
    "user_id": "string value"
  });
});
```
</TabItem>

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

let attributes: [String : Any] = [
   "product_id" : "string value",
   "wishlist_id" : "string value",
   "product_price" : 49.99,
   "source" : "string value",
   "user_id" : "string value"
]
Pushwoosh.configure.postEvent("Product added to wishlist", withAttributes: attributes)
```
</TabItem>

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

NSDictionary *attributes = @{
   @"product_id" : @"string value",
   @"wishlist_id" : @"string value",
   @"product_price" : @(49.99),
   @"source" : @"string value",
   @"user_id" : @"string value"
};
[[Pushwoosh configure] postEvent:@"Product added to wishlist" withAttributes:attributes];
```
</TabItem>

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

TagsBundle attributes = new TagsBundle.Builder()
    .putString("product_id", "string value")
    .putString("wishlist_id", "string value")
    .putAll(new JSONObject(Collections.singletonMap("product_price", 49.99))) // TagsBundle has no decimal setter
    .putString("source", "string value")
    .putString("user_id", "string value")
    .build();

InAppManager.getInstance().postEvent("Product added to wishlist", attributes);
```
</TabItem>
</Tabs>

## Product removed from wishlist

Fire this event when a user deletes a product from their wishlist.

Recommended attributes:

* user\_id: String
* wishlist\_id: String
* product\_id: String

<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("Product removed from wishlist", {
    "wishlist_id": "string value",
    "user_id": "string value",
    "product_id": "string value"
  });
});
```
</TabItem>

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

let attributes: [String : Any] = [
   "wishlist_id" : "string value",
   "user_id" : "string value",
   "product_id" : "string value"
]
Pushwoosh.configure.postEvent("Product removed from wishlist", withAttributes: attributes)
```
</TabItem>

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

NSDictionary *attributes = @{
   @"wishlist_id" : @"string value",
   @"user_id" : @"string value",
   @"product_id" : @"string value"
};
[[Pushwoosh configure] postEvent:@"Product removed from wishlist" withAttributes:attributes];
```
</TabItem>

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

TagsBundle attributes = new TagsBundle.Builder()
    .putString("wishlist_id", "string value")
    .putString("user_id", "string value")
    .putString("product_id", "string value")
    .build();

InAppManager.getInstance().postEvent("Product removed from wishlist", attributes);
```
</TabItem>
</Tabs>

## Product category

Send this event when a user purchases a product of a specific category.

Recommended attributes:

* product\_id: String
* product\_category: String
* currency: String

<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("Product category", {
    "product_id": "string value",
    "product_category": "string value",
    "currency": "string value"
  });
});
```
</TabItem>

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

let attributes: [String : Any] = [
   "product_id" : "string value",
   "product_category" : "string value",
   "currency" : "string value"
]
Pushwoosh.configure.postEvent("Product category", withAttributes: attributes)
```
</TabItem>

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

NSDictionary *attributes = @{
   @"product_id" : @"string value",
   @"product_category" : @"string value",
   @"currency" : @"string value"
};
[[Pushwoosh configure] postEvent:@"Product category" withAttributes:attributes];
```
</TabItem>

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

TagsBundle attributes = new TagsBundle.Builder()
    .putString("product_id", "string value")
    .putString("product_category", "string value")
    .putString("currency", "string value")
    .build();

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

## First purchase

Trigger this event once a user makes their first purchase.

Recommended attributes:

* product\_id: String,
* category: 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("First purchase", {
    "product_id": "string value",
    "category": "string value",
    "date": new Date()
  });
});
```
</TabItem>

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

let attributes: [String : Any] = [
   "product_id" : "string value",
   "category" : "string value",
   "date" : NSDate()
]
Pushwoosh.configure.postEvent("First purchase", withAttributes: attributes)
```
</TabItem>

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

NSDictionary *attributes = @{
   @"product_id" : @"string value",
   @"category" : @"string value",
   @"date" : [NSDate date]
};
[[Pushwoosh configure] postEvent:@"First purchase" withAttributes:attributes];
```
</TabItem>

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

TagsBundle attributes = new TagsBundle.Builder()
    .putString("product_id", "string value")
    .putString("category", "string value")
    .putDate("date", new Date())
    .build();

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