Skip to content

Commit 0916872

Browse files
committed
recover Amplitude etc for examples
1 parent 1b3012c commit 0916872

File tree

7 files changed

+238
-36
lines changed

7 files changed

+238
-36
lines changed

DemoObjCApp/AppDelegate.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
#import "CustomLogger.h"
1313

1414
@import Optimizely;
15+
#if TARGET_OS_IOS
16+
@import Amplitude_iOS;
17+
#endif
18+
1519

1620
static NSString * const kOptimizelySdkKey = @"FCnSegiEkRry9rhVMroit4";
1721
static NSString * const kOptimizelyDatafileName = @"demoTestDatafile";
@@ -27,6 +31,11 @@ @interface AppDelegate ()
2731
@implementation AppDelegate
2832

2933
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
34+
// most of the third-party integrations only support iOS, so the sample code is only targeted for iOS builds
35+
#if TARGET_OS_IOS
36+
37+
#endif
38+
3039
self.userId = [NSString stringWithFormat:@"%d", arc4random()];
3140
self.attributes = @{ @"browser_type": @"safari", @"bool_attr": @(false) };
3241

@@ -115,6 +124,16 @@ -(void)initializeOptimizelySDKWithCustomization {
115124
NSString *userId,
116125
NSDictionary<NSString *,id> *attributes, NSDictionary<NSString *,id> *eventTags, NSDictionary<NSString *,id> *event) {
117126
NSLog(@"Received track notification: %@ %@ %@ %@ %@", eventKey, userId, attributes, eventTags, event);
127+
128+
#if TARGET_OS_IOS
129+
// Amplitude example
130+
NSString *propertyKey = [NSString stringWithFormat:@"[Optimizely] %@", eventKey];
131+
AMPIdentify *identify = [[AMPIdentify alloc] init];
132+
[identify set:propertyKey value:userId];
133+
// Track event (optional)
134+
NSString *eventIdentifier = [NSString stringWithFormat:@"[Optimizely] %@ - %@", eventKey, userId];
135+
[Amplitude.instance logEvent:eventIdentifier];
136+
#endif
118137
}];
119138

120139
[self.optimizely startSDKWithCompletion:^(NSData *data, NSError *error) {

DemoObjCApp/DemoObjcApp.xcodeproj/project.pbxproj

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10-
6923C05F4FFD7394581F4361 /* libPods-DemoObjctvOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2CE090EEBD47E05884C417C0 /* libPods-DemoObjctvOS.a */; };
10+
2EDC4E2400B5EEBA576A62F5 /* Pods_DemoObjciOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E74A6F66A7FA658F00BDB921 /* Pods_DemoObjciOS.framework */; };
1111
6E4DD7F721E51E5500B0C2C7 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EF7499F21E404BC008B22A0 /* main.m */; };
1212
6E4DD7F821E51E5600B0C2C7 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EF7499F21E404BC008B22A0 /* main.m */; };
1313
6E4DD97C21E67AAD00B0C2C7 /* Optimizely.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6E4DD97521E67A6500B0C2C7 /* Optimizely.framework */; };
@@ -34,7 +34,7 @@
3434
6E9681D921EFA5B2009B7FEC /* CustomLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E9681D721EFA5B2009B7FEC /* CustomLogger.m */; };
3535
6EB8456B21EE5DE3005346CC /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EB8456421EE5DE3005346CC /* AppDelegate.m */; };
3636
6EB8456C21EE5DE3005346CC /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EB8456421EE5DE3005346CC /* AppDelegate.m */; };
37-
C2E08E88D2C89768C7551208 /* libPods-DemoObjciOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DB76E67DE203C5276D6958C5 /* libPods-DemoObjciOS.a */; };
37+
A0C60F82A88EDB74234D7D3F /* Pods_DemoObjctvOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 48C9592909E0CF5074F9A84D /* Pods_DemoObjctvOS.framework */; };
3838
/* End PBXBuildFile section */
3939

4040
/* Begin PBXContainerItemProxy section */
@@ -164,8 +164,8 @@
164164
/* End PBXCopyFilesBuildPhase section */
165165

