Format files with Spacecommander. (#24)

This commit is contained in:
Ladan Nasserian
2018-04-02 15:33:24 -07:00
committed by GitHub
parent 14eb8ac16a
commit c1d046a40b
11 changed files with 468 additions and 450 deletions

1
.gitignore vendored
View File

@@ -31,3 +31,4 @@ Carthage
# `pod install` in .travis.yml
#
Pods/
.clang-format

View File

@@ -8,6 +8,7 @@
@import UIKit;
@interface SEGAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;

View File

@@ -10,15 +10,16 @@
#import <Analytics/SEGAnalytics.h>
#import <Segment-Firebase/SEGFirebaseIntegrationFactory.h>
@implementation SEGAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
SEGAnalyticsConfiguration *configuration = [SEGAnalyticsConfiguration configurationWithWriteKey:@"WRITE_KEY_HERE"];
configuration.trackApplicationLifecycleEvents = YES; // Enable this to record certain application events automatically!
configuration.recordScreenViews = YES; // Enable this to record screen views automatically!
configuration.flushAt = 1; // Flush events to Segment every 1 event
configuration.trackApplicationLifecycleEvents = YES; // Enable this to record certain application events automatically!
configuration.recordScreenViews = YES; // Enable this to record screen views automatically!
configuration.flushAt = 1; // Flush events to Segment every 1 event
[configuration use:[SEGFirebaseIntegrationFactory instance]]; // Use Firebase
[SEGAnalytics setupWithConfiguration:configuration];
[SEGAnalytics debug:YES];

View File

@@ -8,6 +8,7 @@
@import UIKit;
@interface SEGViewController : UIViewController
@end

View File

@@ -9,22 +9,27 @@
#import "SEGViewController.h"
#import <Analytics/SEGAnalytics.h>
@interface SEGViewController ()
@end
@implementation SEGViewController
- (IBAction)buttonTouch:(id)sender {
- (IBAction)buttonTouch:(id)sender
{
[[SEGAnalytics sharedAnalytics] track:@"order Completed" properties:@{
@"currency": @"USD",
@"total": @"10.20"}];
@"currency" : @"USD",
@"total" : @"10.20"
}];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[[SEGAnalytics sharedAnalytics] identify:@"123abc" traits:@{@"name":@"fred", @"gender":@"male"}];
// Do any additional setup after loading the view, typically from a nib.
[[SEGAnalytics sharedAnalytics] identify:@"123abc" traits:@{ @"name" : @"fred",
@"gender" : @"male" }];
}
- (void)didReceiveMemoryWarning

View File

