Skip to content

Commit

Permalink
Merge branch 'release/2.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
defagos committed Jun 20, 2017
2 parents 9a3acdf + 72f299b commit b690a83
Show file tree
Hide file tree
Showing 13 changed files with 198 additions and 120 deletions.
4 changes: 2 additions & 2 deletions Cartfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
github "SRGSSR/SRGMediaPlayer-iOS" "2.0.1"
github "SRGSSR/srgdataprovider-ios" "5.1"
github "SRGSSR/SRGMediaPlayer-iOS" "2.0.2"
github "SRGSSR/srgdataprovider-ios" "5.2"
github "comScore/ComScore-iOS-SDK" "92f34897cd7659d56bb5a3e9e85b808cf3758bda"
2 changes: 1 addition & 1 deletion Cartfile.private
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "kif-framework/KIF" == 3.5.1
github "kif-framework/KIF" == 3.5.2
8 changes: 4 additions & 4 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
github "Mantle/Mantle" "2.1.0"
github "SRGSSR/MAKVONotificationCenter" "4a127e52997889729286510103f7e27100223730"
github "SRGSSR/SRGMediaPlayer-iOS" "2.0.1"
github "SRGSSR/libextobjc" "076c968c9ade619ee836c89a935e09e6708d6ef2"
github "SRGSSR/srgdataprovider-ios" "5.1"
github "SRGSSR/SRGMediaPlayer-iOS" "2.0.2"
github "SRGSSR/libextobjc" "cf5eb0c8a2f6f85636f1fb6a1f2083cbc74899f9"
github "SRGSSR/srgdataprovider-ios" "5.2"
github "SRGSSR/srglogger-ios" "1.0"
github "comScore/ComScore-iOS-SDK" "92f34897cd7659d56bb5a3e9e85b808cf3758bda"
github "kif-framework/KIF" "v3.5.1"
github "kif-framework/KIF" "v3.5.2"
10 changes: 5 additions & 5 deletions DemoTests/ViewEventTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ - (void)testAutomaticTracking
XCTAssertEqualObjects(labels[@"srg_ap_push"], @"0");
XCTAssertEqualObjects(labels[@"srg_n1"], @"app");
XCTAssertNil(labels[@"srg_n2"]);
XCTAssertEqualObjects(labels[@"srg_title"], @"Automatic tracking");
XCTAssertEqualObjects(labels[@"srg_title"], @"automatic-tracking");
XCTAssertEqualObjects(labels[@"ns_type"], @"view");
return YES;
}];
Expand Down Expand Up @@ -104,7 +104,7 @@ - (void)testAutomaticTrackingWithLevels
XCTAssertEqualObjects(labels[@"srg_n3"], @"level3");
XCTAssertNil(labels[@"srg_n4"]);
XCTAssertEqualObjects(labels[@"category"], @"level1.level2.level3");
XCTAssertEqualObjects(labels[@"srg_title"], @"Automatic tracking with levels");
XCTAssertEqualObjects(labels[@"srg_title"], @"automatic-tracking-with-levels");
XCTAssertEqualObjects(labels[@"ns_type"], @"view");
return YES;
}];
Expand Down Expand Up @@ -135,7 +135,7 @@ - (void)testMaximumNumberOfLevels
XCTAssertEqualObjects(labels[@"srg_n10"], @"level10");
XCTAssertNil(labels[@"srg_n11"]);
XCTAssertEqualObjects(labels[@"category"], @"level1.level2.level3.level4.level5.level6.level7.level8.level9.level10.level11.level12");
XCTAssertEqualObjects(labels[@"srg_title"], @"Automatic tracking with many levels");
XCTAssertEqualObjects(labels[@"srg_title"], @"automatic-tracking-with-many-levels");
XCTAssertEqualObjects(labels[@"ns_type"], @"view");
return YES;
}];
Expand All @@ -157,7 +157,7 @@ - (void)testAutomaticTrackingWithLevelsAndCustomLabels
XCTAssertEqualObjects(labels[@"srg_n2"], @"level2");
XCTAssertNil(labels[@"srg_n3"]);
XCTAssertEqualObjects(labels[@"category"], @"level1.level2");
XCTAssertEqualObjects(labels[@"srg_title"], @"Automatic tracking with levels and custom labels");
XCTAssertEqualObjects(labels[@"srg_title"], @"automatic-tracking-with-levels-and-custom-labels");
XCTAssertEqualObjects(labels[@"ns_type"], @"view");
XCTAssertEqualObjects(labels[@"custom_label"], @"custom_value");
return YES;
Expand All @@ -179,7 +179,7 @@ - (void)testManualTracking
XCTAssertEqualObjects(labels[@"srg_n1"], @"app");
XCTAssertNil(labels[@"srg_n2"]);
XCTAssertEqualObjects(labels[@"category"], @"app");
XCTAssertEqualObjects(labels[@"srg_title"], @"Manual tracking");
XCTAssertEqualObjects(labels[@"srg_title"], @"manual-tracking");
XCTAssertEqualObjects(labels[@"ns_type"], @"view");
return YES;
}];
Expand Down
89 changes: 46 additions & 43 deletions Framework/Sources/Core/SRGAnalyticsTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ - (void)trackPageViewTitle:(NSString *)title levels:(NSArray<NSString *> *)level
}

