Skip to content

Commit 3d379a3

Browse files
committed
update from master
2 parents 59a1e8e + edced64 commit 3d379a3

23 files changed

+2173
-137
lines changed

CHANGELOG.md

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

3+
* Add `logRevenueV2` and new `Revenue` class to support logging revenue events with properties, and revenue type. See [Readme](https://github.com/amplitude/Amplitude-Javascript#tracking-revenue) for more info.
34
* Add helper method to regenerate a new random deviceId. This can be used to anonymize a user after they log out. Note this is not recommended unless you know what are you doing. See [Readme](https://github.com/amplitude/Amplitude-Javascript#logging-out-and-anonymous-users) for more information.
45

56
### 2.11.0 (April 14, 2016)

README.md

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ This Readme will guide you through using Amplitude's Javascript SDK to track use
1313
<script type="text/javascript">
1414
(function(e,t){var n=e.amplitude||{_q:[]};var r=t.createElement("script");r.type="text/javascript";
1515
r.async=true;r.src="https://d24n15hnbwhuhn.cloudfront.net/libs/amplitude-2.11.0-min.gz.js";
16-
r.onload=function(){e.amplitude.runQueuedFunctions()};var i=t.getElementsByTagName("script")[0];
17-
i.parentNode.insertBefore(r,i);var s=function(){this._q=[];return this};function o(e){
18-
s.prototype[e]=function(){this._q.push([e].concat(Array.prototype.slice.call(arguments,0)));
19-
return this}}var a=["add","append","clearAll","prepend","set","setOnce","unset"];for(var c=0;c<a.length;c++){
20-
o(a[c])}n.Identify=s;var u=["init","logEvent","logRevenue","setUserId","setUserProperties","setOptOut","setVersionName","setDomain","setDeviceId","setGlobalUserProperties","identify","clearUserProperties","regenerateDeviceId"];
21-
function p(e){function t(t){e[t]=function(){e._q.push([t].concat(Array.prototype.slice.call(arguments,0)));
22-
}}for(var n=0;n<u.length;n++){t(u[n])}}p(n);e.amplitude=n})(window,document);
16+
r.onload=function(){e.amplitude.runQueuedFunctions()};var s=t.getElementsByTagName("script")[0];
17+
s.parentNode.insertBefore(r,s);function i(e,t){e.prototype[t]=function(){this._q.push([t].concat(Array.prototype.slice.call(arguments,0)));
18+
return this}}var o=function(){this._q=[];return this};var a=["add","append","clearAll","prepend","set","setOnce","unset"];
19+
for(var u=0;u<a.length;u++){i(o,a[u])}n.Identify=o;var c=function(){this._q=[];return this;
20+
};var p=["setProductId","setQuantity","setPrice","setRevenueType","setEventProperties"];
21+
for(var l=0;l<p.length;l++){i(c,p[l])}n.Revenue=c;var d=["init","logEvent","logRevenue","setUserId","setUserProperties","setOptOut","setVersionName","setDomain","setDeviceId","setGlobalUserProperties","identify","clearUserProperties","logRevenueV2","regenerateDeviceId"];
22+
function v(e){function t(t){e[t]=function(){e._q.push([t].concat(Array.prototype.slice.call(arguments,0)));
23+
}}for(var n=0;n<d.length;n++){t(d[n])}}v(n);e.amplitude=n})(window,document);
2324
2425
amplitude.init("YOUR_API_KEY_HERE");
2526
</script>
@@ -187,15 +188,29 @@ amplitude.clearUserProperties();
187188

188189
# Tracking Revenue #
189190

