Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
701 changes: 569 additions & 132 deletions Amplitude.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

23 changes: 22 additions & 1 deletion Podfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
project 'Amplitude'
use_frameworks!

abstract_target 'AnalyticsConnector' do
pod 'AnalyticsConnector', '~> 1.0.0', :configurations => ['Debug', 'Release']

target 'Amplitude_iOS' do
platform :ios, '11.0'
end

target 'Amplitude_macOS' do
platform :macos, '10.15'
end

target 'Amplitude_watchOS' do
platform :watchos, '3.0'
end

target 'Amplitude_tvOS' do
platform :tvos, '9.0'
end
end

abstract_target 'shared' do

pod 'OCMock', '~> 3.2.1'
pod 'OCMock', '~> 3.8.1'

target 'Amplitude_iOSTests' do
platform :ios, '10.0'
Expand Down
14 changes: 9 additions & 5 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
PODS:
- OCMock (3.2.2)
- AnalyticsConnector (1.0.3)
- OCMock (3.8.1)

DEPENDENCIES:
- OCMock (~> 3.2.1)
- AnalyticsConnector (~> 1.0.0)
- OCMock (~> 3.8.1)

SPEC REPOS:
trunk:
- AnalyticsConnector
- OCMock

SPEC CHECKSUMS:
OCMock: 18c9b7e67d4c2770e95bb77a9cc1ae0c91fe3835
AnalyticsConnector: a53214d38ae22734c6266106c0492b37832633a9
OCMock: 29f6e52085b4e7d9b075cbf03ed7c3112f82f934

PODFILE CHECKSUM: f4462aedc7398f89b3216737d86da7f673eb4649
PODFILE CHECKSUM: d4e644c2397935bf361f832cce6007c2f17cb2ed