NSMutableDictionary *labels = [NSMutableDictionary dictionary];
[labels safeSetValue:title.srg_comScoreTitleFormattedString forKey:@"srg_title"];
[labels safeSetValue:title.srg_comScoreFormattedString forKey:@"srg_title"];
[labels safeSetValue:@(fromPushNotification) forKey:@"srg_ap_push"];

NSString *category = @"app";
Expand Down Expand Up @@ -188,10 +188,10 @@ - (void)trackHiddenEventWithTitle:(NSString *)title customLabels:(NSDictionary *
}

NSMutableDictionary *labels = [NSMutableDictionary dictionary];
[labels safeSetValue:title.srg_comScoreTitleFormattedString forKey:@"srg_title"];
[labels safeSetValue:title.srg_comScoreFormattedString forKey:@"srg_title"];

[labels safeSetValue:@"app" forKey:@"category"];
[labels safeSetValue:[NSString stringWithFormat:@"app.%@", title].srg_comScoreTitleFormattedString forKey:@"name"];
[labels safeSetValue:[NSString stringWithFormat:@"app.%@", title.srg_comScoreFormattedString] forKey:@"name"];

[customLabels enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
[labels safeSetValue:[obj description] forKey:[key description]];
Expand Down Expand Up @@ -225,51 +225,54 @@ - (void)sendApplicationList
}
NSArray<NSDictionary *> *applicationDictionaries = JSONObject;

// Extract URL schemes and installed applications
NSMutableSet<NSString *> *URLSchemes = [NSMutableSet set];
NSMutableSet<NSString *> *installedApplications = [NSMutableSet set];
for (NSDictionary *applicationDictionary in applicationDictionaries) {
NSString *application = applicationDictionary[@"code"];
NSString *URLScheme = applicationDictionary[@"ios"];

if (URLScheme.length == 0 || ! application) {
SRGAnalyticsLogInfo(@"tracker", @"URL scheme or application name missing in %@. Skipped", applicationDictionary);
continue;
// -canOpenURL: should only be called from the main thread
dispatch_async(dispatch_get_main_queue(), ^{
// Extract URL schemes and installed applications
NSMutableSet<NSString *> *URLSchemes = [NSMutableSet set];
NSMutableSet<NSString *> *installedApplications = [NSMutableSet set];
for (NSDictionary *applicationDictionary in applicationDictionaries) {
NSString *application = applicationDictionary[@"code"];
NSString *URLScheme = applicationDictionary[@"ios"];

if (URLScheme.length == 0 || ! application) {
SRGAnalyticsLogInfo(@"tracker", @"URL scheme or application name missing in %@. Skipped", applicationDictionary);
continue;
}

[URLSchemes addObject:URLScheme];

NSString *URLString = [NSString stringWithFormat:@"%@://probe-for-srganalytics", URLScheme];
if (! [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:URLString]]) {
continue;
}

[installedApplications addObject:application];
}

[URLSchemes addObject:URLScheme];
// Since iOS 9, to be able to open a URL in another application (and thus to be able to test for URL scheme
// support), the application must declare the schemes it supports via its Info.plist file (under the
// `LSApplicationQueriesSchemes` key). If we are running on iOS 9 or above, check that the app list is consistent
// with the remote list, and log an error if this is not the case
NSArray<NSString *> *declaredURLSchemesArray = [NSBundle mainBundle].infoDictionary[@"LSApplicationQueriesSchemes"];
NSSet<NSString *> *declaredURLSchemes = declaredURLSchemesArray ? [NSSet setWithArray:declaredURLSchemesArray] : [NSSet set];
if (! [URLSchemes isSubsetOfSet:declaredURLSchemes]) {
SRGAnalyticsLogError(@"tracker", @"The URL schemes declared in your application Info.plist file under the "
"'LSApplicationQueriesSchemes' key must at list contain the scheme list available at "
"https://pastebin.com/raw/RnZYEWCA (the schemes are found under the 'ios' key, or "
"a script is available in the SRGAnalytics repository to collect it). Please "
"update your Info.plist file to make this message disappear");
}

NSString *URLString = [NSString stringWithFormat:@"%@://probe-for-srganalytics", URLScheme];
if (! [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:URLString]]) {
continue;
if (installedApplications.count == 0) {
SRGAnalyticsLogWarning(@"tracker", @"No identified application installed. Nothing to be done");
return;
}

[installedApplications addObject:application];
}

// Since iOS 9, to be able to open a URL in another application (and thus to be able to test for URL scheme
// support), the application must declare the schemes it supports via its Info.plist file (under the
// `LSApplicationQueriesSchemes` key). If we are running on iOS 9 or above, check that the app list is consistent
// with the remote list, and log an error if this is not the case
NSArray<NSString *> *declaredURLSchemesArray = [NSBundle mainBundle].infoDictionary[@"LSApplicationQueriesSchemes"];
NSSet<NSString *> *declaredURLSchemes = declaredURLSchemesArray ? [NSSet setWithArray:declaredURLSchemesArray] : [NSSet set];
if (! [URLSchemes isSubsetOfSet:declaredURLSchemes]) {
SRGAnalyticsLogError(@"tracker", @"The URL schemes declared in your application Info.plist file under the "
"'LSApplicationQueriesSchemes' key must at list contain the scheme list available at "
"https://pastebin.com/raw/RnZYEWCA (the schemes are found under the 'ios' key, or "
"a script is available in the SRGAnalytics repository to collect it). Please "
"update your Info.plist file to make this message disappear");
}

if (installedApplications.count == 0) {
SRGAnalyticsLogWarning(@"tracker", @"No identified application installed. Nothing to be done");
return;
}

NSArray *sortedInstalledApplications = [installedApplications.allObjects sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
NSDictionary *labels = @{ @"srg_evgroup" : @"Installed Apps",
@"srg_evname" : [sortedInstalledApplications componentsJoinedByString:@","] };
[CSComScore hiddenWithLabels:labels];
NSArray *sortedInstalledApplications = [installedApplications.allObjects sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
NSDictionary *labels = @{ @"srg_evgroup" : @"Installed Apps",
@"srg_evname" : [sortedInstalledApplications componentsJoinedByString:@","] };
[CSComScore hiddenWithLabels:labels];
});
}] resume];
}

