-
Notifications
You must be signed in to change notification settings - Fork 45
Adds functionality to increment traits if set #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
e26a198
to
c1da7b9
Compare
|
||
- (void)incrementTrait:(NSString *)trait andValue:(NSString *)value | ||
{ | ||
NSArray *increments = [self.settings objectForKey:@"traitsToIncrement"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The long form and short form usage seems to be inconsistent, we're using both for the changes in this PR - can we stick to one (preferably short form)?
- (void)incrementTrait:(NSString *)trait andValue:(NSString *)value | ||
{ | ||
NSArray *increments = [self.settings objectForKey:@"traitsToIncrement"]; | ||
for (NSString *increment in increments) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems inefficient. The runtime is O(n*m) where n = size of payload.traits
and m = size of settings.traitsToIncrement
.
You should remove the case insensitivity and we can cut the runtime to O(n).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be faster and run in o(n). Looks good otherwise.
693f878
to
ee1b692
Compare
Updates so that for each trait passed in |
[self.amplitude identify:[self.identify set:trait value:value]]; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't we have to remove incremented traits from the traits object? From Amplitude's docs: "Note: If a user property is used in multiple operations on the same Identify object, then only the first operation will be saved and the rest will be ignored. " setUserProperties
isn't called on an Identify object, so I'd expect that traits set via this method would override any traits already incremented on the Identify object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clarification from Amplitude's docs: "You may use setUserProperties shorthand to set multiple user properties at once. This method is simply a wrapper around Identify.set and identify." That said, calling setUserProperties
creates its own instance of the Identify class in Android.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I don't call setUserProperties
if settings has values in traitsToIncrement
. Instead it moves into the incrementTrait block and uses set
. Yup, setUserProperties
is just a wrapper around the logic of using set
on AMPIdentify.
Supports Amplitude's
add
functionality. Will add a new settingtraitsToIncrement
to UI, which will accept an array of traits (of type NSString) to check inidentify.traits
. If the trait is present, it will increment the trait given the value passed in.This will increment a user property by some numerical value. If the user property does not have a value set yet, it will be initialized to 0 before being incremented.