iOS - lonslonz/rakedocument GitHub Wiki
Download
[download ํ์ด์ง](Rake manual#wiki-download)
์ค์น
- ๋ค์ด๋ฐ์ ์์ถ ํ์ผ์ ํผ๋ค.
- Mixpanel ํด๋๋ฅผ ํ๋ก์ ํธ์ drag & drop ํ๋ค. ๊ทธ๋ฆผ๊ณผ ๊ฐ์ด "Copy items into destination Group's folder"๋ฅผ ์ฒดํฌํด์ ๋ณต์ฌํ๋ค.
- Targets > Build Phases > Link binary with libraries ์์ ์๋ framework๋ฅผ ์ถ๊ฐํ๋ค.
- Foundation.framework
- UIKit.framework
- SystemConfiguration.framework
- CoreTelephony.framework
- AdSupport.framework
ARC
ํ์ฌ ์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ ARC๋ฅผ ์ฌ์ฉํ์ง ์๋๋ค. ARC๋ฅผ ์ฌ์ฉํ๋ ํ๋ก์ ํธ์ ํจ๊ป ์ฌ์ฉํ๊ธฐ ์ํด ๋ค์์ ์์ ์ด ํ์ํ๋ค.
- ๋ฉ๋ด์ Project > Target > Build Phases
- ๊ฐ addํ ํ์ผ์ ํด๋ฆญํ์ฌ ๋ค์์ ํ๋๊ทธ๋ฅผ ์ฝ์ : -fno-objc-arc.
์ฝ๋ ๋ฃ๊ธฐ
์ต์ด ์ด๊ธฐํ ํ๊ธฐ
-
application launch๊ฐ ๋๋ ์ดํ ์ด๊ธฐํ๋ฅผ ์ํํ๋ค.
#define MIXPANEL_TOKEN @"YOUR TOKEN" // ์๋น์ค์ ํ ๋น ๋ ํ ํฐ์ ์ฌ์ฉํ๋ค. #define MIXPANLE_USE_DEVSERVER true // ํ ์คํธ์ฉ ๊ฐ๋ฐ์๋ฒ๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด์ true๋ก ์ธํ ํ๋ค. ๋ฐฐํฌ์์๋ ๋ฐ๋์ false๋ก ์ธํ ํ๋ค. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [ [ [UIWindow alloc] initWithFrame:[ [UIScreen mainScreen] bounds]] autorelease]; self.mixpanel = [Mixpanel sharedInstanceWithToken:MIXPANEL_TOKEN andUseDevServer:MIXPANLE_USE_DEVSERVER]; // initialize self.viewController = [ [ [ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease]; self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible]; [ [UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)]; return YES; }
-
define ๊ตฌ๋ฌธ์์ token๊ณผ MIXPANLE_USE_DEVSERVER ๋ฅผ ์ ํ ํด์ผ ํ๋ค.
-
๊ฐ๋ฐ ์๋ฒ๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด์ MIXPANLE_USE_DEVSERVERf๋ฅผ true๋ก ์ธํ ํ๋ค. ์ค ํ๊ฒฝ์์๋ ๋ฐ๋์ false๋ก ๋ณ๊ฒฝํด์ผ ํ๋ค.
ํ์ด์ง ์ ํ์ด๋ button ํด๋ฆญ ์์ ๋ก๊ทธ๋ฅผ ์๊ธฐ
-
๋ก๊ทธ๋ฅผ ์๋ ๊ฒ์
track()
ํจ์๋ฅผ ํธ์ถํ๋ฉด ๋๋ค. -
์๋์ ๊ฐ์ด
track()
์ ์ธ์๋ก ๋ฐ์ดํฐ๋ฅผ ๋๊ธฐ๋ฉด ๋๋ค. ์ธ์๋ NSDictionary ํ์ ์ด๋ค. -
track()
ํจ์์ ์ฒซ๋ฒ์งธ ์ธ์๋ ์ฌ์ฉํ์ง ์๋๋ค. SKP ๋ด์์ ๋ก๊ทธ ํฌ๋งท์ด ์ ์๋์ด ์ฌ์ฉ๋ ๋๋ NSDictionary์ ๋ฏธ๋ฆฌ ์ ์๋ key, value๋ก ๋ฐ์ดํฐ๊ฐ ์ ๋ฌ๋์ด์ผ ํ๋ค.- (IBAction)trackEvent:(id)sender { Mixpanel *mixpanel = [Mixpanel sharedInstance]; [mixpanel track:[NSDictionary dictionaryWithObjectsAndKeys: @"junghyun", @"userId", @"a01jdksa904812df", @"purchaseId", @"30000", @"price", nil]]; }
์์ธ ๋ก๊ทธ๋ฅผ ์๋ฒ์ ๋ณด๋ด๊ธฐ
-
๋ก๊ทธ๋ฅผ ์๋ ๊ฒ๊ณผ ๋ก๊ทธ๋ฅผ ์๋ฒ์ ๋ณด๋ด๋ ๊ฒ์ ๋ค๋ฅด๋ค.
track()
์ ๋ก๊ทธ๋ฅผ ์ฑ ๋ด๋ถ(plist file)์ ์๊ณ ,flush()
๋ ์์ ๋ก๊ทธ๋ฅผ ์๋ฒ์ ๋ณด๋ธ๋ค. -
์์ ๋ก๊ทธ๋ ์์ถํด์ ์ ์ก๋๋ค. ๋ฐ๋ผ์ ์ฌ๋ฌ ๊ฐ์ ๋ก๊ทธ๋ฅผ ํ๋ฒ์ ์๋ฒ์ ๋ณด๋ด๋ ๊ฒ์ด ๋ฐ๋์งํ๋ค. ์ด๋
flush()
๋ฅผ ํธ์ถํ๋ฉด ๋๋ค. -
๋ํดํธ๋ก๋ 1๋ถ์ ํ๋ฒ ์์ธ ๋ก๊ทธ๋ฅผ ์ ์กํ๋ค. (setFlushInterval() ํจ์๋ฅผ ํตํด ์ค์ ๊ฐ๋ฅํ๋ค.)
-
๋ณดํต์ activity์
onDestroy()
์์flush()
๋ฅผ ํธ์ถํ๋ค.- (IBAction)flushPressed:(id)sender { statusText.text = [NSString stringWithFormat:@"flush button pressed"]; Mixpanel *mixpanel = [Mixpanel sharedInstance]; [mixpanel flush]; }
๋ฐ๋ณต๋๋ ํ๋๋ฅผ ํ๋ฒ๋ง ๋ฑ๋กํ๊ธฐ
NSString* memberId = @"CURRENT_MEMBER_ID";
NSString* sessionId = @"NEW_SESSION_ID";
[self.mixpanel registerSuperProperties:@{@"memeberId": memberId}]; // memeberId๋ฅผ super properties๋ก ์ค์
[self.mixpanel registerSuperProperties:@{@"sessionId": sessionId}]; // sessionID๋ฅผ super properties๋ก ์ค์
Sentinel๊ณผ ํจ๊ป ๊ฐ๋ฐํ๊ธฐ
-
Sentinel ์ ์ฉ์ json์ ์ง์ ์ ๋ ฅํ๋ ๋์ Pojo ํด๋์ค๋ฅผ ํตํด ์ ๋ ฅํ๋ ๊ฒ์ด๋ค.
-
Sentine ํํ์ด์ง์์ iOS์ฉ ์ฝ๋๋ฅผ ๋ค์ด๋ฐ์ ํ๋ก์ ํธ์ ๋งํฌํ์ฌ ์ฌ์ฉํ๋ค.
- (IBAction)clickMakeLogWithSentinel:(id)sender { RakeSampleSentinelShuttle *shuttle = [[RakeSampleSentinelShuttle alloc] init]; [shuttle page_id:self.getMyPageId]; [shuttle action_id:@"onclick"]; [shuttle action_extra_value:@"3"]; [self.rake track:[shuttle toNSDictionary]]; NSLog(@"%@", [shuttle toJSONString]); }
-
๋ค๋ฅธ ์ฝ๋๋ ๋์ผํ๋ฉฐ shuttle ๊ฐ์ฒด์ ๋จผ์ ๋ฐ์ดํฐ๋ฅผ set ํ ํ rake track ํจ์ ํธ์ถ์ NSDictionary ๋ก ๋ฐ๊พธ์ด ํธ์ถํ๋ค.
์์
- Rake ์ฌ์ฉ ์์ ๋ฐ Sentinel ์ฌ์ฉ ์์
- ๊ฐ๊ฐ์ ์ฌ์ฉ ์์ ๋ฅผ ๋ณผ ์ ์๋ค.
API
-
Mixpanel::track:(NSDictionary *) properties
- properties : ๋ฐ์ดํฐ๋ฅผ json ํํ๋ก ์ ๋ ฅํ๋ค. SKP์ ๊ฒฝ์ฐ ๋ก๊ทธ ํฌ๋งท์ ์ ์๋ key์ value๋ฅผ ๋ฃ์ด์ฃผ๋ฉด ๋๋ค.
-
Mixpanel::registerSuperProperties:(NSDictionary *) properties
- properties : ๋ฐ์ดํฐ๋ฅผ json ํํ๋ก ์ ๋ ฅํ๋ค. super properties ๋ก ์ ๋ ฅ๋ ๋ฐ์ดํฐ๋ ๋ชจ๋ ๋ก๊ทธ์ ์ ์ง๋๋ค.
-
Mixpanel::registerSuperPropertiesOnce:(NSDictionary *) properties
- properties : ๋ฐ์ดํฐ๋ฅผ json ํํ๋ก ์ ๋ ฅํ๋ค. super properties ๋ก ์ ๋ ฅ๋ ๋ฐ์ดํฐ๋ ๋ชจ๋ ๋ก๊ทธ์ ์ ์ง๋๋ค. ๊ฐ์ ํค๋ก ์ค์ ๋ ๊ฐ์ด ์ด๋ฏธ ์กด์ฌํ๋ค๋ฉด, ์๋ก ์ ๋ ฅํ ํค๋ ๋ฌด์๋๊ณ ์ด์ ๊ฐ์ด ์ ์ง๋๋ค.
-
Mixpanel::unregisterSuperProperties:(NSString *) propertyName
- propertyName : propertyName์ ํด๋นํ๋ super property๋ฅผ ์ญ์ ํ๋ค.
-
Mixpanel::flush()
- ๋ก๊ทธ๋ฅผ ์๋ฒ์ ์ ์ก ํ๋ค.
-
Mixpanel::setFlushInterval:(NSUInteger)interval
- milli-seconds ๋จ์๋ก flush ์ฃผ๊ธฐ๋ฅผ ์ค์ ํ๋ค.