amplitude / Amplitude-JavaScript

JavaScript SDK for Amplitude
MIT License
315 stars 133 forks source link

How do I set $revenue on revenue events with the SDK? #411

Open GusRuss89 opened 3 years ago

GusRuss89 commented 3 years ago

Both the LTV Guide and the Tracking Revenue guide say that you must set $revenue on revenue events in order to track LTV.

The revenue interface in the JavaScript SDK doesn't provide a way to set that, and when I inspect the raw events from the Amplitude browser extension, I don't see any $revenue property either. The event properties look like this:

"event_properties": {
    "productId": "Credits",
    "value": 2.99,
    "hasCoupon": false,
    "$productId": "Credits",
    "$quantity": 1,
    "$price": 2.99
  },

So how can I set $revenue? Or are the docs incorrect in saying I need to set that property?

Thanks, Angus

dantetam commented 3 years ago

Hello Angus @GusRuss89 ,

The help center has generic guides that do not rely on one individual language. Please take a look at the JavaScript guide for tracking revenue. Implementations in different languages vary wildly. Let us know if you have any more concerns about the Revenue API.

Dante

GusRuss89 commented 3 years ago

Hi @dantetam

Thanks for the response. I thought it might be the case that the JS SDK adds that property under the hood, but from what I can see in the raw event properties that get sent to Amplitude, there is no $revenue property.

So does the JS SDK do it correctly even though it doesn't add this property? Or is there no way to properly track LTV using the JS SDK? Or perhaps I'm supposed to set $revenue using Revenue.prototype.setEventProperties()?

Either way it seems that the two documentation pages I linked should be updated, because they both explicitly say that $revenue must be set on the event.

Thanks, Angus

dantetam commented 3 years ago

Hello Angus,

Yeah, you are right to notice there are discrepancies between API implementation across different languages, as well as discrepancies between the help center pages vs the developer docs. Regarding the documentation, they are meant to be two separate sets, for two different audiences. They are also maintained by two different teams. This repo and the engineering is monitored by us, the SDK engineering team. We'll try and align the documentation better.

Yes, to answer your question, the JS SDK should track LTV properly. From the documentation I sent:

The preferred method of tracking revenue for a user 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', 'productIdentifier', etc.) that are used in Amplitude's Event Segmentation and Revenue LTV charts.

I assume you are looking for this LTV chart analytics feature on the Amplitude website.

CC: @jooohhn @ajhorst

Dante