@@ -9,9 +9,10 @@
@import UIKit;
#import "SEGAppDelegate.h"
int main(int argc, char * argv[])
int main(int argc, char *argv[])
{
@autoreleasepool {
@autoreleasepool
{
return UIApplicationMain(argc, argv, nil, NSStringFromClass([SEGAppDelegate class]));
}
}

View File

@@ -8,494 +8,501 @@
// https://github.com/Specta/Specta
SpecBegin(InitialSpecs)
SpecBegin(InitialSpecs);
describe(@"Firebase Integration", ^{
__block id mockFirebase;
__block SEGFirebaseIntegration *integration;
beforeEach(^{
mockFirebase = mockClass([FIRAnalytics class]);
integration = [[SEGFirebaseIntegration alloc] initWithSettings:@{} andFirebase:mockFirebase];
});
it(@"identify with no traits", ^{
SEGIdentifyPayload *payload = [[SEGIdentifyPayload alloc] initWithUserId:@"1111" anonymousId:nil traits:@{} context:@{} integrations:@{}];
[integration identify:payload];
[verify(mockFirebase) setUserID:@"1111"];
});
it(@"identify with traits", ^{
SEGIdentifyPayload *payload = [[SEGIdentifyPayload alloc] initWithUserId:@"7891" anonymousId:nil traits:@{
@"name":@"Jerry Seinfield",
@"gender":@"male",
@"emotion":@"confused",
@"age" :@47
} context:@{} integrations:@{}];
@"name" : @"Jerry Seinfield",
@"gender" : @"male",
@"emotion" : @"confused",
@"age" : @47
} context:@{}
integrations:@{}];
[integration identify:payload];
[verify(mockFirebase) setUserID:@"7891"];
[verify(mockFirebase) setUserPropertyString:@"Jerry Seinfield" forName: @"name"];
[verify(mockFirebase) setUserPropertyString:@"male" forName: @"gender"];
[verify(mockFirebase) setUserPropertyString:@"confused" forName: @"emotion"];
[verify(mockFirebase) setUserPropertyString:@"47" forName: @"age"];
[verify(mockFirebase) setUserPropertyString:@"Jerry Seinfield" forName:@"name"];
[verify(mockFirebase) setUserPropertyString:@"male" forName:@"gender"];
[verify(mockFirebase) setUserPropertyString:@"confused" forName:@"emotion"];
[verify(mockFirebase) setUserPropertyString:@"47" forName:@"age"];
});
it(@"track with no props", ^{
SEGTrackPayload *payload = [[SEGTrackPayload alloc] initWithEvent:@"Email Sent" properties:@{} context:@{} integrations:@{}];
[integration track:payload];
[verify(mockFirebase) logEventWithName:@"Email_Sent" parameters:@{}];
});
it(@"track with props", ^{
SEGTrackPayload *payload = [[SEGTrackPayload alloc] initWithEvent:@"Starship Ordered"
properties:@{
@"Starship Type": @"Death Star"
}
context:@{}
integrations:@{}];
properties:@{
@"Starship Type" : @"Death Star"
}
context:@{}
integrations:@{}];
[integration track:payload];
[verify(mockFirebase) logEventWithName:@"Starship_Ordered" parameters:@{
@"Starship_Type": @"Death Star"}];
@"Starship_Type" : @"Death Star"
}];
});
it(@"track Order Completed", ^{
SEGTrackPayload *payload = [[SEGTrackPayload alloc] initWithEvent:@"Order Completed" properties:@{
@"checkout_id":@"9bcf000000000000",
@"order_id":@"50314b8e",
@"affiliation":@"App Store",
@"total":@30.45,
@"shipping":@5.05,
@"tax":@1.20,
@"currency":@"USD",
@"category":@"Games",
@"revenue": @8,
@"products":@{
@"product_id":@"2013294",
@"category":@"Games",
@"name":@"Monopoly: 3rd Edition",
@"brand":@"Hasbros",
@"price":@"21.99",
@"quantity":@"1"
}
}
context:@{} integrations:@{}];
@"checkout_id" : @"9bcf000000000000",
@"order_id" : @"50314b8e",
@"affiliation" : @"App Store",
@"total" : @30.45,
@"shipping" : @5.05,
@"tax" : @1.20,
@"currency" : @"USD",
@"category" : @"Games",
@"revenue" : @8,
@"products" : @{
@"product_id" : @"2013294",
@"category" : @"Games",
@"name" : @"Monopoly: 3rd Edition",
@"brand" : @"Hasbros",
@"price" : @"21.99",
@"quantity" : @"1"
}
}
context:@{}
integrations:@{}];
[integration track:payload];
// TODO: look into how to handle mapping Firebase reserved params to each products
[verify(mockFirebase) logEventWithName:@"ecommerce_purchase" parameters:@{
@"checkout_id":@"9bcf000000000000",
@"transaction_id":@"50314b8e",
@"affiliation":@"App Store",
@"value":@30.45,
@"shipping":@5.05,
@"tax":@1.20,
@"currency":@"USD",
@"item_category":@"Games",
@"products":@{
@"product_id":@"2013294",
@"category":@"Games",
@"name":@"Monopoly: 3rd Edition",
@"brand":@"Hasbros",
@"price":@"21.99",
@"quantity":@"1"
}
}];
@"checkout_id" : @"9bcf000000000000",
@"transaction_id" : @"50314b8e",
@"affiliation" : @"App Store",
@"value" : @30.45,
@"shipping" : @5.05,
@"tax" : @1.20,
@"currency" : @"USD",
@"item_category" : @"Games",
@"products" : @{
@"product_id" : @"2013294",
@"category" : @"Games",
@"name" : @"Monopoly: 3rd Edition",
@"brand" : @"Hasbros",
@"price" : @"21.99",
@"quantity" : @"1"
}
}];
});
it(@"track Product Clicked", ^{
SEGTrackPayload *payload = [[SEGTrackPayload alloc] initWithEvent:@"Product Clicked"
properties:@{
@"product_id": @"507f1f77bcf86cd799439011",
@"sku":@"G-32",
@"category":@"Games",
@"name":@"Monopoly: 3rd Edition",
@"brand":@"Hasbro",
@"variant":@"200 pieces",
@"price":@18.99,
@"quantity":@1,
@"coupon":@"MAYDEALS",
@"position":@3,
@"url":@"https://www.company.com/product/path",
@"image_url":@"https://www.company.com/product/path.jpg"
}
context:@{}
integrations:@{}];
properties:@{
@"product_id" : @"507f1f77bcf86cd799439011",
@"sku" : @"G-32",
@"category" : @"Games",
@"name" : @"Monopoly: 3rd Edition",
@"brand" : @"Hasbro",
@"variant" : @"200 pieces",
@"price" : @18.99,
@"quantity" : @1,
@"coupon" : @"MAYDEALS",
@"position" : @3,
@"url" : @"https://www.company.com/product/path",
@"image_url" : @"https://www.company.com/product/path.jpg"
}
context:@{}
integrations:@{}];
[integration track:payload];
[verify(mockFirebase) logEventWithName:@"select_content" parameters:@{
@"item_id": @"507f1f77bcf86cd799439011",
@"sku":@"G-32",
@"item_category":@"Games",
@"item_name":@"Monopoly: 3rd Edition",
@"brand":@"Hasbro",
@"variant":@"200 pieces",
@"price":@18.99,
@"quantity":@1,
@"coupon":@"MAYDEALS",
@"position":@3,
@"url":@"https://www.company.com/product/path",
@"image_url":@"https://www.company.com/product/path.jpg"}];
@"item_id" : @"507f1f77bcf86cd799439011",
@"sku" : @"G-32",
@"item_category" : @"Games",
@"item_name" : @"Monopoly: 3rd Edition",
@"brand" : @"Hasbro",
@"variant" : @"200 pieces",
@"price" : @18.99,
@"quantity" : @1,
@"coupon" : @"MAYDEALS",
@"position" : @3,
@"url" : @"https://www.company.com/product/path",
@"image_url" : @"https://www.company.com/product/path.jpg"
}];
});
it(@"track Product Viewed", ^{
SEGTrackPayload *payload = [[SEGTrackPayload alloc] initWithEvent:@"Product Viewed"
properties:@{
@"product_id": @"507f1f77bcf86cd799439011",
@"sku":@"G-32",
@"category":@"Games",
@"name":@"Monopoly 3rd Edition",
@"brand":@"Hasbro",
@"variant":@"200 pieces",
@"price":@18.99,
@"quantity":@1,
@"coupon":@"MAYDEALS",
@"currency":@"usd",
@"position":@3,
@"url":@"https://www.company.com/product/path",
@"image_url":@"https://www.company.com/product/path.jpg"
}
context:@{}
integrations:@{}];
properties:@{
@"product_id" : @"507f1f77bcf86cd799439011",
@"sku" : @"G-32",
@"category" : @"Games",
@"name" : @"Monopoly 3rd Edition",
@"brand" : @"Hasbro",
@"variant" : @"200 pieces",
@"price" : @18.99,
@"quantity" : @1,
@"coupon" : @"MAYDEALS",
@"currency" : @"usd",
@"position" : @3,
@"url" : @"https://www.company.com/product/path",
@"image_url" : @"https://www.company.com/product/path.jpg"
}
context:@{}
integrations:@{}];
[integration track:payload];
[verify(mockFirebase) logEventWithName:@"view_item" parameters:@{
@"item_id": @"507f1f77bcf86cd799439011",
@"sku":@"G-32",
@"item_category":@"Games",
@"item_name":@"Monopoly 3rd Edition",
@"brand":@"Hasbro",
@"variant":@"200 pieces",
@"price":@18.99,
@"quantity":@1,
@"coupon":@"MAYDEALS",
@"currency":@"usd",
@"position":@3,
@"url":@"https://www.company.com/product/path",
@"image_url":@"https://www.company.com/product/path.jpg"}];
@"item_id" : @"507f1f77bcf86cd799439011",
@"sku" : @"G-32",
@"item_category" : @"Games",
@"item_name" : @"Monopoly 3rd Edition",
@"brand" : @"Hasbro",
@"variant" : @"200 pieces",
@"price" : @18.99,
@"quantity" : @1,
@"coupon" : @"MAYDEALS",
@"currency" : @"usd",
@"position" : @3,
@"url" : @"https://www.company.com/product/path",
@"image_url" : @"https://www.company.com/product/path.jpg"
}];
});
it(@"track Product Added", ^{
SEGTrackPayload *payload = [[SEGTrackPayload alloc] initWithEvent:@"Product Added"
properties:@{
@"cart_id":@"skdjsidjsdkdj29j",
@"product_id": @"507f1f77bcf86cd799439011",
@"sku":@"G-32",
@"category":@"Games",
@"name":@"Monopoly: 3rd Edition",
@"brand":@"Hasbro",
@"variant":@"200 pieces",
@"price":@18.99,
@"quantity":@1,
@"coupon":@"MAYDEALS",
@"position":@3,
@"url":@"https://www.company.com/product/path",
@"image_url":@"https://www.company.com/product/path.jpg"
}
context:@{}
integrations:@{}];
properties:@{
@"cart_id" : @"skdjsidjsdkdj29j",
@"product_id" : @"507f1f77bcf86cd799439011",
@"sku" : @"G-32",
@"category" : @"Games",
@"name" : @"Monopoly: 3rd Edition",
@"brand" : @"Hasbro",
@"variant" : @"200 pieces",
@"price" : @18.99,
@"quantity" : @1,
@"coupon" : @"MAYDEALS",
@"position" : @3,
@"url" : @"https://www.company.com/product/path",
@"image_url" : @"https://www.company.com/product/path.jpg"
}
context:@{}
integrations:@{}];
[integration track:payload];
[verify(mockFirebase) logEventWithName:@"add_to_cart" parameters:@{
@"cart_id":@"skdjsidjsdkdj29j",
@"item_id": @"507f1f77bcf86cd799439011",
@"sku":@"G-32",
@"item_category":@"Games",
@"item_name":@"Monopoly: 3rd Edition",
@"brand":@"Hasbro",
@"variant":@"200 pieces",
@"price":@18.99,
@"quantity":@1,
@"coupon":@"MAYDEALS",
@"position":@3,
@"url":@"https://www.company.com/product/path",
@"image_url":@"https://www.company.com/product/path.jpg"}];
@"cart_id" : @"skdjsidjsdkdj29j",
@"item_id" : @"507f1f77bcf86cd799439011",
@"sku" : @"G-32",
@"item_category" : @"Games",
@"item_name" : @"Monopoly: 3rd Edition",
@"brand" : @"Hasbro",
@"variant" : @"200 pieces",
@"price" : @18.99,
@"quantity" : @1,
@"coupon" : @"MAYDEALS",
@"position" : @3,
@"url" : @"https://www.company.com/product/path",
@"image_url" : @"https://www.company.com/product/path.jpg"
}];
});
it(@"track Product Removed", ^{
SEGTrackPayload *payload = [[SEGTrackPayload alloc] initWithEvent:@"Product Removed"
properties:@{
@"cart_id":@"ksjdj92dj29dj92d2j",
@"product_id": @"507f1f77bcf86cd799439011",
@"sku":@"G-32",
@"category":@"Games",
@"name":@"Monopoly: 3rd Edition",
@"brand":@"Hasbro",
@"variant":@"200 pieces",
@"price":@18.99,
@"quantity":@1,
@"coupon":@"MAYDEALS",
@"position":@3,
@"url":@"https://www.company.com/product/path",
@"image_url":@"https://www.company.com/product/path.jpg"
}
context:@{}
integrations:@{}];
properties:@{
@"cart_id" : @"ksjdj92dj29dj92d2j",
@"product_id" : @"507f1f77bcf86cd799439011",
@"sku" : @"G-32",
@"category" : @"Games",
@"name" : @"Monopoly: 3rd Edition",
@"brand" : @"Hasbro",
@"variant" : @"200 pieces",
@"price" : @18.99,
@"quantity" : @1,
@"coupon" : @"MAYDEALS",
@"position" : @3,
@"url" : @"https://www.company.com/product/path",
@"image_url" : @"https://www.company.com/product/path.jpg"
}
context:@{}
integrations:@{}];
[integration track:payload];
[verify(mockFirebase) logEventWithName:@"remove_from_cart" parameters:@{
@"cart_id":@"ksjdj92dj29dj92d2j",
@"item_id": @"507f1f77bcf86cd799439011",
@"sku":@"G-32",
@"item_category":@"Games",
@"item_name":@"Monopoly: 3rd Edition",
@"brand":@"Hasbro",
@"variant":@"200 pieces",
@"price":@18.99,
@"quantity":@1,
@"coupon":@"MAYDEALS",
@"position":@3,
@"url":@"https://www.company.com/product/path",
@"image_url":@"https://www.company.com/product/path.jpg"}];
@"cart_id" : @"ksjdj92dj29dj92d2j",
@"item_id" : @"507f1f77bcf86cd799439011",
@"sku" : @"G-32",
@"item_category" : @"Games",
@"item_name" : @"Monopoly: 3rd Edition",
@"brand" : @"Hasbro",
@"variant" : @"200 pieces",
@"price" : @18.99,
@"quantity" : @1,
@"coupon" : @"MAYDEALS",
@"position" : @3,
@"url" : @"https://www.company.com/product/path",
@"image_url" : @"https://www.company.com/product/path.jpg"
}];
});
it(@"track Checkout Started", ^{
SEGTrackPayload *payload = [[SEGTrackPayload alloc] initWithEvent:@"Checkout Started"
properties:@{
@"checkout_id":@"9bcf000000000000",
@"order_id":@"50314b8e",
@"affiliation":@"App Store",
@"total":@30.45,
@"shipping":@5.05,
@"tax":@1.20,
@"currency":@"USD",
@"category":@"Games",
@"revenue": @8,
@"products":@{
@"product_id":@"2013294",
@"category":@"Games",
@"name":@"Monopoly: 3rd Edition",
@"brand":@"Hasbros",
@"price":@"21.99",
@"quantity":@"1"
}
}
context:@{}
integrations:@{}];
properties:@{
@"checkout_id" : @"9bcf000000000000",
@"order_id" : @"50314b8e",
@"affiliation" : @"App Store",
@"total" : @30.45,
@"shipping" : @5.05,
@"tax" : @1.20,
@"currency" : @"USD",
@"category" : @"Games",
@"revenue" : @8,
@"products" : @{
@"product_id" : @"2013294",
@"category" : @"Games",
@"name" : @"Monopoly: 3rd Edition",
@"brand" : @"Hasbros",
@"price" : @"21.99",
@"quantity" : @"1"
}
}
context:@{}
integrations:@{}];
[integration track:payload];
[verify(mockFirebase) logEventWithName:@"begin_checkout" parameters:@{
@"checkout_id":@"9bcf000000000000",
@"transaction_id":@"50314b8e",
@"affiliation":@"App Store",
@"value":@30.45,
@"shipping":@5.05,
@"tax":@1.20,
@"currency":@"USD",
@"item_category":@"Games",
@"products":@{
@"product_id":@"2013294",
@"category":@"Games",
@"name":@"Monopoly: 3rd Edition",
@"brand":@"Hasbros",
@"price":@"21.99",
@"quantity":@"1"
}
}];
@"checkout_id" : @"9bcf000000000000",
@"transaction_id" : @"50314b8e",
@"affiliation" : @"App Store",
@"value" : @30.45,
@"shipping" : @5.05,
@"tax" : @1.20,
@"currency" : @"USD",
@"item_category" : @"Games",
@"products" : @{
@"product_id" : @"2013294",
@"category" : @"Games",
@"name" : @"Monopoly: 3rd Edition",
@"brand" : @"Hasbros",
@"price" : @"21.99",
@"quantity" : @"1"
}
}];
});
it(@"track Payment Info Entered", ^{
SEGTrackPayload *payload = [[SEGTrackPayload alloc] initWithEvent:@"Payment Info Entered"
properties:@{
@"checkout_id": @"39f39fj39f3jf93fj9fj39fj3f",
@"order_id":@"dkfsjidfjsdifsdfksdjfkdsfjsdfkdsf",
@"step":@"Payment",
@"shipping_method":@"ground",
@"payment_method":@"credit card"
}
context:@{}
integrations:@{}];
properties:@{
@"checkout_id" : @"39f39fj39f3jf93fj9fj39fj3f",
@"order_id" : @"dkfsjidfjsdifsdfksdjfkdsfjsdfkdsf",
@"step" : @"Payment",
@"shipping_method" : @"ground",
@"payment_method" : @"credit card"
}
context:@{}
integrations:@{}];
[integration track:payload];
[verify(mockFirebase) logEventWithName:@"add_payment_info" parameters:@{
@"checkout_id": @"39f39fj39f3jf93fj9fj39fj3f",
@"transaction_id":@"dkfsjidfjsdifsdfksdjfkdsfjsdfkdsf",
@"step":@"Payment",
@"shipping_method":@"ground",
@"payment_method":@"credit card"}];
@"checkout_id" : @"39f39fj39f3jf93fj9fj39fj3f",
@"transaction_id" : @"dkfsjidfjsdifsdfksdjfkdsfjsdfkdsf",
@"step" : @"Payment",
@"shipping_method" : @"ground",
@"payment_method" : @"credit card"
}];
});
it(@"track Order Refunded", ^{
SEGTrackPayload *payload = [[SEGTrackPayload alloc] initWithEvent:@"Order Refunded"
properties:@{
@"order_id": @"50314b8e9bcf000000000000"
}
context:@{}
integrations:@{}];
properties:@{
@"order_id" : @"50314b8e9bcf000000000000"
}
context:@{}
integrations:@{}];
[integration track:payload];
[verify(mockFirebase) logEventWithName:@"purchase_refund" parameters:@{
@"transaction_id": @"50314b8e9bcf000000000000"}];
@"transaction_id" : @"50314b8e9bcf000000000000"
}];
});
it(@"track Product List Viewed", ^{
SEGTrackPayload *payload = [[SEGTrackPayload alloc] initWithEvent:@"Product List Viewed"
properties:@{
@"list_id": @"hot_deals_1",
@"category":@"Deals",
@"products":@{
@"product_id":@"2013294",
@"category":@"Games",
@"name":@"Monopoly: 3rd Edition",
@"brand":@"Hasbros",
@"price":@"21.99",
@"quantity":@"1"
}
}
context:@{}
integrations:@{}];
properties:@{
@"list_id" : @"hot_deals_1",
@"category" : @"Deals",
@"products" : @{
@"product_id" : @"2013294",
@"category" : @"Games",
@"name" : @"Monopoly: 3rd Edition",
@"brand" : @"Hasbros",
@"price" : @"21.99",
@"quantity" : @"1"
}
}
context:@{}
integrations:@{}];
[integration track:payload];
[verify(mockFirebase) logEventWithName:@"view_item_list" parameters:@{
@"list_id": @"hot_deals_1",
@"item_category":@"Deals",
@"products":@{
@"product_id":@"2013294",
@"category":@"Games",
@"name":@"Monopoly: 3rd Edition",
@"brand":@"Hasbros",
@"price":@"21.99",
@"quantity":@"1"
}
}];
@"list_id" : @"hot_deals_1",
@"item_category" : @"Deals",
@"products" : @{
@"product_id" : @"2013294",
@"category" : @"Games",
@"name" : @"Monopoly: 3rd Edition",
@"brand" : @"Hasbros",
@"price" : @"21.99",
@"quantity" : @"1"
}
}];
});
it(@"track Product Added to Wishlist", ^{
SEGTrackPayload *payload = [[SEGTrackPayload alloc] initWithEvent:@"Product Added to Wishlist"
properties:@{
@"wishlist_id": @"skdjsidjsdkdj29j",
@"wishlist_name": @"Loved Games",
@"product_id": @"507f1f77bcf86cd799439011",
@"sku": @"G-32",
@"category": @"Games",
@"name": @"Monopoly: 3rd Edition",
@"brand": @"Hasbro",
@"variant": @"200 pieces",
@"price": @18.99,
@"quantity": @1,
@"coupon": @"MAYDEALS",
@"position": @3,
@"url": @"https://www.company.com/product/path",
@"image_url": @"https://www.company.com/product/path.jpg"
}
context:@{}
integrations:@{}];
properties:@{
@"wishlist_id" : @"skdjsidjsdkdj29j",
@"wishlist_name" : @"Loved Games",
@"product_id" : @"507f1f77bcf86cd799439011",
@"sku" : @"G-32",
@"category" : @"Games",
@"name" : @"Monopoly: 3rd Edition",
@"brand" : @"Hasbro",
@"variant" : @"200 pieces",
@"price" : @18.99,
@"quantity" : @1,
@"coupon" : @"MAYDEALS",
@"position" : @3,
@"url" : @"https://www.company.com/product/path",
@"image_url" : @"https://www.company.com/product/path.jpg"
}
context:@{}
integrations:@{}];
[integration track:payload];
[verify(mockFirebase) logEventWithName:@"add_to_wishlist" parameters:@{
@"wishlist_id": @"skdjsidjsdkdj29j",
@"wishlist_name": @"Loved Games",
@"item_id": @"507f1f77bcf86cd799439011",
@"sku": @"G-32",
@"item_category": @"Games",
@"item_name": @"Monopoly: 3rd Edition",
@"brand": @"Hasbro",
@"variant": @"200 pieces",
@"price": @18.99,
@"quantity": @1,
@"coupon": @"MAYDEALS",
@"position": @3,
@"url": @"https://www.company.com/product/path",
@"image_url": @"https://www.company.com/product/path.jpg"
}];
@"wishlist_id" : @"skdjsidjsdkdj29j",
@"wishlist_name" : @"Loved Games",
@"item_id" : @"507f1f77bcf86cd799439011",
@"sku" : @"G-32",
@"item_category" : @"Games",
@"item_name" : @"Monopoly: 3rd Edition",
@"brand" : @"Hasbro",
@"variant" : @"200 pieces",
@"price" : @18.99,
@"quantity" : @1,
@"coupon" : @"MAYDEALS",
@"position" : @3,
@"url" : @"https://www.company.com/product/path",
@"image_url" : @"https://www.company.com/product/path.jpg"
}];
});
it(@"track Product Shared", ^{
SEGTrackPayload *payload = [[SEGTrackPayload alloc] initWithEvent:@"Product Shared"
properties:@{
@"share_via": @"email",
@"share_message": @"Hey, check out this item",
@"recipient": @"friend@gmail.com",
@"product_id": @"507f1f77bcf86cd799439011",
@"sku": @"G-32",
@"category": @"Games",
@"name": @"Monopoly: 3rd Edition",
@"brand": @"Hasbro",
@"variant": @"200 pieces",
@"price": @18.99,
@"url": @"https://www.company.com/product/path",
@"image_url": @"https://www.company.com/product/path.jpg"
}
context:@{}
integrations:@{}];
properties:@{
@"share_via" : @"email",
@"share_message" : @"Hey, check out this item",
@"recipient" : @"friend@gmail.com",
@"product_id" : @"507f1f77bcf86cd799439011",
@"sku" : @"G-32",
@"category" : @"Games",
@"name" : @"Monopoly: 3rd Edition",
@"brand" : @"Hasbro",
@"variant" : @"200 pieces",
@"price" : @18.99,
@"url" : @"https://www.company.com/product/path",
@"image_url" : @"https://www.company.com/product/path.jpg"
}
context:@{}
integrations:@{}];
[integration track:payload];
[verify(mockFirebase) logEventWithName:@"share" parameters:@{
@"share_via": @"email",
@"share_message": @"Hey, check out this item",
@"recipient": @"friend@gmail.com",
@"item_id": @"507f1f77bcf86cd799439011",
@"sku": @"G-32",
@"item_category": @"Games",
@"item_name": @"Monopoly: 3rd Edition",
@"brand": @"Hasbro",
@"variant": @"200 pieces",
@"price": @18.99,
@"url": @"https://www.company.com/product/path",
@"image_url": @"https://www.company.com/product/path.jpg"
}];
@"share_via" : @"email",
@"share_message" : @"Hey, check out this item",
@"recipient" : @"friend@gmail.com",
@"item_id" : @"507f1f77bcf86cd799439011",
@"sku" : @"G-32",
@"item_category" : @"Games",
@"item_name" : @"Monopoly: 3rd Edition",
@"brand" : @"Hasbro",
@"variant" : @"200 pieces",
@"price" : @18.99,
@"url" : @"https://www.company.com/product/path",
@"image_url" : @"https://www.company.com/product/path.jpg"
}];
});
it(@"track Cart Shared", ^{
SEGTrackPayload *payload = [[SEGTrackPayload alloc] initWithEvent:@"Cart Shared"
properties:@{
@"share_via": @"email",
@"share_message": @"Hey, check out this item",
@"recipient": @"friend@gmail.com",
@"product_id": @"507f1f77bcf86cd799439011",
@"sku": @"G-32",
@"category": @"Games",
@"name": @"Monopoly: 3rd Edition",
@"brand": @"Hasbro",
@"variant": @"200 pieces",
@"price": @18.99,
@"url": @"https://www.company.com/product/path",
@"image_url": @"https://www.company.com/product/path.jpg"
}
context:@{}
integrations:@{}];
properties:@{
@"share_via" : @"email",
@"share_message" : @"Hey, check out this item",
@"recipient" : @"friend@gmail.com",
@"product_id" : @"507f1f77bcf86cd799439011",
@"sku" : @"G-32",
@"category" : @"Games",
@"name" : @"Monopoly: 3rd Edition",
@"brand" : @"Hasbro",
@"variant" : @"200 pieces",
@"price" : @18.99,
@"url" : @"https://www.company.com/product/path",
@"image_url" : @"https://www.company.com/product/path.jpg"
}
context:@{}
integrations:@{}];
[integration track:payload];
[verify(mockFirebase) logEventWithName:@"share" parameters:@{
@"share_via": @"email",
@"share_message": @"Hey, check out this item",
@"recipient": @"friend@gmail.com",
@"item_id": @"507f1f77bcf86cd799439011",
@"sku": @"G-32",
@"item_category": @"Games",
@"item_name": @"Monopoly: 3rd Edition",
@"brand": @"Hasbro",
@"variant": @"200 pieces",
@"price": @18.99,
@"url": @"https://www.company.com/product/path",
@"image_url": @"https://www.company.com/product/path.jpg"
}];
@"share_via" : @"email",
@"share_message" : @"Hey, check out this item",
@"recipient" : @"friend@gmail.com",
@"item_id" : @"507f1f77bcf86cd799439011",
@"sku" : @"G-32",
@"item_category" : @"Games",
@"item_name" : @"Monopoly: 3rd Edition",
@"brand" : @"Hasbro",
@"variant" : @"200 pieces",
@"price" : @18.99,
@"url" : @"https://www.company.com/product/path",
@"image_url" : @"https://www.company.com/product/path.jpg"
}];
});
it(@"track Products Searched", ^{
SEGTrackPayload *payload = [[SEGTrackPayload alloc] initWithEvent:@"Products Searched"
properties:@{
@"query": @"blue hotpants"
}
context:@{}
integrations:@{}];
properties:@{
@"query" : @"blue hotpants"
}
context:@{}
integrations:@{}];
[integration track:payload];
[verify(mockFirebase) logEventWithName:@"search" parameters:@{
@"search_term": @"blue hotpants"
}];
@"search_term" : @"blue hotpants"
}];
});
});
SpecEnd