190-
To track revenue from a user, call
191+
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 eventProperties 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.
191192
193+
Each time a user generates revenue, you create a `Revenue` object and fill out the revenue properties:
192194
```javascript
193-
amplitude.logRevenue(9.99, 1, 'product');
195+
var revenue = new amplitude.Revenue().setProductId('com.company.productId').setPrice(3.99).setQuantity(3);
196+
amplitude.logRevenueV2(revenue);
194197
```
195198
196-
The function takes a unit price, a quantity, and a product identifier. Quantity and product identifier are optional parameters.
199+
`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:
197200
198-
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.
201+
| Name | Type | Description | default |
202+
|--------------------|------------|----------------------------------------------------------------------------------------------------------|---------|
203+
| productId | String | Required: an identifier for the product (we recommend something like the Google Play Store product Id) | null |
204+
| quantity | Integer | Required: the quantity of products purchased. Defaults to 1 if not specified. Revenue = quantity * price | 1 |
205+
| price | Double | Required: the price of the products purchased (can be negative). Revenue = quantity * price | null |
206+
| revenueType | String | Optional: the type of revenue (ex: tax, refund, income) | null |
207+
| eventProperties | Object | Optional: an object of event properties to include in the revenue event | null |
208+
209+
Note: the price can be negative, which might be useful for tracking revenue lost, for example refunds or costs. Also note, you can set event properties on the revenue event just as you would with logEvent by passing in a object of string key value pairs. These event properties, however, will only appear in the Event Segmentation tab, not in the Revenue tab.
210+
211+
### Backwards compatibility ###
212+
213+
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.
199214
200215
# Opting User Out of Logging #
201216

amplitude-segment-snippet.min.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
(function(e,t){var r=e.amplitude||{_q:[]};var n=function(){this._q=[];return this;
2-
};function i(e){n.prototype[e]=function(){this._q.push([e].concat(Array.prototype.slice.call(arguments,0)));
3-
return this}}var o=["add","append","clearAll","prepend","set","setOnce","unset"];for(var s=0;s<o.length;s++){
4-
i(o[s])}r.Identify=n;var a=["init","logEvent","logRevenue","setUserId","setUserProperties","setOptOut","setVersionName","setDomain","setDeviceId","setGlobalUserProperties","identify","clearUserProperties","regenerateDeviceId"];
5-
function c(e){function t(t){e[t]=function(){e._q.push([t].concat(Array.prototype.slice.call(arguments,0)));
6-
}}for(var r=0;r<a.length;r++){t(a[r])}}c(r);e.amplitude=r})(window,document);
1+
(function(e,t){var r=e.amplitude||{_q:[]};function n(e,t){e.prototype[t]=function(){
2+
this._q.push([t].concat(Array.prototype.slice.call(arguments,0)));return this}}var i=function(){
3+
this._q=[];return this};var s=["add","append","clearAll","prepend","set","setOnce","unset"];
4+
for(var o=0;o<s.length;o++){n(i,s[o])}r.Identify=i;var a=function(){this._q=[];return this;
5+
};var c=["setProductId","setQuantity","setPrice","setRevenueType","setEventProperties"];
6+
for(var u=0;u<c.length;u++){n(a,c[u])}r.Revenue=a;var l=["init","logEvent","logRevenue","setUserId","setUserProperties","setOptOut","setVersionName","setDomain","setDeviceId","setGlobalUserProperties","identify","clearUserProperties","logRevenueV2","regenerateDeviceId"];
7+
function p(e){function t(t){e[t]=function(){e._q.push([t].concat(Array.prototype.slice.call(arguments,0)));
8+
}}for(var r=0;r<l.length;r++){t(l[r])}}p(r);e.amplitude=r})(window,document);

amplitude-snippet.min.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
(function(e,t){var n=e.amplitude||{_q:[]};var r=t.createElement("script");r.type="text/javascript";
22
r.async=true;r.src="https://d24n15hnbwhuhn.cloudfront.net/libs/amplitude-2.11.0-min.gz.js";
3-
r.onload=function(){e.amplitude.runQueuedFunctions()};var i=t.getElementsByTagName("script")[0];
4-
i.parentNode.insertBefore(r,i);var s=function(){this._q=[];return this};function o(e){
5-
s.prototype[e]=function(){this._q.push([e].concat(Array.prototype.slice.call(arguments,0)));
6-
return this}}var a=["add","append","clearAll","prepend","set","setOnce","unset"];for(var c=0;c<a.length;c++){
7-
o(a[c])}n.Identify=s;var u=["init","logEvent","logRevenue","setUserId","setUserProperties","setOptOut","setVersionName","setDomain","setDeviceId","setGlobalUserProperties","identify","clearUserProperties","regenerateDeviceId"];
8-
function p(e){function t(t){e[t]=function(){e._q.push([t].concat(Array.prototype.slice.call(arguments,0)));
9-
}}for(var n=0;n<u.length;n++){t(u[n])}}p(n);e.amplitude=n})(window,document);
3+
r.onload=function(){e.amplitude.runQueuedFunctions()};var s=t.getElementsByTagName("script")[0];
4+
s.parentNode.insertBefore(r,s);function i(e,t){e.prototype[t]=function(){this._q.push([t].concat(Array.prototype.slice.call(arguments,0)));
5+
return this}}var o=function(){this._q=[];return this};var a=["add","append","clearAll","prepend","set","setOnce","unset"];
6+
for(var u=0;u<a.length;u++){i(o,a[u])}n.Identify=o;var c=function(){this._q=[];return this;
7+
};var p=["setProductId","setQuantity","setPrice","setRevenueType","setEventProperties"];
8+
for(var l=0;l<p.length;l++){i(c,p[l])}n.Revenue=c;var d=["init","logEvent","logRevenue","setUserId","setUserProperties","setOptOut","setVersionName","setDomain","setDeviceId","setGlobalUserProperties","identify","clearUserProperties","logRevenueV2","regenerateDeviceId"];
9+
function v(e){function t(t){e[t]=function(){e._q.push([t].concat(Array.prototype.slice.call(arguments,0)));
10+
}}for(var n=0;n<d.length;n++){t(d[n])}}v(n);e.amplitude=n})(window,document);

0 commit comments

Comments
 (0)