Skip to content

Commit acd9f97

Browse files
authored
Remove writekey from header; Add context.instanceId (#1049)
* Removed writkey from header; Add context.instanceId * Fixed segmentmac project to use local dependency * Added writekey to payload body * Cleaned up test info
1 parent 1135436 commit acd9f97

File tree

9 files changed

+33
-35
lines changed

9 files changed

+33
-35
lines changed

Examples/SegmentMac/SegmentMac.xcodeproj/project.pbxproj

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

99
/* Begin PBXBuildFile section */
10+
46B3728F293E699F006B1BFB /* Segment in Frameworks */ = {isa = PBXBuildFile; productRef = 46B3728E293E699F006B1BFB /* Segment */; };
1011
96A12BAE24B3AEE200949804 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A12BAD24B3AEE200949804 /* AppDelegate.swift */; };
1112
96A12BB024B3AEE200949804 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A12BAF24B3AEE200949804 /* ViewController.swift */; };
1213
96A12BB224B3AEE400949804 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96A12BB124B3AEE400949804 /* Assets.xcassets */; };
1314
96A12BB524B3AEE400949804 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 96A12BB324B3AEE400949804 /* Main.storyboard */; };
14-
96E46DAA2547A9090086871C /* Segment in Frameworks */ = {isa = PBXBuildFile; productRef = 96E46DA92547A9090086871C /* Segment */; };
1515
/* End PBXBuildFile section */
1616

1717
/* Begin PBXCopyFilesBuildPhase section */
@@ -42,7 +42,7 @@
4242
isa = PBXFrameworksBuildPhase;
4343
buildActionMask = 2147483647;
4444
files = (
45-
96E46DAA2547A9090086871C /* Segment in Frameworks */,
45+
46B3728F293E699F006B1BFB /* Segment in Frameworks */,
4646
);
4747
runOnlyForDeploymentPostprocessing = 0;
4848
};
@@ -104,7 +104,7 @@
104104
);
105105
name = SegmentMac;
106106
packageProductDependencies = (
107-
96E46DA92547A9090086871C /* Segment */,
107+
46B3728E293E699F006B1BFB /* Segment */,
108108
);
109109
productName = SegmentMac;
110110
productReference = 96A12BAA24B3AEE200949804 /* SegmentMac.app */;
@@ -135,7 +135,6 @@
135135
);
136136
mainGroup = 96A12BA124B3AEE200949804;
137137
packageReferences = (
138-
961C616B24BE5BA200A8B8E3 /* XCRemoteSwiftPackageReference "analytics-ios" */,
139138
);
140139
productRefGroup = 96A12BAB24B3AEE200949804 /* Products */;
141140
projectDirPath = "";
@@ -358,21 +357,9 @@
358357
};
359358
/* End XCConfigurationList section */
360359

