Skip to content

Commit 746f500

Browse files
author
Brandon Sneed
committed
Fixes compile issues w/ latest Amplitude-iOS
1 parent 0dc24b1 commit 746f500

10 files changed

+138
-33
lines changed

Example/Podfile

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
source 'https://github.com/CocoaPods/Specs.git'
22
platform :ios, '10.0'
3-
plugin 'cocoapods-repo-update'
43

54
# Do not use_frameworks due to iOS 7 support
65
# use_frameworks!

Example/Podfile.lock

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
PODS:
2-
- Amplitude (5.2.1)
3-
- Analytics (4.0.3)
2+
- Amplitude (7.0.1)
3+
- Analytics (4.0.5)
44
- Expecta (1.0.6)
55
- OCHamcrest (7.1.2)
66
- OCMockito (5.1.3):
77
- OCHamcrest (~> 7.0)
8-
- Segment-Amplitude (3.0.2):
8+
- Segment-Amplitude (3.2.0):
99
- Amplitude
1010
- Analytics
1111
- Specta (1.0.7)
@@ -30,14 +30,14 @@ EXTERNAL SOURCES:
3030
:path: "../"
3131

3232
SPEC CHECKSUMS:
33-
Amplitude: 9774e93d48d9f41f271a4479e06369a30ab31db1
34-
Analytics: 54b0551629871648686cb4ee1d243bf4f703f2c2
33+
Amplitude: 31a9038dca905b78294418ed277da9c2e07658ad
34+
Analytics: 4bcf052c91e1f3339219e83d6a036fb2bd7c218d
3535
Expecta: 3b6bd90a64b9a1dcb0b70aa0e10a7f8f631667d5
3636
OCHamcrest: b284c9592c28c1e4025a8542e67ea41a635d0d73
3737
OCMockito: 677cbb4a18fd492b5a4fb10144dada4de5ddb877
38-
Segment-Amplitude: 4dacdc8b53bd30ee39a936f5024c7d5ed626879b
38+
Segment-Amplitude: 300e2888691b75b8364389b2c242f6b953932945
3939
Specta: 3e1bd89c3517421982dc4d1c992503e48bd5fe66
4040

4141
PODFILE CHECKSUM: a7bf6ef16f54033a66dc8c09524260667af4e881
4242

43-
COCOAPODS: 1.9.1
43+
COCOAPODS: 1.10.0.rc.1

Example/Segment-Amplitude.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
6003F5BA195388D20070C39A /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6003F5B8195388D20070C39A /* InfoPlist.strings */; };
2323
6003F5BC195388D20070C39A /* Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6003F5BB195388D20070C39A /* Tests.m */; };
2424
873B8AEB1B1F5CCA007FD442 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 873B8AEA1B1F5CCA007FD442 /* Main.storyboard */; };
25+
A3585CD2251BCF0A00F46088 /* TestSetupBlock.m in Sources */ = {isa = PBXBuildFile; fileRef = A3585CD1251BCF0A00F46088 /* TestSetupBlock.m */; };
2526
CE22D33DED2C8C1F20382F06 /* libPods-Segment-Amplitude_Example.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A31B91CBBB7876EE6D25775 /* libPods-Segment-Amplitude_Example.a */; };
2627
/* End PBXBuildFile section */
2728

