Skip to content

Commit

Permalink
Merge tag 'v2.1.0'
Browse files Browse the repository at this point in the history
version 2.1.0

Conflicts:
	Mixpanel/Mixpanel.m
	README.md
  • Loading branch information
bdolman committed Nov 5, 2013
2 parents 70273bd + a49bb55 commit 18c74a7
Show file tree
Hide file tree
Showing 53 changed files with 3,308 additions and 1,508 deletions.
1 change: 1 addition & 0 deletions HelloMixpanel/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Pods
Binary file added HelloMixpanel/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
323 changes: 239 additions & 84 deletions HelloMixpanel/HelloMixpanel.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions HelloMixpanel/HelloMixpanel/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

#import <UIKit/UIKit.h>

#import "Mixpanel.h"

@class ViewController;
@class Mixpanel;

@interface AppDelegate : UIResponder <UIApplicationDelegate>
@interface AppDelegate : UIResponder <UIApplicationDelegate, MixpanelDelegate>

@property (strong, nonatomic) UIWindow *window;

Expand Down
33 changes: 17 additions & 16 deletions HelloMixpanel/HelloMixpanel/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#import "ViewController.h"

// IMPORTANT!!! replace with you api token from https://mixpanel.com/account/
#define MIXPANEL_TOKEN @"YOUR MIXPANEL PROJECT TOKEN"
#define MIXPANEL_TOKEN @"YOUR_MIXPANEL_PROJECT_TOKEN"

@implementation AppDelegate

Expand All @@ -38,31 +38,34 @@ - (void)dealloc
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

// Override point for customization after application launch.

// Initialize the MixpanelAPI object
self.mixpanel = [Mixpanel sharedInstanceWithToken:MIXPANEL_TOKEN];

self.mixpanel.checkForSurveysOnActive = YES;
self.mixpanel.showSurveyOnActive = YES; //Change this to NO to show your surveys manually.

// Set the upload interval to 20 seconds for demonstration purposes. This would be overkill for most applications.
self.mixpanel.flushInterval = 20; // defaults to 60 seconds

// Set some super properties, which will be added to every tracked event
[self.mixpanel registerSuperProperties:@{@"Plan": @"Premium"}];

// Name a user in Mixpanel Streams
self.mixpanel.nameTag = @"Walter Sobchak";

// Set some super properties, which will be added to every tracked event
[self.mixpanel registerSuperProperties:[NSDictionary dictionaryWithObjectsAndKeys:@"Premium", @"Plan", nil]];


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;
}

#pragma mark * Push notifications
#pragma mark - Push notifications

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
[self.mixpanel.people addPushDeviceToken:devToken];
Expand All @@ -79,17 +82,16 @@ - (void)application:(UIApplication *)app didFailToRegisterForRemoteNotifications
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
// Show alert for push notifications recevied while the app is running
NSString *message = [[userInfo objectForKey:@"aps"] objectForKey:@"alert"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@""
message:message
message:userInfo[@"aps"][@"alert"]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}

#pragma mark * Session timing example
#pragma mark - Session timing example

- (void)applicationDidBecomeActive:(UIApplication *)application
{
Expand All @@ -103,7 +105,7 @@ - (void)applicationWillResignActive:(UIApplication *)application
[[Mixpanel sharedInstance] track:@"Session" properties:[NSDictionary dictionaryWithObject:seconds forKey:@"Length"]];
}

#pragma mark * Background task tracking test
#pragma mark - Background task tracking test

- (void)applicationDidEnterBackground:(UIApplication *)application
{
Expand All @@ -121,7 +123,7 @@ - (void)applicationDidEnterBackground:(UIApplication *)application

// track some events and set some people properties
Mixpanel *mixpanel = [Mixpanel sharedInstance];
[mixpanel registerSuperProperties:[NSDictionary dictionaryWithObject:@"Hi!" forKey:@"Background Super Property"]];
[mixpanel registerSuperProperties:@{@"Background Super Property": @"Hi!"}];
[mixpanel track:@"Background Event"];
[mixpanel.people set:@"Background Property" to:[NSDate date]];

Expand All @@ -131,7 +133,6 @@ - (void)applicationDidEnterBackground:(UIApplication *)application
});

NSLog(@"%@ dispatched background task %lu", self, (unsigned long)self.bgTask);

}

@end
1 change: 0 additions & 1 deletion HelloMixpanel/HelloMixpanel/HelloMixpanel-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
Expand Down
90 changes: 62 additions & 28 deletions HelloMixpanel/HelloMixpanel/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
// limitations under the License.

