Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto committed Oct 27, 2023
1 parent 9e12d79 commit 3bc8be0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 72 deletions.
12 changes: 3 additions & 9 deletions PostHogExample/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,7 @@ class AppDelegate: NSObject, UIApplicationDelegate {

PostHogSDK.shared.setup(config)
// PostHogSDK.shared.debug()
// let props: [String : Any] = ["test": 1,
// "test2": 2.1,
// "test3": "test",
// "test4": true,
// "test5": [1, 2, 3],
// "test6": ["one": 1]]
let defaultCenter = NotificationCenter.default
let props: [String: Any] = ["not": defaultCenter, "url": URL(string: "123")!]
PostHogSDK.shared.capture("App started!", properties: props)
// PostHogSDK.shared.capture("App started!")

// DispatchQueue.global(qos: .utility).async {
// let task = Api().failingRequest()
Expand All @@ -37,6 +29,8 @@ class AppDelegate: NSObject, UIApplicationDelegate {
// ])
// }

let defaultCenter = NotificationCenter.default

#if os(iOS) || os(tvOS)
defaultCenter.addObserver(self,
selector: #selector(receiveFeatureFlags),
Expand Down
113 changes: 50 additions & 63 deletions PostHogObjCExample/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,73 +31,60 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
config.preloadFeatureFlags = NO;
[[PostHogSDK shared] debug:YES];
[[PostHogSDK shared] setup:config];
// NSLog(@"getDistinctId: %@", [[PostHogSDK shared] getDistinctId]);
// NSLog(@"getAnonymousId: %@", [[PostHogSDK shared] getAnonymousId]);
//
NSLog(@"getDistinctId: %@", [[PostHogSDK shared] getDistinctId]);
NSLog(@"getAnonymousId: %@", [[PostHogSDK shared] getAnonymousId]);

NSMutableDictionary *props = [NSMutableDictionary dictionary];
props[@"str"] = @"running";
props[@"numb"] = @1;
props[@"numb_2"] = @1.5;
props[@"bool"] = @YES;
props[@"date"] = NSDate.now;
props[@"url"] = [NSURL URLWithString:@"test"];
NSMutableArray *doubleDigits = [NSMutableArray array];
[doubleDigits addObject:@1];
props[@"arr"] = doubleDigits;
NSMutableDictionary *props2 = [NSMutableDictionary dictionary];
props2[@"1"] = @"test";
props[@"dict"] = props2;
props[@"state"] = @"running";

NSMutableDictionary *userProps = [NSMutableDictionary dictionary];
userProps[@"userAge"] = @50;

//
// NSMutableDictionary *userProps = [NSMutableDictionary dictionary];
// userProps[@"userAge"] = @50;
//
// NSMutableDictionary *userPropsOnce = [NSMutableDictionary dictionary];
// userPropsOnce[@"userAlive"] = @YES;
//
// NSMutableDictionary *groupProps = [NSMutableDictionary dictionary];
// groupProps[@"groupName"] = @"theGroup";
//
// NSMutableDictionary *registerProps = [NSMutableDictionary dictionary];
// props[@"loggedIn"] = @YES;
// [[PostHogSDK shared] registerProperties:registerProps];
// [[PostHogSDK shared] unregisterProperties:@"test2"];
//
// [[PostHogSDK shared] identify:@"my_new_id"];
// [[PostHogSDK shared] identifyWithDistinctId:@"my_new_id" userProperties:userProps];
// [[PostHogSDK shared] identifyWithDistinctId:@"my_new_id" userProperties:userProps userPropertiesSetOnce:userPropsOnce];
//
//
// [[PostHogSDK shared] optIn];
// [[PostHogSDK shared] optOut];
// NSLog(@"isOptOut: %d", [[PostHogSDK shared] isOptOut]);
// NSLog(@"isFeatureEnabled: %d", [[PostHogSDK shared] isFeatureEnabled:@"myFlag"]);
// NSLog(@"getFeatureFlag: %@", [[PostHogSDK shared] getFeatureFlag:@"myFlag"]);
// NSLog(@"getFeatureFlagPayload: %@", [[PostHogSDK shared] getFeatureFlagPayload:@"myFlag"]);
//
// [[PostHogSDK shared] reloadFeatureFlags];
// [[PostHogSDK shared] reloadFeatureFlagsWithCallback:^(){
// NSLog(@"called");
// }];
//
// [[PostHogSDK shared] capture:@"theEvent"];
NSMutableDictionary *userPropsOnce = [NSMutableDictionary dictionary];
userPropsOnce[@"userAlive"] = @YES;

NSMutableDictionary *groupProps = [NSMutableDictionary dictionary];
groupProps[@"groupName"] = @"theGroup";

NSMutableDictionary *registerProps = [NSMutableDictionary dictionary];
props[@"loggedIn"] = @YES;
[[PostHogSDK shared] registerProperties:registerProps];
[[PostHogSDK shared] unregisterProperties:@"test2"];

[[PostHogSDK shared] identify:@"my_new_id"];
[[PostHogSDK shared] identifyWithDistinctId:@"my_new_id" userProperties:userProps];
[[PostHogSDK shared] identifyWithDistinctId:@"my_new_id" userProperties:userProps userPropertiesSetOnce:userPropsOnce];


[[PostHogSDK shared] optIn];
[[PostHogSDK shared] optOut];
NSLog(@"isOptOut: %d", [[PostHogSDK shared] isOptOut]);
NSLog(@"isFeatureEnabled: %d", [[PostHogSDK shared] isFeatureEnabled:@"myFlag"]);
NSLog(@"getFeatureFlag: %@", [[PostHogSDK shared] getFeatureFlag:@"myFlag"]);
NSLog(@"getFeatureFlagPayload: %@", [[PostHogSDK shared] getFeatureFlagPayload:@"myFlag"]);

[[PostHogSDK shared] reloadFeatureFlags];
[[PostHogSDK shared] reloadFeatureFlagsWithCallback:^(){
NSLog(@"called");
}];

[[PostHogSDK shared] capture:@"theEvent"];
[[PostHogSDK shared] captureWithEvent:@"theEvent" properties:props];
// [[PostHogSDK shared] captureWithEvent:@"theEvent" properties:props userProperties:userProps];
// [[PostHogSDK shared] captureWithEvent:@"theEvent" properties:props userProperties:userProps userPropertiesSetOnce:userPropsOnce];
// [[PostHogSDK shared] captureWithEvent:@"theEvent" properties:props userProperties:userProps userPropertiesSetOnce:userPropsOnce groupProperties:groupProps];
//
// [[PostHogSDK shared] groupWithType:@"theType" key:@"theKey"];
// [[PostHogSDK shared] groupWithType:@"theType" key:@"theKey" groupProperties:groupProps];
//
// [[PostHogSDK shared] alias:@"theAlias"];
//
// [[PostHogSDK shared] screen:@"theScreen"];
// [[PostHogSDK shared] screenWithTitle:@"theScreen" properties:props];
//
// [[PostHogSDK shared] flush];
// [[PostHogSDK shared] reset];
// [[PostHogSDK shared] close];
[[PostHogSDK shared] captureWithEvent:@"theEvent" properties:props userProperties:userProps];
[[PostHogSDK shared] captureWithEvent:@"theEvent" properties:props userProperties:userProps userPropertiesSetOnce:userPropsOnce];
[[PostHogSDK shared] captureWithEvent:@"theEvent" properties:props userProperties:userProps userPropertiesSetOnce:userPropsOnce groupProperties:groupProps];

[[PostHogSDK shared] groupWithType:@"theType" key:@"theKey"];
[[PostHogSDK shared] groupWithType:@"theType" key:@"theKey" groupProperties:groupProps];

[[PostHogSDK shared] alias:@"theAlias"];

[[PostHogSDK shared] screen:@"theScreen"];
[[PostHogSDK shared] screenWithTitle:@"theScreen" properties:props];

[[PostHogSDK shared] flush];
[[PostHogSDK shared] reset];
[[PostHogSDK shared] close];

PostHogSDK *postHog = [PostHogSDK with:config];

Expand Down

0 comments on commit 3bc8be0

Please sign in to comment.