This guide assumes that you have setup the client as we have in the Setup instructions, and have initialized this to the
client
variable.Grab details on the feature usage
You will need to ensure you have details on both:- The user who has used the feature
- The feature which the user has used
id
in Kana for both Objects.
If neither the user nor feature exist yet in Kana, then you should create these first:
Create Users
Create Features
We will work on the assumption that you have pulled the following user and have all the following details to hand:
Ruby
Send the request to Kana
Now we can make the request to Kana in order to record a user’s usage of a particular feature. We do this through the createusageevent mutation. This requires three arguments:-
userId
- theid
of the User -
featureId
- theid
if the Feature -
delta
- the amount of the feature that’s been used as an Integer.
What format should the id arguments both be in?We expect these
id
arguments to be String’s - as this matches the id
scalar type on the User object and Feature object respectively. If any other field type is used, an error will occur telling you we can’t accept any field type except String.Ruby
Ruby
Make sure that this request is sent to Kana only upon the feature being
successfully used, when no more errors could occur preventing usage. This
will prevent discrepancies whereby feature usage has been recorded to Kana
despite the feature not actually having been used (ie. due to errors, etc).
Ruby
Congratulations 🎉 You’ve now successfully recorded a feature’s usage.We will return
true
if the usage event was successful. Feel free to use the response you get back to log the call, or raise any errors/retry the call if the request is not successful or returns false
in the response.