Amplitude-JavaScript icon indicating copy to clipboard operation
Amplitude-JavaScript copied to clipboard

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

Open GusRuss89 opened this issue 3 years ago • 3 comments

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

GusRuss89 avatar Jul 09 '21 10:07 GusRuss89

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

dantetam avatar Jul 13 '21 14:07 dantetam

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

GusRuss89 avatar Jul 13 '21 22:07 GusRuss89

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

dantetam avatar Jul 14 '21 02:07 dantetam