#import "Mixpanel.h"
#import "MPSurvey.h"

#import "ViewController.h"

@interface ViewController ()
@interface ViewController () <UINavigationControllerDelegate, UIImagePickerControllerDelegate>

@property(nonatomic, retain) IBOutlet UISegmentedControl *genderControl;
@property(nonatomic, retain) IBOutlet UISegmentedControl *weaponControl;

- (IBAction)trackEvent:(id)sender;
- (IBAction)sendPeopleRecord:(id)sender;
@property(nonatomic, retain) IBOutlet UIImageView *fakeBackground;
@property(nonatomic, retain) IBOutlet UITextField *surveyIDField;
@property(nonatomic, retain) IBOutlet UIScrollView *scrollView;

@end

Expand All @@ -36,47 +37,35 @@ - (void)dealloc
{
self.genderControl = nil;
self.weaponControl = nil;
self.fakeBackground = nil;
[super dealloc];
}

- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"grid.png"]];
UIScrollView *tempScrollView = (UIScrollView *)self.view;
tempScrollView.contentSize = CGSizeMake(320, 342);
}

- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
_scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
_scrollView.contentSize = self.view.bounds.size;

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)];
[self.view addGestureRecognizer:tap];
}

- (IBAction)trackEvent:(id)sender
{
Mixpanel *mixpanel = [Mixpanel sharedInstance];
[mixpanel track:@"Player Create" properties:[NSDictionary dictionaryWithObjectsAndKeys:
[self.genderControl titleForSegmentAtIndex:self.genderControl.selectedSegmentIndex], @"gender",
[self.weaponControl titleForSegmentAtIndex:self.weaponControl.selectedSegmentIndex], @"weapon",
nil]];
NSString *gender = [self.genderControl titleForSegmentAtIndex:(NSUInteger)self.genderControl.selectedSegmentIndex];
NSString *weapon = [self.weaponControl titleForSegmentAtIndex:(NSUInteger)self.weaponControl.selectedSegmentIndex];
[mixpanel track:@"Player Create" properties:@{@"gender": gender, @"weapon": weapon}];
}

- (IBAction)sendPeopleRecord:(id)sender
- (IBAction)setPeopleProperties:(id)sender
{
Mixpanel *mixpanel = [Mixpanel sharedInstance];
[mixpanel.people set:[NSDictionary dictionaryWithObjectsAndKeys:
[self.genderControl titleForSegmentAtIndex:self.genderControl.selectedSegmentIndex], @"gender",
[self.weaponControl titleForSegmentAtIndex:self.weaponControl.selectedSegmentIndex], @"weapon",
@"Demo", @"$first_name",
@"User", @"$last_name",
@"[email protected]", @"$email",
nil]];
NSString *gender = [self.genderControl titleForSegmentAtIndex:(NSUInteger)self.genderControl.selectedSegmentIndex];
NSString *weapon = [self.weaponControl titleForSegmentAtIndex:(NSUInteger)self.weaponControl.selectedSegmentIndex];
[mixpanel.people set:@{@"gender": gender, @"weapon": weapon}];
// Mixpanel People requires that you explicitly set a distinct ID for the current user. In this case,
// we're using the automatically generated distinct ID from event tracking, based on the device's MAC address.
// It is strongly recommended that you use the same distinct IDs for Mixpanel Engagement and Mixpanel People.
Expand All @@ -86,4 +75,49 @@ - (IBAction)sendPeopleRecord:(id)sender
[mixpanel identify:mixpanel.distinctId];
}

- (IBAction)showSurvey:(id)sender
{
Mixpanel *mixpanel = [Mixpanel sharedInstance];

if ([_surveyIDField.text length] > 0) {
[mixpanel showSurveyWithID:(NSUInteger)([_surveyIDField.text integerValue])];

} else {
[mixpanel showSurvey];
}
[_surveyIDField resignFirstResponder];
}

- (IBAction)changeBackground
{
if (_fakeBackground.image) {
_fakeBackground.image = nil;
_fakeBackground.hidden = YES;
} else {
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePickerController.delegate = self;
[self presentViewController:imagePickerController animated:YES completion:nil];
}
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
_fakeBackground.image = image;
_fakeBackground.hidden = NO;
[self dismissViewControllerAnimated:YES completion:NULL];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:NULL];
}

- (void)dismissKeyboard
{
[_surveyIDField resignFirstResponder];
}

@end
Loading

0 comments on commit 18c74a7

Please sign in to comment.