Expand Down
1 change: 0 additions & 1 deletion Framework/Sources/Helpers/NSString+SRGAnalytics.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ NS_ASSUME_NONNULL_BEGIN
/**
* Format the receiver in a standard way.
*/
@property (nonatomic, readonly, copy, nullable) NSString *srg_comScoreTitleFormattedString;
@property (nonatomic, readonly, copy, nullable) NSString *srg_comScoreFormattedString;

@end
Expand Down
25 changes: 12 additions & 13 deletions Framework/Sources/Helpers/NSString+SRGAnalytics.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,22 @@

@implementation NSString (SRGAnalytics)

- (NSString *)srg_comScoreTitleFormattedString
{
NSCharacterSet *andSet = [NSCharacterSet characterSetWithCharactersInString:@"+&"];
NSCharacterSet *strokeSet = [NSCharacterSet characterSetWithCharactersInString:@"=/\\<>()"];
NSString *title = [[self componentsSeparatedByCharactersInSet:strokeSet] componentsJoinedByString:@"-"];
return [[title componentsSeparatedByCharactersInSet:andSet] componentsJoinedByString:@"and"];
}

- (NSString *)srg_comScoreFormattedString
{
// Remove accentuated characters
NSLocale *posixLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
NSRegularExpression *regexp = [NSRegularExpression regularExpressionWithPattern:@"[^a-z0-9 -]" options:0 error:nil];
NSString *normalizedString = [self.lowercaseString stringByFoldingWithOptions:NSDiacriticInsensitiveSearch locale:posixLocale];

// See rules at https://srfmmz.atlassian.net/wiki/display/SRGPLAY/Measurement+of+SRG+Player+Apps
NSCharacterSet *andSet = [NSCharacterSet characterSetWithCharactersInString:@"+&"];
normalizedString = [[normalizedString componentsSeparatedByCharactersInSet:andSet] componentsJoinedByString:@"and"];

// Squash all non-alphanumeric characters as a single hyphen
NSRegularExpression *regularExpression = [NSRegularExpression regularExpressionWithPattern:@"[^a-z0-9]+" options:0 error:NULL];
normalizedString = [regularExpression stringByReplacingMatchesInString:normalizedString options:0 range:NSMakeRange(0, normalizedString.length) withTemplate:@"-"];

NSString *normalizedString = [[self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] lowercaseString];
normalizedString = [normalizedString stringByFoldingWithOptions:NSDiacriticInsensitiveSearch locale:posixLocale];
normalizedString = [regexp stringByReplacingMatchesInString:normalizedString options:0 range:NSMakeRange(0, [normalizedString length]) withTemplate:@""];
return [normalizedString stringByReplacingOccurrencesOfString:@" " withString:@"-"];
// Trim hyphens at both ends, if any
return [normalizedString stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"-"]];
}

@end
Loading

0 comments on commit b690a83

Please sign in to comment.