Skip to content

Commit 9da80e3

Browse files
committed
update readme, only add properties to object if value is not null
1 parent 0480b7d commit 9da80e3

File tree

12 files changed

+61
-44
lines changed

12 files changed

+61
-44
lines changed

README.md

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -193,33 +193,18 @@ var revenue = new amplitude.Revenue().setProductId('com.company.productId').setP
193193
amplitude.logRevenueV2(revenue);
194194
```
195195
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:
196+
`productId` and `price` are required fields. `quantity` defaults to 1 if not specified. Each field has a corresponding `set` method (for example `setProductId`, `setQuantity`, etc). This table describes the different fields available:
197197
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 |
198+
| Name | Type | Description | default |
199+
|--------------------|------------|----------------------------------------------------------------------------------------------------------|---------|
200+
| productId | String | Required: an identifier for the product (we recommend something like the Google Play Store product Id) | null |
201+
| quantity | Integer | Required: the quantity of products purchased. Defaults to 1 if not specified. Revenue = quantity * price | 1 |
202+
| price | Double | Required: the price of the products purchased (can be negative). Revenue = quantity * price | null |
203+
| revenueType | String | Optional: the type of revenue (ex: tax, refund, income) | null |
204+
| revenueProperties | Object | Optional: an object of event properties to include in the revenue event | null |
205205
206206
Note: the price can be negative, which might be useful for tracking revenue lost, for example refunds or costs.
207207
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-
223208
### Backwards compatibility ###
224209
225210
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.

amplitude.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3414,10 +3414,19 @@ Revenue.prototype._isValidRevenue = function _isValidRevenue() {
34143414
*/
34153415
Revenue.prototype._toJSONObject = function _toJSONObject() {
34163416
var obj = type(this._properties) === 'object' ? this._properties : {};
3417-
obj[constants.REVENUE_PRODUCT_ID] = this._productId;
3418-
obj[constants.REVENUE_QUANTITY] = this._quantity;
3419-
obj[constants.REVENUE_PRICE] = this._price;
3420-
obj[constants.REVENUE_REVENUE_TYPE] = this._revenueType;
3417+
3418+
if (this._productId !== null) {
3419+
obj[constants.REVENUE_PRODUCT_ID] = this._productId;
3420+
}
3421+
if (this._quantity !== null) {
3422+
obj[constants.REVENUE_QUANTITY] = this._quantity;
3423+
}
3424+
if (this._price !== null) {
3425+
obj[constants.REVENUE_PRICE] = this._price;
3426+
}
3427+
if (this._revenueType !== null) {
3428+
obj[constants.REVENUE_REVENUE_TYPE] = this._revenueType;
3429+
}
34213430
return obj;
34223431
};
34233432

amplitude.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

documentation/Amplitude.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2483,7 +2483,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Amplitude
24832483
<br class="clear">
24842484

24852485
<footer>
2486-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Mon Apr 18 2016 22:40:49 GMT-0700 (PDT)
2486+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Tue Apr 19 2016 16:37:04 GMT-0700 (PDT)
24872487
</footer>
24882488

24892489
<script> prettyPrint(); </script>

documentation/Identify.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Amplitude
12951295
<br class="clear">
12961296

12971297
<footer>
1298-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Mon Apr 18 2016 22:40:49 GMT-0700 (PDT)
1298+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Tue Apr 19 2016 16:37:04 GMT-0700 (PDT)
12991299
</footer>
13001300

13011301
<script> prettyPrint(); </script>

documentation/Revenue.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Amplitude
965965
<br class="clear">
966966

967967
<footer>
968-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Mon Apr 18 2016 22:40:49 GMT-0700 (PDT)
968+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Tue Apr 19 2016 16:37:04 GMT-0700 (PDT)
969969
</footer>
970970

971971
<script> prettyPrint(); </script>

documentation/amplitude.js.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Amplitude
10921092
<br class="clear">
10931093

10941094
<footer>
1095-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Mon Apr 18 2016 22:40:49 GMT-0700 (PDT)
1095+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Tue Apr 19 2016 16:37:04 GMT-0700 (PDT)
10961096
</footer>
10971097

10981098
<script> prettyPrint(); </script>

documentation/identify.js.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Amplitude
226226
<br class="clear">
227227

228228
<footer>
229-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Mon Apr 18 2016 22:40:49 GMT-0700 (PDT)
229+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Tue Apr 19 2016 16:37:04 GMT-0700 (PDT)
230230
</footer>
231231

232232
<script> prettyPrint(); </script>

documentation/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Amplitude
5656
<br class="clear">
5757

5858
<footer>
59-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Mon Apr 18 2016 22:40:49 GMT-0700 (PDT)
59+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Tue Apr 19 2016 16:37:04 GMT-0700 (PDT)
6060
</footer>
6161

6262
<script> prettyPrint(); </script>

documentation/revenue.js.html

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,19 @@ <h1 class="page-title">Source: revenue.js</h1>
167167
*/
168168
Revenue.prototype._toJSONObject = function _toJSONObject() {
169169
var obj = type(this._properties) === 'object' ? this._properties : {};
170-
obj[constants.REVENUE_PRODUCT_ID] = this._productId;
171-
obj[constants.REVENUE_QUANTITY] = this._quantity;
172-
obj[constants.REVENUE_PRICE] = this._price;
173-
obj[constants.REVENUE_REVENUE_TYPE] = this._revenueType;
170+
171+
if (this._productId !== null) {
172+
obj[constants.REVENUE_PRODUCT_ID] = this._productId;
173+
}
174+
if (this._quantity !== null) {
175+
obj[constants.REVENUE_QUANTITY] = this._quantity;
176+
}
177+
if (this._price !== null) {
178+
obj[constants.REVENUE_PRICE] = this._price;
179+
}
180+
if (this._revenueType !== null) {
181+
obj[constants.REVENUE_REVENUE_TYPE] = this._revenueType;
182+
}
174183
return obj;
175184
};
176185

@@ -191,7 +200,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Amplitude
191200
<br class="clear">
192201

193202
<footer>
194-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Mon Apr 18 2016 22:40:49 GMT-0700 (PDT)
203+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Tue Apr 19 2016 16:37:04 GMT-0700 (PDT)
195204
</footer>
196205

197206
<script> prettyPrint(); </script>

0 commit comments

Comments
 (0)