-
Notifications
You must be signed in to change notification settings - Fork 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
Cleans up revenue logic #40
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,62 +98,46 @@ - (void)trackRevenue:(NSDictionary *)properties andRevenueOrTotal:(NSNumber *)re | |
// Use logRevenueV2 with revenue properties. | ||
if ([(NSNumber *)[self.settings objectForKey:@"useLogRevenueV2"] boolValue]) { | ||
[self trackLogRevenueV2:properties andRevenueOrTotal:revenueOrTotal]; | ||
} else { | ||
// fallback to logRevenue v1 | ||
id productId = [properties objectForKey:@"productId"] ?: [properties objectForKey:@"product_id"]; | ||
if (!productId || ![productId isKindOfClass:[NSString class]]) { | ||
productId = nil; | ||
} | ||
id quantity = [properties objectForKey:@"quantity"]; | ||
if (!quantity || ![quantity isKindOfClass:[NSNumber class]]) { | ||
quantity = [NSNumber numberWithInt:1]; | ||
} | ||
id receipt = [properties objectForKey:@"receipt"]; | ||
if (!receipt || ![receipt isKindOfClass:[NSString class]]) { | ||
receipt = nil; | ||
} | ||
[self.amplitude logRevenue:productId | ||
quantity:[quantity integerValue] | ||
price:revenueOrTotal | ||
receipt:receipt]; | ||
SEGLog(@"[Amplitude logRevenue:%@ quantity:%d price:%@ receipt:%@];", productId, [quantity integerValue], revenueOrTotal, receipt); | ||
return; | ||
} | ||
|
||
// fallback to logRevenue v1 | ||
NSString *productId = [properties objectForKey:@"productId"] ?: [properties objectForKey:@"product_id"] ?: nil; | ||
NSNumber *quantity = [properties objectForKey:@"quantity"] ?: [NSNumber numberWithInt:1]; | ||
id receipt = [properties objectForKey:@"receipt"] ?: nil; | ||
[self.amplitude logRevenue:productId | ||
quantity:[quantity integerValue] | ||
price:revenueOrTotal | ||
receipt:receipt]; | ||
SEGLog(@"[Amplitude logRevenue:%@ quantity:%d price:%@ receipt:%@];", productId, [quantity integerValue], revenueOrTotal, receipt); | ||
} | ||
|
||
- (void)trackLogRevenueV2:(NSDictionary *)properties andRevenueOrTotal:(NSNumber *)revenueOrTotal | ||
{ | ||
id price = [properties objectForKey:@"price"]; | ||
id quantity = [properties objectForKey:@"quantity"]; | ||
|
||
// if no price fallback to using revenue | ||
if (!price || ![price isKindOfClass:[NSNumber class]]) { | ||
price = revenueOrTotal; | ||
quantity = [NSNumber numberWithInt:1]; | ||
} else if (!quantity || ![quantity isKindOfClass:[NSNumber class]]) { | ||
quantity = [NSNumber numberWithInt:1]; | ||
} | ||
|
||
NSNumber *price = [properties objectForKey:@"price"] ?: revenueOrTotal; | ||
NSNumber *quantity = [properties objectForKey:@"quantity"] ?: [NSNumber numberWithInt:1]; | ||
[[self.amprevenue setPrice:price] setQuantity:[quantity integerValue]]; | ||
SEGLog(@"[[AMPRevenue revenue] setPrice:%@] setQuantity: %d];", price, [quantity integerValue]); | ||
|
||
id productId = [properties objectForKey:@"productId"] ?: [properties objectForKey:@"product_id"]; | ||
if (productId && [productId isKindOfClass:[NSString class]] && ![productId isEqualToString:@""]) { | ||
NSString *productId = [properties objectForKey:@"productId"] ?: [properties objectForKey:@"product_id"]; | ||
if (productId && ![productId isEqualToString:@""]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is gonna crash if |
||
[self.amprevenue setProductIdentifier:productId]; | ||
SEGLog(@"[[AMPRevenue revenue] setProductIdentifier:%@];", productId); | ||
} | ||
|
||
//Receipt is meant to be of type NSData | ||
// Amplitude throws a warning that receipt is meant to be of type NSData. Previously, Segment checked for only type NSString. For backwards capability, removed the check | ||
id receipt = [properties objectForKey:@"receipt"]; | ||
if (receipt && [receipt isKindOfClass:[NSString class]] && ![receipt isEqualToString:@""]) { | ||
if (receipt) { | ||
[self.amprevenue setReceipt:receipt]; | ||
SEGLog(@"[[AMPRevenue revenue] setReceipt:%@];", receipt); | ||
} | ||
id revenueType = [properties objectForKey:@"revenueType"] ?: [properties objectForKey:@"revenue_type"]; | ||
if (revenueType && [revenueType isKindOfClass:[NSString class]] && ![revenueType isEqualToString:@""]) { | ||
|
||
NSString *revenueType = [properties objectForKey:@"revenueType"] ?: [properties objectForKey:@"revenue_type"]; | ||
if (revenueType && ![revenueType isEqualToString:@""]) { | ||
[self.amprevenue setRevenueType:revenueType]; | ||
SEGLog(@"[AMPRevenue revenue] setRevenueType:%@];", revenueType); | ||
} | ||
NSLog(@"Price : %@, Quantity : %@", price, quantity); | ||
|
||
[self.amplitude logRevenueV2:self.amprevenue]; | ||
SEGLog(@"[Amplitude logRevenueV2:%@];", self.amprevenue); | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You could use the shorthand
properties[@"price"]
syntax here