COCOAPODS: 1.11.3
COCOAPODS: 1.16.2
8 changes: 4 additions & 4 deletions Sources/Amplitude/AMPServerZoneUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ @implementation AMPServerZoneUtil
+ (NSString *)getEventLogApi:(AMPServerZone)serverZone {
NSString *eventLogUrl = kAMPEventLogUrl;
switch (serverZone) {
case EU:
case AMPServerZoneEU:
eventLogUrl = kAMPEventLogEuUrl;
break;
case US:
case AMPServerZoneUS:
eventLogUrl = kAMPEventLogUrl;
break;

Expand All @@ -47,10 +47,10 @@ + (NSString *)getEventLogApi:(AMPServerZone)serverZone {
+ (NSString *)getDynamicConfigApi:(AMPServerZone)serverZone {
NSString *dynamicConfigUrl = kAMPDyanmicConfigUrl;
switch (serverZone) {
case EU:
case AMPServerZoneEU:
dynamicConfigUrl = kAMPDyanmicConfigEuUrl;
break;
case US:
case AMPServerZoneUS:
dynamicConfigUrl = kAMPDyanmicConfigUrl;
break;

Expand Down
20 changes: 19 additions & 1 deletion Sources/Amplitude/Amplitude.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
#endif
#endif

#ifndef AMPLITUDE_INCLUDE_ANALYTICS_CONNECTOR
#define AMPLITUDE_INCLUDE_ANALYTICS_CONNECTOR __has_include(<AnalyticsConnector/AnalyticsConnector.h>)
#endif

#import "Amplitude.h"
#import "AmplitudePrivate.h"
Expand Down Expand Up @@ -88,7 +91,9 @@
#import <Cocoa/Cocoa.h>
#endif

#if AMPLITUDE_INCLUDE_ANALYTICS_CONNECTOR
@import AnalyticsConnector;
#endif

@interface Amplitude ()

Expand Down Expand Up @@ -219,7 +224,7 @@ - (instancetype)initWithInstanceName:(NSString *)instanceName {
_backoffUpload = NO;
_offline = NO;
_serverUrl = kAMPEventLogUrl;
_serverZone = US;
_serverZone = AMPServerZoneUS;
self.libraryName = kAMPLibrary;
self.libraryVersion = kAMPVersion;
self.contentTypeHeader = kAMPContentTypeHeader;
Expand All @@ -241,10 +246,12 @@ - (instancetype)initWithInstanceName:(NSString *)instanceName {
_numRetries = 0;
_maxRetries = 5;

#if AMPLITUDE_INCLUDE_ANALYTICS_CONNECTOR
// Set the event receiver to forward events generated by Experiment SDK
[[[AnalyticsConnector getInstance:self.instanceName] eventBridge] setEventReceiver:^(AnalyticsEvent * _Nonnull event) {
[self logEvent:[event eventType] withEventProperties:[event eventProperties] withApiProperties:nil withUserProperties:[event userProperties] withGroups:nil withGroupProperties:nil withTimestamp:nil outOfSession:false];
}];
#endif

self.defaultTracking = [[AMPDefaultTrackingOptions alloc] init];

Expand Down Expand Up @@ -539,10 +546,13 @@ - (void)initializeApiKey:(NSString *)apiKey
} else {
self.userId = [self.dbHelper getValue:USER_ID];
}

#if AMPLITUDE_INCLUDE_ANALYTICS_CONNECTOR
// Set the user ID and device ID in the amplitude core instance. This is used to share user identity and user properties
// between Analytics and Experiment SDKs.
id<IdentityStoreEditor> identityStoreEditor = [[[AnalyticsConnector getInstance:self.instanceName] identityStore] editIdentity];
[[[identityStoreEditor setUserId:self.userId] setDeviceId:self.deviceId] commit];
#endif
if (self.initCompletionBlock != nil) {
self.initCompletionBlock();
}
Expand Down Expand Up @@ -731,11 +741,13 @@ - (void)logEvent:(NSString *)eventType withEventProperties:(NSDictionary *)event
return;
}

#if AMPLITUDE_INCLUDE_ANALYTICS_CONNECTOR
// Apply identify events to amplitude core to notify experiment SDK that user properties have changed.
if ([eventType isEqualToString:IDENTIFY_EVENT]) {
id<IdentityStoreEditor> editor = [[[AnalyticsConnector getInstance:self.instanceName] identityStore] editIdentity];
[[editor updateUserProperties:[event valueForKey:@"user_properties"]] commit];
}
#endif

event = [self->_identifyInterceptor intercept:event];
if ([event count] != 0) {
Expand Down Expand Up @@ -1545,10 +1557,12 @@ - (void)setUserId:(NSString *)userId startNewSession:(BOOL)startNewSession {
self->_userId = userId;
[self.dbHelper insertOrReplaceKeyValue:USER_ID value:self.userId];

#if AMPLITUDE_INCLUDE_ANALYTICS_CONNECTOR
// Set the user ID amplitude core instance. This is used to share user identity
// between Analytics and Experiment SDKs.
id<IdentityStoreEditor> identityStoreEditor = [[[AnalyticsConnector getInstance:self.instanceName] identityStore] editIdentity];
[[identityStoreEditor setUserId:self.userId] commit];
#endif
[self->_middlewareRunner dispatchAmplitude:self didChangeUserId:self.userId];

if (startNewSession) {
Expand Down Expand Up @@ -1619,10 +1633,14 @@ - (void)setDeviceId:(NSString *)deviceId {
[self runOnBackgroundQueue:^{
self->_deviceId = deviceId;
[self.dbHelper insertOrReplaceKeyValue:DEVICE_ID value:deviceId];

#if AMPLITUDE_INCLUDE_ANALYTICS_CONNECTOR
// Set the device ID in the amplitude core instance. This is used to share user identity
// between Analytics and Experiment SDKs.
id<IdentityStoreEditor> identityStoreEditor = [[[AnalyticsConnector getInstance:self.instanceName] identityStore] editIdentity];
[[identityStoreEditor setDeviceId:self.deviceId] commit];
#endif

[self->_middlewareRunner dispatchAmplitude:self didChangeDeviceId:self.deviceId];
}];
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Amplitude/Public/AMPMiddleware.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
*/
@interface AMPMiddlewarePayload: NSObject

@property NSMutableDictionary *_Nonnull event;
@property NSMutableDictionary *_Nullable extra;
@property (nonatomic, strong) NSMutableDictionary *_Nonnull event;
@property (nonatomic, strong) NSMutableDictionary *_Nullable extra;

- (instancetype _Nonnull)initWithEvent:(NSMutableDictionary *_Nonnull) event withExtra:(NSMutableDictionary *_Nullable) extra;

Expand Down
16 changes: 16 additions & 0 deletions Sources/Amplitude/Public/AMPServerZone.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,24 @@ typedef NS_ENUM(NSInteger, AMPServerZone);

#ifndef AMPServerZone_h
#define AMPServerZone_h

#ifdef AMPLITUDE_USE_PREFIXED_SERVERZONE

typedef NS_ENUM(NSInteger, AMPServerZone) {
AMPServerZoneUS,
AMPServerZoneEU
};

#else

typedef NS_ENUM(NSInteger, AMPServerZone) {
US,
EU
};

#define AMPServerZoneUS US
#define AMPServerZoneEU EU

#endif

#endif
36 changes: 36 additions & 0 deletions scripts/build_static_libs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

set -euo pipefail

WORKSPACE="Amplitude.xcworkspace"
CONFIGURATION="Static Library"
BUILD_DIR="build"

# List of schemes and corresponding SDKs for each platform
PLATFORMS=(
"Amplitude_macOS:macosx"
"Amplitude_iOS:iphoneos"
"Amplitude_tvOS:appletvos"
"Amplitude_watchOS:watchos"
)

echo "📦 Starting multi-platform build..."

for entry in "${PLATFORMS[@]}"; do
SCHEME="${entry%%:*}"
SDK="${entry##*:}"

echo "🚧 Building scheme '$SCHEME' with SDK '$SDK'..."

xcodebuild \
-workspace "$WORKSPACE" \
-scheme "$SCHEME" \
-configuration "$CONFIGURATION" \
-sdk "$SDK" \
BUILD_DIR="$BUILD_DIR" \
build

echo "✅ Finished building $SCHEME ($SDK)"
done

echo "🎉 All platform builds completed successfully."
Loading