@@ -63,6 +64,7 @@
6364
91AECAC26A53C35405CA5402 /* Pods-Segment-Amplitude_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Segment-Amplitude_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-Segment-Amplitude_Example/Pods-Segment-Amplitude_Example.release.xcconfig"; sourceTree = "<group>"; };
6465
97DEF26D0B2C6B8BB484FE4F /* Pods-Segment-Amplitude_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Segment-Amplitude_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Segment-Amplitude_Tests/Pods-Segment-Amplitude_Tests.debug.xcconfig"; sourceTree = "<group>"; };
6566
9EEA123C7A20DF690C5D6E46 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
67+
A3585CD1251BCF0A00F46088 /* TestSetupBlock.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TestSetupBlock.m; sourceTree = "<group>"; };
6668
D499617867A9269C55AA5760 /* Pods_Segment_Amplitude_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Segment_Amplitude_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6769
F26E1DEACA3B4F2A695BCDD1 /* Segment-Amplitude.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = "Segment-Amplitude.podspec"; path = "../Segment-Amplitude.podspec"; sourceTree = "<group>"; };
6870
/* End PBXFileReference section */
@@ -168,6 +170,7 @@
168170
isa = PBXGroup;
169171
children = (
170172
6003F5BB195388D20070C39A /* Tests.m */,
173+
A3585CD1251BCF0A00F46088 /* TestSetupBlock.m */,
171174
6003F5B6195388D20070C39A /* Supporting Files */,
172175
);
173176
path = Tests;
@@ -391,6 +394,7 @@
391394
buildActionMask = 2147483647;
392395
files = (
393396
6003F5BC195388D20070C39A /* Tests.m in Sources */,
397+
A3585CD2251BCF0A00F46088 /* TestSetupBlock.m in Sources */,
394398
);
395399
runOnlyForDeploymentPostprocessing = 0;
396400
};

Example/Tests/TestSetupBlock.m

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//
2+
// TestSetupBlock.m
3+
// Segment-Amplitude_Tests
4+
//
5+
// Created by Brandon Sneed on 9/23/20.
6+
// Copyright © 2020 Prateek Srivastava. All rights reserved.
7+
//
8+
9+
#import <XCTest/XCTest.h>
10+
11+
#import "SEGAmplitudeIntegrationFactory.h"
12+
13+
@interface TestSetupBlock : XCTestCase
14+
15+
@end
16+
17+
@implementation TestSetupBlock
18+
19+
- (void)setUp {
20+
// Put setup code here. This method is called before the invocation of each test method in the class.
21+
}
22+
23+
- (void)tearDown {
24+
// Put teardown code here. This method is called after the invocation of each test method in the class.
25+
}
26+
27+
- (void)testSetupBlockCalled {
28+
__block Amplitude *amp = nil;
29+
30+
SEGAmplitudeIntegrationFactory *factory = [SEGAmplitudeIntegrationFactory instanceWithSetupBlock:^(Amplitude *amplitude) {
31+
amp = amplitude;
32+
amplitude.adSupportBlock = ^NSString * _Nonnull{
33+
return @"1234";
34+
};
35+
amplitude.locationInfoBlock = ^NSDictionary * _Nullable{
36+
return @{
37+
@"lat" : @37.7,
38+
@"lng" : @122.4
39+
};
40+
};
41+
}];
42+
43+
SEGAnalytics *analytics = [[SEGAnalytics alloc] init];
44+
SEGAmplitudeIntegration *integration = [factory createWithSettings:@{} forAnalytics:analytics];
45+
46+
XCTAssertTrue(amp != nil);
47+
XCTAssertTrue(amp.adSupportBlock != nil);
48+
XCTAssertTrue(amp.locationInfoBlock != nil);
49+
50+
NSString *idfa = amp.adSupportBlock();
51+
NSDictionary *location = amp.locationInfoBlock();
52+
53+
XCTAssertTrue([idfa isEqualToString:@"1234"]);
54+
XCTAssertTrue([[location objectForKey:@"lat"] isEqual:@37.7]);
55+
}
56+
57+
@end

Example/Tests/Tests.m

+19-15
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
amplitude = mock([Amplitude class]);
4242
amprevenue = mock([AMPRevenue class]);
4343
identify = mock([AMPIdentify class]);
44-
integration = [[SEGAmplitudeIntegration alloc] initWithSettings:@{} andAmplitude:amplitude andAmpRevenue:amprevenue andAmpIdentify:identify];
44+
integration = [[SEGAmplitudeIntegration alloc] initWithSettings:@{} andAmplitude:amplitude andAmpRevenue:amprevenue andAmpIdentify:identify setupBlock:nil];
4545
});
4646

