Skip to content

Commit 1274dc1

Browse files
committed
added logRevenueV2, documentation
1 parent b1e0b4c commit 1274dc1

File tree

14 files changed

+585
-64
lines changed

14 files changed

+585
-64
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## Unreleased
22

3+
* Add `logRevenueV2` and new `Revenue` class to support logging revenue events with properties, revenue type, and verified. See [Readme](https://github.com/amplitude/Amplitude-Javascript#tracking-revenue) for more info.
4+
35
### 2.11.0 (April 14, 2016)
46

57
* Add tracking of each user's initial_utm parameters (which is captured as a set once operation). Utm parameters are now sent only once per user session.

README.md

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,44 @@ amplitude.clearUserProperties();
185185

186186
# Tracking Revenue #
187187

188-
To track revenue from a user, call
188+
The preferred method of tracking revenue for a user now is to use `logRevenueV2()` in conjunction with the provided `Revenue` interface. `Revenue` instances will store each revenue transaction and allow you to define several special revenue properties (such as revenueType, productId, etc) that are used in Amplitude dashboard's Revenue tab. You can now also add event properties to the revenue event, via the revenueProperties field. These `Revenue` instance objects are then passed into `logRevenueV2` to send as revenue events to Amplitude servers. This allows us to automatically display data relevant to revenue on the Amplitude website, including average revenue per daily active user (ARPDAU), 1, 7, 14, 30, 60, and 90 day revenue, lifetime value (LTV) estimates, and revenue by advertising campaign cohort and daily/weekly/monthly cohorts.
189189
190+
Each time a user generates revenue, you create a `Revenue` object and fill out the revenue properties:
190191
```javascript
191-
amplitude.logRevenue(9.99, 1, 'product');
192+
var revenue = new amplitude.Revenue().setProductId('com.company.productId'"').setPrice(3.99).setQuantity(3);
193+
amplitude.logRevenueV2(revenue);
192194
```
193195

194-
The function takes a unit price, a quantity, and a product identifier. Quantity and product identifier are optional parameters.
196+
`productId`, `price`, and `quantity` are required fields. Each field has a corresponding `set` method (for example `setProductId`, `setQuantity`, etc), as well as a corresponding event property key (see below for how to send revenue properties in event properties). This table describes the different fields available:
195197

196-
This allows us to automatically display data relevant to revenue on the Amplitude website, including average revenue per daily active user (ARPDAU), 7, 30, and 90 day revenue, lifetime value (LTV) estimates, and revenue by advertising campaign cohort and daily/weekly/monthly cohorts.
198+
| Name | Type | Description | default | property key |
199+
|--------------------|------------|----------------------------------------------------------------------------------------------------------|---------|--------------|
200+
| productId | String | Required: an identifier for the product (we recommend something like the Google Play Store product Id) | null | $productId |
201+
| quantity | Integer | Required: the quantity of products purchased. Defaults to 1 if not specified. Revenue = quantity * price | 1 | $quantity |
202+
| price | Double | Required: the price of the products purchased (can be negative). Revenue = quantity * price | null | $price |
203+
| revenueType | String | Optional: the type of revenue (ex: tax, refund, income) | null | $revenueType |
204+
| revenueProperties | Object | Optional: an object of event properties to include in the revenue event | null | n/a |
205+
206+
Note: the price can be negative, which might be useful for tracking revenue lost, for example refunds or costs.
207+
208+
### Sending Revenue as Event Properties ###
209+
210+
Instead of sending revenue through Amplitude's special revenue event, you can send revenue properties as event properties on any event you log. The `property key` column in the above table denotes the string key to use when declaring the event property. Note: you still need to set a productId and a price. If quantity is not set, it is assumed to be 1:
211+
212+
```java
213+
var properties = {
214+
'description': 'some event description',
215+
'color': 'green',
216+
'$productId': 'productIdentifier',
217+
'$price': 10.99,
218+
'$quantity': 2
219+
};
220+
amplitude.logEvent('Completed purchase', properties);
221+
```
222+
223+
### Backwards compatibility ###
224+
225+
The existing `logRevenue` methods still work but are deprecated. Fields such as `revenueType` will be missing from events logged with the old methods, so Revenue segmentation on those events will be limited in Amplitude dashboards.
197226

198227
# Opting User Out of Logging #
199228

0 commit comments

Comments
 (0)