166166
/* Begin PBXFileReference section */
167-
2CE090EEBD47E05884C417C0 /* libPods-DemoObjctvOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-DemoObjctvOS.a"; sourceTree = BUILT_PRODUCTS_DIR; };
168167
3EFD1578D8AB431E6FD4B8FE /* Pods-DemoObjctvOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DemoObjctvOS.debug.xcconfig"; path = "../Pods/Target Support Files/Pods-DemoObjctvOS/Pods-DemoObjctvOS.debug.xcconfig"; sourceTree = "<group>"; };
168+
48C9592909E0CF5074F9A84D /* Pods_DemoObjctvOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_DemoObjctvOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
169169
6E4DD96D21E67A6500B0C2C7 /* OptimizelySwiftSDK.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = OptimizelySwiftSDK.xcodeproj; path = ../OptimizelySDK/OptimizelySwiftSDK.xcodeproj; sourceTree = "<group>"; };
170170
6E96817521EEA321009B7FEC /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/tvOSMain.storyboard; sourceTree = "<group>"; };
171171
6E96817621EEA321009B7FEC /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -192,7 +192,7 @@
192192
762D1F9E4AA702083D17C4C9 /* Pods-DemoObjciOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DemoObjciOS.release.xcconfig"; path = "../Pods/Target Support Files/Pods-DemoObjciOS/Pods-DemoObjciOS.release.xcconfig"; sourceTree = "<group>"; };
193193
D47F5FC88600AFD4E656D50A /* Pods-DemoObjciOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DemoObjciOS.debug.xcconfig"; path = "../Pods/Target Support Files/Pods-DemoObjciOS/Pods-DemoObjciOS.debug.xcconfig"; sourceTree = "<group>"; };
194194
D58542E1B5771327083E56E2 /* Pods-DemoObjctvOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DemoObjctvOS.release.xcconfig"; path = "../Pods/Target Support Files/Pods-DemoObjctvOS/Pods-DemoObjctvOS.release.xcconfig"; sourceTree = "<group>"; };
195-
DB76E67DE203C5276D6958C5 /* libPods-DemoObjciOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-DemoObjciOS.a"; sourceTree = BUILT_PRODUCTS_DIR; };
195+
E74A6F66A7FA658F00BDB921 /* Pods_DemoObjciOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_DemoObjciOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
196196
/* End PBXFileReference section */
197197