View File

@@ -6,6 +6,7 @@
#import <Foundation/Foundation.h>
#import <Analytics/SEGIntegration.h>
@interface SEGFirebaseIntegration : NSObject <SEGIntegration>
@property (nonatomic, strong) NSDictionary *settings;

View File

@@ -2,6 +2,7 @@
#import <Analytics/SEGAnalyticsUtils.h>
#import <Firebase/Firebase.h>
@implementation SEGFirebaseIntegration
#pragma mark - Initialization
@@ -16,7 +17,7 @@
[FIROptions defaultOptions].deepLinkURLScheme = deepLinkURLScheme;
SEGLog(@"[FIROptions defaultOptions].deepLinkURLScheme = %@;", deepLinkURLScheme);
}
[FIRApp configure];
SEGLog(@"[FIRApp Configure]");
}
@@ -40,7 +41,7 @@
}
// Firebase requires user properties to be an NSString
NSDictionary *mappedTraits = [SEGFirebaseIntegration mapToStrings:payload.traits];
[mappedTraits enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *obj, BOOL *stop){
[mappedTraits enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *obj, BOOL *stop) {
NSString *trait = [key stringByReplacingOccurrencesOfString:@" " withString:@"_"];
NSString *value = [obj stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
[self.firebaseClass setUserPropertyString:value forName:trait];
@@ -49,17 +50,16 @@
}
- (void)track:(SEGTrackPayload *)payload
{
NSString *name = [self formatFirebaseEventNames:payload.event];
NSDictionary *parameters = [self returnMappedFirebaseParameters:payload.properties];
{
NSString *name = [self formatFirebaseEventNames:payload.event];
NSDictionary *parameters = [self returnMappedFirebaseParameters:payload.properties];
[self.firebaseClass logEventWithName:name parameters:parameters];
SEGLog(@"[FIRAnalytics logEventWithName:%@ parameters:%@]", name, parameters);
}
[self.firebaseClass logEventWithName:name parameters:parameters];
SEGLog(@"[FIRAnalytics logEventWithName:%@ parameters:%@]", name, parameters);
}
# pragma mark - Utilities
#pragma mark - Utilities
// Event names can be up to 32 characters long, may only contain alphanumeric
// characters and underscores ("_"), and must start with an alphabetic character. The "firebase_"
@@ -71,23 +71,22 @@
- (NSString *)formatFirebaseEventNames:(NSString *)event
{
NSDictionary *mapper = [NSDictionary dictionaryWithObjectsAndKeys:
kFIREventSelectContent, @"Product Clicked",
kFIREventViewItem, @"Product Viewed",
kFIREventAddToCart, @"Product Added",
kFIREventRemoveFromCart, @"Product Removed",
kFIREventBeginCheckout, @"Checkout Started",
kFIREventAddPaymentInfo, @"Payment Info Entered",
kFIREventEcommercePurchase, @"Order Completed",
kFIREventPurchaseRefund, @"Order Refunded",
kFIREventViewItemList, @"Product List Viewed",
kFIREventAddToWishlist, @"Product Added to Wishlist",
kFIREventShare, @"Product Shared",
kFIREventShare, @"Cart Shared",
kFIREventSearch, @"Products Searched", nil
];
kFIREventSelectContent, @"Product Clicked",
kFIREventViewItem, @"Product Viewed",
kFIREventAddToCart, @"Product Added",
kFIREventRemoveFromCart, @"Product Removed",
kFIREventBeginCheckout, @"Checkout Started",
kFIREventAddPaymentInfo, @"Payment Info Entered",
kFIREventEcommercePurchase, @"Order Completed",
kFIREventPurchaseRefund, @"Order Refunded",
kFIREventViewItemList, @"Product List Viewed",
kFIREventAddToWishlist, @"Product Added to Wishlist",
kFIREventShare, @"Product Shared",
kFIREventShare, @"Cart Shared",
kFIREventSearch, @"Products Searched", nil];
NSString *mappedEvent = [mapper objectForKey:event];
if (mappedEvent) {
return mappedEvent;
} else {
@@ -105,20 +104,20 @@
- (NSDictionary *)returnMappedFirebaseParameters:(NSDictionary *)properties
{
NSDictionary *map = [NSDictionary dictionaryWithObjectsAndKeys:
kFIRParameterItemCategory, @"category",
kFIRParameterItemID, @"product_id",
kFIRParameterItemName, @"name",
kFIRParameterPrice, @"price",
kFIRParameterQuantity, @"quantity",
kFIRParameterSearchTerm, @"query",
kFIRParameterShipping, @"shipping",
kFIRParameterTax, @"tax",
kFIRParameterValue, @"total",
kFIRParameterValue, @"revenue",
kFIRParameterTransactionID, @"order_id",
kFIRParameterCurrency, @"currency", nil];
kFIRParameterItemCategory, @"category",
kFIRParameterItemID, @"product_id",
kFIRParameterItemName, @"name",
kFIRParameterPrice, @"price",
kFIRParameterQuantity, @"quantity",
kFIRParameterSearchTerm, @"query",
kFIRParameterShipping, @"shipping",
kFIRParameterTax, @"tax",
kFIRParameterValue, @"total",
kFIRParameterValue, @"revenue",
kFIRParameterTransactionID, @"order_id",
kFIRParameterCurrency, @"currency", nil];
return [SEGFirebaseIntegration mapToFirebaseParameters:properties withMap:map];
}
@@ -132,7 +131,7 @@
[mappedParams setObject:data forKey:new];
}
}];
return [formatEventProperties(mappedParams) copy];
}
@@ -142,23 +141,22 @@ NSDictionary *formatEventProperties(NSDictionary *dictionary)
[dictionary enumerateKeysAndObjectsUsingBlock:^(id key, id data, BOOL *stop) {
[output removeObjectForKey:key];
key = [key stringByReplacingOccurrencesOfString:@" " withString:@"_"];
if ([data isKindOfClass:[NSNumber class]]){
if ([data isKindOfClass:[NSNumber class]]) {
data = [NSNumber numberWithDouble:[data doubleValue]];
[output setObject:data forKey:key];
} else {
[output setObject:data forKey:key];
}
}];
return [output copy];
return [output copy];
}
// Firebase requires all User traits to be Strings
+ (NSDictionary *)mapToStrings:(NSDictionary *)dictionary
{
NSMutableDictionary *output = [NSMutableDictionary dictionaryWithCapacity:dictionary.count];
[dictionary enumerateKeysAndObjectsUsingBlock:^(id key, id data, BOOL *stop) {
if ([data isKindOfClass:[NSString class]]) {
[output setObject:data forKey:key];
@@ -166,7 +164,7 @@ NSDictionary *formatEventProperties(NSDictionary *dictionary)
[output setObject:[NSString stringWithFormat:@"%@", data] forKey:key];
}
}];
return [output copy];
}

View File

@@ -1,8 +1,9 @@
#import <Foundation/Foundation.h>
#import <Analytics/SEGIntegrationFactory.h>
@interface SEGFirebaseIntegrationFactory : NSObject<SEGIntegrationFactory>
@interface SEGFirebaseIntegrationFactory : NSObject <SEGIntegrationFactory>
+ (instancetype)instance;
@end
@end

View File

@@ -6,6 +6,7 @@
#import "SEGFirebaseIntegrationFactory.h"
#import "SEGFirebaseIntegration.h"
@implementation SEGFirebaseIntegrationFactory
+ (instancetype)instance
@@ -34,4 +35,4 @@
return @"Firebase";
}
@end
@end