4747
describe(@"Identify", ^{
@@ -51,7 +51,8 @@
5151
@"traitsToSetOnce" : [NSNull null] }
5252
andAmplitude:amplitude
5353
andAmpRevenue:amprevenue
54-
andAmpIdentify:identify];
54+
andAmpIdentify:identify
55+
setupBlock:nil];
5556
SEGIdentifyPayload *payload = [[SEGIdentifyPayload alloc] initWithUserId:@"1111" anonymousId:nil traits:@{} context:@{} integrations:@{}];
5657

5758
[integration identify:payload];
@@ -63,7 +64,8 @@
6364
@"traitsToSetOnce" : @[] }
6465
andAmplitude:amplitude
6566
andAmpRevenue:amprevenue
66-
andAmpIdentify:identify];
67+
andAmpIdentify:identify
68+
setupBlock:nil];
6769
SEGIdentifyPayload *payload = [[SEGIdentifyPayload alloc] initWithUserId:@"7891" anonymousId:nil traits:@{
6870
@"name" : @"George Costanza",
6971
@"gender" : @"male",
@@ -91,7 +93,7 @@
9193
});
9294

9395
it(@"increments identify trait", ^{
94-
integration = [[SEGAmplitudeIntegration alloc] initWithSettings:@{ @"traitsToIncrement" : @[ @"karma", @"store_credit" ] } andAmplitude:amplitude andAmpRevenue:amprevenue andAmpIdentify:identify];
96+
integration = [[SEGAmplitudeIntegration alloc] initWithSettings:@{ @"traitsToIncrement" : @[ @"karma", @"store_credit" ] } andAmplitude:amplitude andAmpRevenue:amprevenue andAmpIdentify:identify setupBlock:nil];
9597

9698
SEGIdentifyPayload *payload = [[SEGIdentifyPayload alloc] initWithUserId:@"3290842" anonymousId:nil traits:@{ @"karma" : @0.23,
9799
@"store_credit" : @20,
@@ -106,7 +108,7 @@
106108
});
107109

108110
it(@"sets identify trait once", ^{
109-
integration = [[SEGAmplitudeIntegration alloc] initWithSettings:@{ @"traitsToSetOnce" : @[ @"sign_up_date" ] } andAmplitude:amplitude andAmpRevenue:amprevenue andAmpIdentify:identify];
111+
integration = [[SEGAmplitudeIntegration alloc] initWithSettings:@{ @"traitsToSetOnce" : @[ @"sign_up_date" ] } andAmplitude:amplitude andAmpRevenue:amprevenue andAmpIdentify:identify setupBlock:nil];
110112

111113
SEGIdentifyPayload *payload = [[SEGIdentifyPayload alloc] initWithUserId:@"3290842" anonymousId:nil traits:@{ @"sign_up_date" : @"2015-08-24",
112114
@"city" : @"los angeles" }
@@ -123,7 +125,8 @@
123125
@"traitsToIncrement" : @[ @"age" ] }
124126
andAmplitude:amplitude
125127
andAmpRevenue:amprevenue
126-
andAmpIdentify:identify];
128+
andAmpIdentify:identify
129+
setupBlock:nil];
127130

128131
SEGIdentifyPayload *payload = [[SEGIdentifyPayload alloc] initWithUserId:@"3290842" anonymousId:nil traits:@{ @"address" : @{
129132
@"street" : @"California st",
@@ -149,23 +152,23 @@
149152

150153
describe(@"Screen", ^{
151154
it(@"does not call screen if trackAllPages = false", ^{
152-
integration = [[SEGAmplitudeIntegration alloc] initWithSettings:@{ @"trackAllPages" : @false } andAmplitude:amplitude andAmpRevenue:amprevenue andAmpIdentify:identify];
155+
integration = [[SEGAmplitudeIntegration alloc] initWithSettings:@{ @"trackAllPages" : @false } andAmplitude:amplitude andAmpRevenue:amprevenue andAmpIdentify:identify setupBlock:nil];
153156

154157
SEGScreenPayload *payload = [[SEGScreenPayload alloc] initWithName:@"Shirts" properties:@{} context:@{} integrations:@{}];
155158
[integration screen:payload];
156159
[verifyCount(amplitude, never()) logEvent:@"Viewed Shirts Screen" withEventProperties:@{}];
157160
});
158161

159162
it(@"trackAllPages", ^{
160-
integration = [[SEGAmplitudeIntegration alloc] initWithSettings:@{ @"trackAllPages" : @true } andAmplitude:amplitude andAmpRevenue:amprevenue andAmpIdentify:identify];
163+
integration = [[SEGAmplitudeIntegration alloc] initWithSettings:@{ @"trackAllPages" : @true } andAmplitude:amplitude andAmpRevenue:amprevenue andAmpIdentify:identify setupBlock:nil];
161164

162165
SEGScreenPayload *payload = [[SEGScreenPayload alloc] initWithName:@"Shirts" properties:@{} context:@{} integrations:@{}];
163166
[integration screen:payload];
164167
[verify(amplitude) logEvent:@"Viewed Shirts Screen" withEventProperties:@{} withGroups:nil outOfSession:false];
165168
});
166169

167170
it(@"trackAllPagesV2", ^{
168-
integration = [[SEGAmplitudeIntegration alloc] initWithSettings:@{ @"trackAllPagesV2" : @true } andAmplitude:amplitude andAmpRevenue:amprevenue andAmpIdentify:identify];
171+
integration = [[SEGAmplitudeIntegration alloc] initWithSettings:@{ @"trackAllPagesV2" : @true } andAmplitude:amplitude andAmpRevenue:amprevenue andAmpIdentify:identify setupBlock:nil];
169172

170173
SEGScreenPayload *payload = [[SEGScreenPayload alloc] initWithName:@"Shirts" properties:@{ @"url" : @"seinfeld.wikia.com/wiki/The_Puffy_Shirt",
171174
@"Feed Type" : @"private" }
@@ -191,7 +194,8 @@
191194
@"groupTypeTrait" : @"industry" }
192195
andAmplitude:amplitude
193196
andAmpRevenue:amprevenue
194-
andAmpIdentify:identify];
197+
andAmpIdentify:identify
198+
setupBlock:nil];
195199
SEGGroupPayload *payload = [[SEGGroupPayload alloc] initWithGroupId:@"32423084" traits:@{
196200
@"company" : @"Segment",
197201
@"industry" : @"Technology"
@@ -289,7 +293,7 @@
289293

290294

291295
it(@"tracks Order Completed with revenue if both total and revenue are present", ^{
292-
integration = [[SEGAmplitudeIntegration alloc] initWithSettings:@{ @"useLogRevenueV2" : @true } andAmplitude:amplitude andAmpRevenue:amprevenue andAmpIdentify:identify];
296+
integration = [[SEGAmplitudeIntegration alloc] initWithSettings:@{ @"useLogRevenueV2" : @true } andAmplitude:amplitude andAmpRevenue:amprevenue andAmpIdentify:identify setupBlock:nil];
293297

294298
NSDictionary *props = @{
295299
@"checkout_id" : @"9bcf000000000000",
@@ -321,7 +325,7 @@
321325
});
322326

323327
it(@"tracks Order Completed with total if revenue is not present", ^{
324-
integration = [[SEGAmplitudeIntegration alloc] initWithSettings:@{ @"useLogRevenueV2" : @true } andAmplitude:amplitude andAmpRevenue:amprevenue andAmpIdentify:identify];
328+
integration = [[SEGAmplitudeIntegration alloc] initWithSettings:@{ @"useLogRevenueV2" : @true } andAmplitude:amplitude andAmpRevenue:amprevenue andAmpIdentify:identify setupBlock:nil];
325329

326330
NSDictionary *props = @{
327331
@"checkout_id" : @"9bcf000000000000",
@@ -353,7 +357,7 @@
353357
});
354358

355359
it(@"tracks Order Completed with revenue of type String", ^{
356-
integration = [[SEGAmplitudeIntegration alloc] initWithSettings:@{ @"useLogRevenueV2" : @true } andAmplitude:amplitude andAmpRevenue:amprevenue andAmpIdentify:identify];
360+
integration = [[SEGAmplitudeIntegration alloc] initWithSettings:@{ @"useLogRevenueV2" : @true } andAmplitude:amplitude andAmpRevenue:amprevenue andAmpIdentify:identify setupBlock:nil];
357361

358362
NSDictionary *props = @{
359363
@"checkout_id" : @"9bcf000000000000",
@@ -386,7 +390,7 @@
386390

387391
// NOTE: This is against our spec. We do not have a v1/v2 ECommerce event that sends both revenue and price/quantity as a tope level property
388392
it(@"tracks with top level price and quantity", ^{
389-
integration = [[SEGAmplitudeIntegration alloc] initWithSettings:@{ @"useLogRevenueV2" : @true } andAmplitude:amplitude andAmpRevenue:amprevenue andAmpIdentify:identify];
393+
integration = [[SEGAmplitudeIntegration alloc] initWithSettings:@{ @"useLogRevenueV2" : @true } andAmplitude:amplitude andAmpRevenue:amprevenue andAmpIdentify:identify setupBlock:nil];
390394

391395
SEGTrackPayload *payload = [[SEGTrackPayload alloc] initWithEvent:@"Viewed Product" properties:@{
392396
@"revenue" : @20.99,
@@ -406,7 +410,7 @@
406410
});
407411

408412
it(@"tracks Amplitude ecommerce fields", ^{
409-
integration = [[SEGAmplitudeIntegration alloc] initWithSettings:@{ @"useLogRevenueV2" : @true } andAmplitude:amplitude andAmpRevenue:amprevenue andAmpIdentify:identify];
413+
integration = [[SEGAmplitudeIntegration alloc] initWithSettings:@{ @"useLogRevenueV2" : @true } andAmplitude:amplitude andAmpRevenue:amprevenue andAmpIdentify:identify setupBlock:nil];
410414

411415
SEGTrackPayload *payload = [[SEGTrackPayload alloc] initWithEvent:@"Viewed Product" properties:@{
412416
@"revenue" : @20.00,

Pod/Classes/SEGAmplitudeIntegration.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#import <Amplitude/Amplitude.h>
1010
#endif
1111

12+
typedef void(^SEGAmplitudeSetupBlock)(Amplitude *amplitude);
1213

1314
@interface SEGAmplitudeIntegration : NSObject <SEGIntegration>
1415

@@ -19,7 +20,7 @@
1920
@property NSSet *traitsToIncrement;
2021
@property NSSet *traitsToSetOnce;
2122

22-
- (id)initWithSettings:(NSDictionary *)settings;
23-
- (id)initWithSettings:(NSDictionary *)settings andAmplitude:(Amplitude *)amplitude andAmpRevenue:(AMPRevenue *)amprevenue andAmpIdentify:(AMPIdentify *)identify;
23+
- (id)initWithSettings:(NSDictionary *)settings setupBlock:(SEGAmplitudeSetupBlock)setupBlock;
24+
- (id)initWithSettings:(NSDictionary *)settings andAmplitude:(Amplitude *)amplitude andAmpRevenue:(AMPRevenue *)amprevenue andAmpIdentify:(AMPIdentify *)identify setupBlock:(SEGAmplitudeSetupBlock)setupBlock;
2425

2526
@end

Pod/Classes/SEGAmplitudeIntegration.m

+11-5
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
@implementation SEGAmplitudeIntegration
66

7-
- (id)initWithSettings:(NSDictionary *)settings
7+
- (id)initWithSettings:(NSDictionary *)settings setupBlock:(SEGAmplitudeSetupBlock)setupBlock
88
{
9-
return [self initWithSettings:settings andAmplitude:[Amplitude instance] andAmpRevenue:[AMPRevenue revenue] andAmpIdentify:[AMPIdentify identify]];
9+
return [self initWithSettings:settings andAmplitude:[Amplitude instance] andAmpRevenue:[AMPRevenue revenue] andAmpIdentify:[AMPIdentify identify] setupBlock:setupBlock];
1010
}
1111

12-
- (id)initWithSettings:(NSDictionary *)settings andAmplitude:(Amplitude *)amplitude andAmpRevenue:(AMPRevenue *)amprevenue andAmpIdentify:(AMPIdentify *)identify
12+
- (id)initWithSettings:(NSDictionary *)settings andAmplitude:(Amplitude *)amplitude andAmpRevenue:(AMPRevenue *)amprevenue andAmpIdentify:(AMPIdentify *)identify setupBlock:(SEGAmplitudeSetupBlock)setupBlock
1313
{
1414
if (self = [super init]) {
1515
self.settings = settings;
@@ -24,15 +24,17 @@ - (id)initWithSettings:(NSDictionary *)settings andAmplitude:(Amplitude *)amplit
2424
self.traitsToSetOnce = [NSSet setWithArray:self.settings[@"traitsToSetOnce"]];
2525
}
2626

27+
// NOTE: As of Amplitude-iOS 7.0.1, this is no longer available. A callback is used instead.
28+
2729
// Amplitude states that if you want location tracking disabled on startup of the app,
2830
// Call before initializing the apiKey
29-
if ([(NSNumber *)self.settings[@"enableLocationListening"] boolValue]) {
31+
/*if ([(NSNumber *)self.settings[@"enableLocationListening"] boolValue]) {
3032
[self.amplitude enableLocationListening];
3133
SEGLog(@"[Ampltidue enableLocationListening]");
3234
} else {
3335
[self.amplitude disableLocationListening];
3436
SEGLog(@"[Ampltidue disableLocationListening]");
35-
}
37+
}*/
3638

3739
NSString *apiKey = self.settings[@"apiKey"];
3840
[self.amplitude initializeApiKey:apiKey];
@@ -46,6 +48,10 @@ - (id)initWithSettings:(NSDictionary *)settings andAmplitude:(Amplitude *)amplit
4648
if ([(NSNumber *)self.settings[@"useAdvertisingIdForDeviceId"] boolValue]) {
4749
[self.amplitude useAdvertisingIdForDeviceId];
4850
}
51+
52+
if (setupBlock != nil) {
53+
setupBlock(self.amplitude);
54+
}
4955
}
5056
return self;
5157
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,33 @@
11
#import <Foundation/Foundation.h>
22
#import <Analytics/Analytics.h>
33

4+
#import "SEGAmplitudeIntegration.h"
5+
46

57
@interface SEGAmplitudeIntegrationFactory : NSObject <SEGIntegrationFactory>
68

79
+ (instancetype)instance;
810

11+
/**
12+
This method can be used to set Amplitude's adSupportBlock and locationInfoBlock.
13+
14+
Example:
15+
16+
SEGAmplitudeIntegrationFactory *factory = [SEGAmplitudeIntegrationFactory instanceWithSetupBlock:^{
17+
amplitude.adSupportBlock = ^{
18+
return [[ASIdentifierManager sharedManager] advertisingIdentifier];
19+
};
20+
amplitude.locationInfoBlock = ^{
21+
return @{
22+
@"lat" : @37.7,
23+
@"lng" : @122.4
24+
};
25+
};
26+
}];
27+
...
28+
[analyticsConfiguration use:factory];
29+
30+
*/
31+
+ (instancetype)instanceWithSetupBlock:(SEGAmplitudeSetupBlock)setupBlock;
32+
933
@end

0 commit comments

Comments
 (0)