2
0

Bump External dependencies.

This commit is contained in:
Maarten Billemont
2013-08-11 00:08:25 -04:00
parent 77439af486
commit 8375808cdc
224 changed files with 13810 additions and 2949 deletions

View File

@@ -1,4 +1,4 @@
Copyright (c) 2009, Char Software, Inc. d/b/a Localytics
Copyright (c) 2013, Char Software, Inc. d/b/a Localytics
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -18,4 +18,5 @@ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@@ -18,6 +18,8 @@
sqlite3 *_databaseConnection;
}
@property (nonatomic, assign, readonly) BOOL firstRun;
- (unsigned long long)databaseSize;
- (int)eventCount;
- (NSTimeInterval)createdTimestamp;
@@ -50,6 +52,8 @@
- (BOOL)isOptedOut;
- (BOOL)setOptedOut:(BOOL)optOut;
- (NSString *)appVersion;
- (BOOL)updateAppVersion:(NSString *)appVersion;
- (NSString *)installId;
- (NSString *)appKey; // Most recent app key-- may not be that used to open the session.

View File

@@ -29,6 +29,7 @@
- (void)upgradeToSchemaV10;
- (void)upgradeToSchemaV11;
- (void)upgradeToSchemaV12;
- (void)upgradeToSchemaV13;
- (void)moveDbToCaches;
- (NSString *)randomUUID;
@end
@@ -74,12 +75,12 @@
}
// Check db connection, creating schema if necessary.
BOOL firstRun = NO;
_firstRun = NO;
if (code == SQLITE_OK) {
sqlite3_busy_timeout(_databaseConnection, BUSY_TIMEOUT); // Defaults to 0, otherwise.
if ([self schemaVersion] == 0) {
[self createSchema];
firstRun = YES;
_firstRun = YES;
}
}
@@ -117,9 +118,12 @@
if ([self schemaVersion] < 12) {
[self upgradeToSchemaV12];
}
if ([self schemaVersion] < 13) {
[self upgradeToSchemaV13];
}
// Perfrorm first run actions
if(firstRun)
if(_firstRun)
{
[self collectFacebookAttributionIfAvailable];
}
@@ -672,6 +676,29 @@
}
}
- (void)upgradeToSchemaV13
{
int code = sqlite3_exec(_databaseConnection, "BEGIN", NULL, NULL, NULL);
if (code == SQLITE_OK) {
code = sqlite3_exec(_databaseConnection,
"ALTER TABLE localytics_info ADD app_version CHAR(64)",
NULL, NULL, NULL);
}
if (code == SQLITE_OK) {
code = sqlite3_exec(_databaseConnection,
"UPDATE localytics_info set schema_version = 13",
NULL, NULL, NULL);
}
// Commit transaction.
if (code == SQLITE_OK || code == SQLITE_DONE) {
sqlite3_exec(_databaseConnection, "COMMIT", NULL, NULL, NULL);
} else {
sqlite3_exec(_databaseConnection, "ROLLBACK", NULL, NULL, NULL);
}
}
- (unsigned long long)databaseSize {
unsigned long long size = 0;
@@ -756,6 +783,30 @@
return code == SQLITE_OK;
}
- (NSString *)appVersion {
NSString *appVersion = nil;
sqlite3_stmt *selectAppVersion;
sqlite3_prepare_v2(_databaseConnection, "SELECT app_version FROM localytics_info", -1, &selectAppVersion, NULL);
int code = sqlite3_step(selectAppVersion);
if (code == SQLITE_ROW) {
char* chars = (char *)sqlite3_column_text(selectAppVersion, 0);
if(chars) appVersion = [NSString stringWithUTF8String:chars];
}
sqlite3_finalize(selectAppVersion);
return appVersion;
}
- (BOOL)updateAppVersion:(NSString *)appVersion {
sqlite3_stmt *updateAppVersion;
sqlite3_prepare_v2(_databaseConnection, "UPDATE localytics_info set app_version = ?", -1, &updateAppVersion, NULL);
sqlite3_bind_text (updateAppVersion, 1, [appVersion UTF8String], -1, SQLITE_TRANSIENT);
int code = sqlite3_step(updateAppVersion);
sqlite3_finalize(updateAppVersion);
return (code == SQLITE_DONE);
}
- (NSString *)customDimension:(int)dimension {
if(dimension < 0 || dimension > 9) {
return nil;

View File

@@ -40,7 +40,6 @@
NSMutableString *_screens; // Comma-delimited list of screens tagged during this session.
NSTimeInterval _sessionActiveDuration; // Duration that session open.
BOOL _sessionHasBeenOpen; // Whether or not this session has ever been open.
BOOL _delaySession; // Whether or not the server should delay processing on this upload
LocalyticsDatabase *_db; // Localytics database reference
LocalyticsUploader *_uploader; // Localytics uploader reference
}
@@ -60,8 +59,10 @@
@property (nonatomic, retain) NSMutableString *screens;
@property (nonatomic, assign) NSTimeInterval sessionActiveDuration;
@property (nonatomic, assign) BOOL sessionHasBeenOpen;
@property (nonatomic, assign) BOOL delaySession;
@property (nonatomic, assign) NSInteger sessionNumber;
@property (nonatomic, assign) BOOL needsSessionStartActions;
@property (nonatomic, assign) BOOL needsFirstRunActions;
@property (nonatomic, assign) BOOL needsUpgradeActions;
// Private methods.
+ (id)allocFactory;
@@ -80,7 +81,9 @@
- (LocalyticsDatabase *)db;
- (LocalyticsUploader *)uploader;
- (BOOL)uploadIsNeeded;
- (void)onStartSession;
- (void)onFirstRun;
- (void)onUpgrade;
// Datapoint methods.
- (NSString *)customDimensions;

View File

@@ -10,7 +10,7 @@
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#define CLIENT_VERSION @"2.17.3"
#define CLIENT_VERSION @"2.18.0"
#define MARKETING_PLATFORM
/*!

View File

@@ -49,12 +49,14 @@ static LocalyticsSession *_sharedLocalyticsSession = nil;
@synthesize screens = _screens;
@synthesize sessionActiveDuration = _sessionActiveDuration;
@synthesize sessionHasBeenOpen = _sessionHasBeenOpen;
@synthesize delaySession = _delaySession;
@synthesize sessionNumber = _sessionNumber;
@synthesize enableHTTPS = _enableHTTPS;
@synthesize loggingEnabled = _loggingEnabled;
@synthesize localyticsDelegate = _localyticsDelegate;
@synthesize facebookAttribution = _facebookAttribution;
@synthesize needsSessionStartActions = _needsSessionStartActions;
@synthesize needsFirstRunActions = _needsFirstRunActions;
@synthesize needsUpgradeActions = _needsUpgradeActions;
// Stores the last location passed in to the app.
CLLocationCoordinate2D lastDeviceLocation = {0,0};
@@ -91,7 +93,9 @@ CLLocationCoordinate2D lastDeviceLocation = {0,0};
_queue = dispatch_queue_create("com.Localytics.operations", DISPATCH_QUEUE_SERIAL);
_criticalGroup = dispatch_group_create();
_enableHTTPS = NO;
_delaySession = NO;
_needsSessionStartActions = NO;
_needsFirstRunActions = NO;
_needsUpgradeActions = NO;
[_sharedLocalyticsSession db];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];
@@ -135,11 +139,21 @@ CLLocationCoordinate2D lastDeviceLocation = {0,0};
// Record the key for future checks.
[[[LocalyticsSession shared] db] updateAppKey:appKey];
}
// Check for first run
self.needsFirstRunActions = [[[LocalyticsSession shared] db] firstRun];
// Check for app upgrade
NSString *currentAppVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
NSString *storedAppVersion = [[[LocalyticsSession shared] db] appVersion];
if (storedAppVersion && ![currentAppVersion isEqualToString:storedAppVersion])
self.needsUpgradeActions = YES;
if (storedAppVersion == nil || ![currentAppVersion isEqualToString:storedAppVersion])
[[[LocalyticsSession shared] db] updateAppVersion:currentAppVersion];
self.applicationKey = appKey;
self.hasInitialized = YES;
self.facebookAttribution = [[[LocalyticsSession shared] db] facebookAttributionFromDb];
self.delaySession = self.facebookAttribution != nil;
LocalyticsLog("Object Initialized. Application's key is: %@", self.applicationKey);
@@ -634,8 +648,6 @@ CLLocationCoordinate2D lastDeviceLocation = {0,0};
}
@catch (NSException * e) { }
});
[self uploadPartnerAttributions];
}
- (BOOL)uploadIsNeeded
@@ -643,21 +655,11 @@ CLLocationCoordinate2D lastDeviceLocation = {0,0};
return [[self db] unstagedEventCount] > 0;
}
- (void)uploadPartnerAttributions
{
dispatch_group_async(_criticalGroup, _queue, ^{
@try {
if (!self.facebookAttribution)
return;
[[self uploader] uploaderAttributionWithApplicationKey:self.applicationKey
attribution:self.facebookAttribution
installId:[self installationId]
advertisingIdentifier:[self advertisingIdentifier]];
}
@catch (NSException *e) {}
});
}
- (void)onStartSession {}
- (void)onFirstRun {}
- (void)onUpgrade {}
#pragma mark Private Methods
@@ -669,6 +671,23 @@ CLLocationCoordinate2D lastDeviceLocation = {0,0};
- (void)uploadCallback:(NSDictionary*)info
{
#pragma unused(info)
if (self.needsFirstRunActions)
{
[self onFirstRun];
self.needsFirstRunActions = NO;
}
if (self.needsUpgradeActions)
{
[self onUpgrade];
self.needsUpgradeActions = NO;
}
if (self.needsSessionStartActions)
{
[self onStartSession];
self.needsSessionStartActions = NO;
}
}
- (void)dequeueCloseEventBlobString
@@ -773,6 +792,12 @@ CLLocationCoordinate2D lastDeviceLocation = {0,0};
self.isSessionOpen = YES;
self.sessionHasBeenOpen = YES;
LocalyticsLog("Succesfully opened session. UUID is: %@", self.sessionUUID);
// Queue up a call to onStartSession after upload
self.needsSessionStartActions = YES;
// Upload after opening session successfully
[self upload];
}
else {
[db rollbackTransaction:t];
@@ -898,6 +923,13 @@ CLLocationCoordinate2D lastDeviceLocation = {0,0};
[headerString appendString:[NSString stringWithFormat:@",\"%@\":%@", PARAM_JAILBROKEN, [self isDeviceJailbroken] ? @"true" : @"false"]];
[headerString appendString:[NSString stringWithFormat:@",\"%@\":%d", PARAM_TIMEZONE_OFFSET, [[NSTimeZone localTimeZone] secondsFromGMT]]];
// >> Attribution information
//
if (self.facebookAttribution)
{
[headerString appendString:[self formatAttributeWithName:PARAM_FB_ATTRIBUTION value:self.facebookAttribution]];
}
// Close second level - attributes
[headerString appendString:@"}"];
@@ -1198,27 +1230,27 @@ CLLocationCoordinate2D lastDeviceLocation = {0,0};
*/
- (NSString *)installationId
{
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *installId = [prefs stringForKey:PREFERENCES_KEY];
if(installId == nil)
{
LocalyticsLog("Install ID not found in preferences, checking DB");
installId = [[self db] installId];
}
// If it hasn't been found yet, generate a new one.
if(installId == nil)
{
LocalyticsLog("Install ID not find one in database, generating a new one.");
installId = [self randomUUID];
}
// Store the newly generated installId
[prefs setObject:installId forKey:PREFERENCES_KEY];
[[NSUserDefaults standardUserDefaults] synchronize];
return installId;
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *installId = [prefs stringForKey:PREFERENCES_KEY];
if(installId == nil)
{
LocalyticsLog("Install ID not found in preferences, checking DB");
installId = [[self db] installId];
}
// If it hasn't been found yet, generate a new one.
if(installId == nil)
{
LocalyticsLog("Install ID not find one in database, generating a new one.");
installId = [self randomUUID];
}
// Store the newly generated installId
[prefs setObject:installId forKey:PREFERENCES_KEY];
[[NSUserDefaults standardUserDefaults] synchronize];
return installId;
}
/*!
@@ -1259,7 +1291,12 @@ CLLocationCoordinate2D lastDeviceLocation = {0,0};
*/
- (NSString *)appVersion
{
return [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
if (version == nil || [version isEqualToString:@""])
version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
return version;
}
- (NSString *)customDimension:(int)dimension

View File

@@ -56,16 +56,6 @@ extern NSString * const kLocalyticsKeyResponseBody;
- (void)uploaderWithApplicationKey:(NSString *)localyticsApplicationKey useHTTPS:(BOOL)useHTTPS installId:(NSString *)installId libraryVersion:(NSString *)libraryVersion resultTarget:(id)target callback:(SEL)callbackMethod;
/*!
@method LocalyticsUploader
@abstract Upload attribution data to Localytics.
@param localyticsApplicationKey the Localytics application ID
@param attribution Attribution cookie captured at install time
@param installId Install id passed to the server in the x-install-id header field.
@param advertisingIdentifier The Apple 'advertisingidentifier'
*/
- (void)uploaderAttributionWithApplicationKey:(NSString *)appKey attribution:(NSString *)attribution installId:(NSString *)installId advertisingIdentifier:(NSString *)advertisingIdentifier;
/*!
@method uploadTimeStamp
@abstract Retrieve upload TimeStamp.

View File

@@ -22,10 +22,6 @@
#define LOCALYTICS_URL_SECURED @"https://analytics.localytics.com/api/v2/applications/%@/uploads"
#endif
#ifndef LOCALYTICS_ATTRIBUTION_SERVER
#define LOCALYTICS_ATTRIBUTION_SERVER @"http://a.localytics.com/fb_install/"
#endif
NSString * const kLocalyticsKeyResponseBody = @"localytics.key.responseBody";
@interface LocalyticsUploader ()
@@ -178,11 +174,6 @@ NSString * const kLocalyticsKeyResponseBody = @"localytics.key.responseBody";
[submitRequest setValue:@"gzip" forHTTPHeaderField:@"Content-Encoding"];
[submitRequest setValue:[NSString stringWithFormat:@"%d", requestData.length] forHTTPHeaderField:@"Content-Length"];
if ([LocalyticsSession shared].delaySession == YES)
{
[submitRequest setValue:@"true" forHTTPHeaderField:HEADER_DELAY_SESSION];
}
[submitRequest setHTTPBody:requestData];
return submitRequest;
@@ -196,71 +187,6 @@ NSString * const kLocalyticsKeyResponseBody = @"localytics.key.responseBody";
[[[LocalyticsSession shared] db] vacuumIfRequired];
}
- (void)uploaderAttributionWithApplicationKey:(NSString *)appKey attribution:(NSString *)attribution installId:(NSString *)installId advertisingIdentifier:(NSString *)advertisingIdentifier
{
// Required parameters
if(!attribution)
return;
NSString *apiUrlString = [LOCALYTICS_ATTRIBUTION_SERVER stringByAppendingString:appKey];
NSMutableURLRequest *submitRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:apiUrlString]
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:60.0];
NSMutableString *postBody = [NSMutableString string];
[postBody appendFormat:@"%@=%@", FB_ATTRIBUTION, attribution];
[postBody appendFormat:@"&%@=%ld", FB_ATTRIBUTION_TIME, (long)[[[LocalyticsSession shared] db] createdTimestamp]];
if(advertisingIdentifier)
{
[postBody appendFormat:@"&%@=%@", FB_DEVICE_ID_TYPE, @"adid"];
[postBody appendFormat:@"&%@=%@", FB_DEVICE_ID, advertisingIdentifier];
}
if(installId)
{
[postBody appendFormat:@"&%@=%@", FB_INSTALL_ID, installId];
}
[submitRequest setHTTPMethod:@"POST"];
[submitRequest setHTTPBody:[postBody dataUsingEncoding:NSUTF8StringEncoding]];
// Perform synchronous upload in an async dispatch. This is necessary because the calling block will not persist to
// receive the response data.
dispatch_group_async([[LocalyticsSession shared] criticalGroup], [[LocalyticsSession shared] queue], ^{
@try {
NSURLResponse *response = nil;
NSError *responseError = nil;
[NSURLConnection sendSynchronousRequest:submitRequest
returningResponse:&response
error:&responseError];
NSInteger responseStatusCode = [(NSHTTPURLResponse *)response statusCode];
if (responseError) {
// On error, simply print the error and close the uploader. We have to assume the data was not transmited
// so it is not deleted.
LocalyticsLog("Error uploading Facebook attribution. Code: %d, Description: %@",
[responseError code],
[responseError localizedDescription]);
}
else
{
// While response status codes in the 5xx range leave upload rows intact, the default case is to delete.
if (responseStatusCode >= 500 && responseStatusCode < 600) {
LocalyticsLog("Facebook attribution upload unsuccessful. Response code %d", responseStatusCode);
}
else
{
LocalyticsLog("Facebook attribution upload completed successfully. Response code %d", responseStatusCode);
[[[LocalyticsSession shared] db] setFacebookAttribution:nil];
[LocalyticsSession shared].facebookAttribution = nil;
}
}
}
@catch (NSException * e) {}
});
}
/*!
@method gzipDeflatedDataWithData
@abstract Deflates the provided data using gzip at the default compression level (6).

View File

@@ -17,7 +17,6 @@
#define HEADER_CLIENT_TIME @"x-upload-time"
#define HEADER_INSTALL_ID @"x-install-id"
#define HEADER_CLIENT_VERSION @"x-client-version"
#define HEADER_DELAY_SESSION @"ll-first-session"
/*********************
* Shared Attributes *
@@ -69,6 +68,7 @@
#define PARAM_IDENTIFIERS @"ids" // Identifiers (dictionary)
#define PARAM_BIRTH_TIME @"b" // Birth time (Since epoch)
#define PARAM_TIMEZONE_OFFSET @"tz" // Device offset from GMT in seconds
#define PARAM_FB_ATTRIBUTION @"fbat" // Facebook attribution cookie
/*****************
* Session Start *
@@ -119,15 +119,5 @@
#define PARAM_NEW_FLOW_EVENTS @"nw" // Events and screens encountered during this session that have NOT been staged for upload.
#define PARAM_OLD_FLOW_EVENTS @"od" // Events and screens encountered during this session that HAVE been staged for upload.
/************************
* Partner attributions *
***********************/
#define FB_ATTRIBUTION @"fb_attrib_first" // Facebook attribution cookie
#define FB_ATTRIBUTION_TIME @"fb_attrib_first_date" // Time original attribution cookie was collected
#define FB_ATTRIBUTION_CURRENT @"fb_attrib_current" // Facebook attribution cookie
#define FB_ATTRIBUTION_CURRENT_TIME @"fb_attrib_current_date" // Time original attribution cookie was collected
#define FB_DEVICE_ID @"dpid" // Device unique identifiers
#define FB_DEVICE_ID_TYPE @"dpid_type" // Either UDID or ADID (advertisingIdentifier)
#define FB_INSTALL_ID @"install_id" // Device install ID