198198
/* Begin PBXFrameworksBuildPhase section */
@@ -201,7 +201,7 @@
201201
buildActionMask = 2147483647;
202202
files = (
203203
6E4DD97C21E67AAD00B0C2C7 /* Optimizely.framework in Frameworks */,
204-
C2E08E88D2C89768C7551208 /* libPods-DemoObjciOS.a in Frameworks */,
204+
2EDC4E2400B5EEBA576A62F5 /* Pods_DemoObjciOS.framework in Frameworks */,
205205
);
206206
runOnlyForDeploymentPostprocessing = 0;
207207
};
@@ -210,7 +210,7 @@
210210
buildActionMask = 2147483647;
211211
files = (
212212
6E4DD98021E67ABA00B0C2C7 /* Optimizely.framework in Frameworks */,
213-
6923C05F4FFD7394581F4361 /* libPods-DemoObjctvOS.a in Frameworks */,
213+
A0C60F82A88EDB74234D7D3F /* Pods_DemoObjctvOS.framework in Frameworks */,
214214
);
215215
runOnlyForDeploymentPostprocessing = 0;
216216
};
@@ -335,8 +335,8 @@
335335
isa = PBXGroup;
336336
children = (
337337
6E4DD96D21E67A6500B0C2C7 /* OptimizelySwiftSDK.xcodeproj */,
338-
2CE090EEBD47E05884C417C0 /* libPods-DemoObjctvOS.a */,
339-
DB76E67DE203C5276D6958C5 /* libPods-DemoObjciOS.a */,
338+
E74A6F66A7FA658F00BDB921 /* Pods_DemoObjciOS.framework */,
339+
48C9592909E0CF5074F9A84D /* Pods_DemoObjctvOS.framework */,
340340
);
341341
name = Frameworks;
342342
sourceTree = "<group>";
@@ -364,6 +364,7 @@
364364
6EF7498B21E404BB008B22A0 /* Frameworks */,
365365
6EF7498C21E404BB008B22A0 /* Resources */,
366366
6E4DD93B21E6708E00B0C2C7 /* Embed Frameworks */,
367+
7493B4816C0BC9BAABDE8B5B /* [CP] Embed Pods Frameworks */,
367368
);
368369
buildRules = (
369370
);
@@ -601,6 +602,34 @@
601602
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
602603
showEnvVarsInLog = 0;
603604
};
605+
7493B4816C0BC9BAABDE8B5B /* [CP] Embed Pods Frameworks */ = {
606+
isa = PBXShellScriptBuildPhase;
607+
buildActionMask = 2147483647;
608+
files = (
609+
);
610+
inputFileListPaths = (
611+
);
612+
inputPaths = (
613+
"${PODS_ROOT}/Target Support Files/Pods-DemoObjciOS/Pods-DemoObjciOS-frameworks.sh",
614+
"${BUILT_PRODUCTS_DIR}/Amplitude-iOS/Amplitude_iOS.framework",
615+
"${BUILT_PRODUCTS_DIR}/GoogleToolboxForMac/GoogleToolboxForMac.framework",
616+
"${PODS_ROOT}/Localytics/Localytics-iOS-5.5.0/Localytics.framework",
617+
"${BUILT_PRODUCTS_DIR}/Mixpanel-swift/Mixpanel.framework",
618+
);
619+
name = "[CP] Embed Pods Frameworks";
620+
outputFileListPaths = (
621+
);
622+
outputPaths = (
623+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Amplitude_iOS.framework",
624+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GoogleToolboxForMac.framework",
625+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Localytics.framework",
626+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mixpanel.framework",
627+
);
628+
runOnlyForDeploymentPostprocessing = 0;
629+
shellPath = /bin/sh;
630+
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-DemoObjciOS/Pods-DemoObjciOS-frameworks.sh\"\n";
631+
showEnvVarsInLog = 0;
632+
};
604633
/* End PBXShellScriptBuildPhase section */
605634

606635
/* Begin PBXSourcesBuildPhase section */

DemoSwiftApp/AppDelegate.swift

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
import UIKit
1818
import Optimizely
19+
#if os(iOS)
20+
import Amplitude_iOS
21+
#endif
22+
1923

2024
@UIApplicationMain
2125
class AppDelegate: UIResponder, UIApplicationDelegate {
@@ -38,7 +42,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3842
}
3943

4044
func applicationDidFinishLaunching(_ application: UIApplication) {
41-
45+
// most of the third-party integrations only support iOS, so the sample code is only targeted for iOS builds
46+
#if os(iOS)
47+
Amplitude.instance().initializeApiKey("YOUR_API_KEY_HERE")
48+
#endif
49+
4250
// initialize SDK in one of these two ways:
4351
// (1) asynchronous SDK initialization (RECOMMENDED)
4452
// - fetch a JSON datafile from the server
@@ -105,10 +113,22 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
105113

106114
_ = optimizely.notificationCenter.addDecisionNotificationListener(decisionListener: { (type, userId, attributes, decisionInfo) in
107115
print("Received decision notification: \(type) \(userId) \(String(describing: attributes)) \(decisionInfo)")
108-
})
116+
})
109117

110118
_ = optimizely.notificationCenter.addTrackNotificationListener(trackListener: { (eventKey, userId, attributes, eventTags, event) in
111119
print("Received track notification: \(eventKey) \(userId) \(String(describing: attributes)) \(String(describing: eventTags)) \(event)")
120+
121+
#if os(iOS)
122+
123+
// Amplitude example
124+
let propertyKey = "[Optimizely] " + eventKey
125+
let identify = AMPIdentify()
126+
identify.set(propertyKey, value: userId as NSObject?)
127+
// Track event (optional)
128+
let eventIdentifier = "[Optimizely] " + eventKey + " - " + userId
129+
Amplitude.instance().logEvent(eventIdentifier)
130+
131+
#endif
112132
})
113133

114134
_ = optimizely.notificationCenter.addDatafileChangeNotificationListener(datafileListener: { (data) in

0 commit comments

Comments
 (0)