361-
/* Begin XCRemoteSwiftPackageReference section */
362-
961C616B24BE5BA200A8B8E3 /* XCRemoteSwiftPackageReference "analytics-ios" */ = {
363-
isa = XCRemoteSwiftPackageReference;
364-
repositoryURL = "https://github.com/segmentio/analytics-ios.git";
365-
requirement = {
366-
kind = upToNextMajorVersion;
367-
minimumVersion = 4.1.0;
368-
};
369-
};
370-
/* End XCRemoteSwiftPackageReference section */
371-
372360
/* Begin XCSwiftPackageProductDependency section */
373-
96E46DA92547A9090086871C /* Segment */ = {
361+
46B3728E293E699F006B1BFB /* Segment */ = {
374362
isa = XCSwiftPackageProductDependency;
375-
package = 961C616B24BE5BA200A8B8E3 /* XCRemoteSwiftPackageReference "analytics-ios" */;
376363
productName = Segment;
377364
};
378365
/* End XCSwiftPackageProductDependency section */

Examples/SegmentMac/SegmentMac.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 0 additions & 16 deletions
This file was deleted.

Examples/SegmentMac/SegmentMac.xcworkspace/contents.xcworkspacedata

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

Examples/SegmentMac/SegmentMac/ViewController.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ class ViewController: NSViewController {
1818
override func viewDidLoad() {
1919
super.viewDidLoad()
2020

21-
let configuration = AnalyticsConfiguration(writeKey: "8XpdAWa7qJVBJMK8V4FfXQOrnvCzu3Ie")
21+
let configuration = AnalyticsConfiguration(writeKey: "<WRITE KEY>")
2222

2323
// Enable this to record certain application events automatically!
2424
configuration.trackApplicationLifecycleEvents = true
2525
// Enable this to record screen views automatically!
2626
configuration.recordScreenViews = true
27+
configuration.flushAt = 1
2728
Analytics.setup(with: configuration)
2829

2930

Segment/Classes/SEGAnalyticsConfiguration.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ @interface SEGAnalyticsConfiguration ()
4242
@property (nonatomic, copy, readwrite) NSString *writeKey;
4343
@property (nonatomic, strong, readonly) NSMutableArray *factories;
4444
@property (nonatomic, strong) SEGAnalyticsExperimental *experimental;
45+
@property (nonatomic, strong) NSString *instanceId;
4546

4647
- (instancetype)initWithWriteKey:(NSString *)writeKey defaultAPIHost:(NSURL * _Nullable)defaultAPIHost;
4748

@@ -64,6 +65,7 @@ - (instancetype)initWithWriteKey:(NSString *)writeKey defaultAPIHost:(NSURL * _N
6465
{
6566
if (self = [self init]) {
6667
self.writeKey = writeKey;
68+
self.instanceId = [NSUUID UUID].UUIDString;
6769

6870
// get the host we have stored
6971
NSString *host = [SEGUtils getAPIHost];

Segment/Classes/SEGHTTPClient.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ - (NSURLSession *)sessionForWriteKey:(NSString *)writeKey
5454
@"Accept-Encoding" : @"gzip",
5555
@"Content-Encoding" : @"gzip",
5656
@"Content-Type" : @"application/json",
57-
@"Authorization" : [@"Basic " stringByAppendingString:[[self class] authorizationHeader:writeKey]],
5857
@"User-Agent" : [NSString stringWithFormat:@"analytics-ios/%@", [SEGAnalytics version]],
5958
};
6059
session = [NSURLSession sessionWithConfiguration:config delegate:self.httpSessionDelegate delegateQueue:NULL];

Segment/Classes/SEGSegmentIntegration.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ - (void)sendData:(NSArray *)batch
389389
{
390390
NSMutableDictionary *payload = [[NSMutableDictionary alloc] init];
391391
[payload setObject:iso8601FormattedString([NSDate date]) forKey:@"sentAt"];
392+
[payload setObject:_configuration.writeKey forKey:@"writeKey"];
392393
[payload setObject:batch forKey:@"batch"];
393394

394395
SEGLog(@"%@ Flushing %lu of %lu queued API calls.", self, (unsigned long)batch.count, (unsigned long)self.queue.count);

Segment/Internal/SEGUtils.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
const NSString *segment_apiHost = @"segment_apihost";
2020

21+
@interface SEGAnalyticsConfiguration(InstanceId)
22+
@property (nonatomic, strong) NSString *instanceId;
23+
@end
24+
2125
@implementation SEGUtils
2226

2327
+ (void)saveAPIHost:(nonnull NSString *)apiHost
@@ -182,6 +186,8 @@ BOOL getAdTrackingEnabled(SEGAnalyticsConfiguration *configuration)
182186
@"name" : @"analytics-ios",
183187
@"version" : [SEGAnalytics version]
184188
};
189+
190+
dict[@"instanceId"] = configuration.instanceId;
185191

186192
NSMutableDictionary *infoDictionary = [[[NSBundle mainBundle] infoDictionary] mutableCopy];
187193
[infoDictionary addEntriesFromDictionary:[[NSBundle mainBundle] localizedInfoDictionary]];

0 commit comments

Comments
 (0)