Skip to content

Instantly share code, notes, and snippets.

@ChiAnTai
Created August 21, 2018 00:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChiAnTai/613334af21145633ccf90ba6f9b3a1bd to your computer and use it in GitHub Desktop.
Save ChiAnTai/613334af21145633ccf90ba6f9b3a1bd to your computer and use it in GitHub Desktop.
RCT_EXPORT_METHOD(sendEcommerceCheckoutStep:(NSString *)trackerId step:(nonnull NSNumber *)step products:(NSArray *)products)
{
id<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:trackerId];
GAIDictionaryBuilder *builder = [GAIDictionaryBuilder createEventWithCategory:@"Ecommerce"
action:@"Checkout"
label:nil
value:nil];
GAIEcommerceProductAction *action = [[GAIEcommerceProductAction alloc] init];
[action setAction:kGAIPACheckout];
[action setCheckoutStep:step];
for(NSDictionary* reactProduct in products) {
GAIEcommerceProduct *product = [[GAIEcommerceProduct alloc] init];
[product setId:reactProduct[@"item_id"]];
[product setName:reactProduct[@"name"]];
[product setPrice:reactProduct[@"price"]];
[product setQuantity:reactProduct[@"qty"]];
[builder addProduct:product];
}
[builder setProductAction:action];
[tracker send:[builder build]];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment