Skip to content

Commit

Permalink
Remove writekey from header; Add context.instanceId (#1049)
Browse files Browse the repository at this point in the history
* Removed writkey from header; Add context.instanceId

* Fixed segmentmac project to use local dependency

* Added writekey to payload body

* Cleaned up test info
  • Loading branch information
bsneed authored Jan 6, 2023
1 parent 1135436 commit acd9f97
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 35 deletions.
21 changes: 4 additions & 17 deletions Examples/SegmentMac/SegmentMac.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
objects = {

/* Begin PBXBuildFile section */
46B3728F293E699F006B1BFB /* Segment in Frameworks */ = {isa = PBXBuildFile; productRef = 46B3728E293E699F006B1BFB /* Segment */; };
96A12BAE24B3AEE200949804 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A12BAD24B3AEE200949804 /* AppDelegate.swift */; };
96A12BB024B3AEE200949804 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A12BAF24B3AEE200949804 /* ViewController.swift */; };
96A12BB224B3AEE400949804 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96A12BB124B3AEE400949804 /* Assets.xcassets */; };
96A12BB524B3AEE400949804 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 96A12BB324B3AEE400949804 /* Main.storyboard */; };
96E46DAA2547A9090086871C /* Segment in Frameworks */ = {isa = PBXBuildFile; productRef = 96E46DA92547A9090086871C /* Segment */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -42,7 +42,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
96E46DAA2547A9090086871C /* Segment in Frameworks */,
46B3728F293E699F006B1BFB /* Segment in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -104,7 +104,7 @@
);
name = SegmentMac;
packageProductDependencies = (
96E46DA92547A9090086871C /* Segment */,
46B3728E293E699F006B1BFB /* Segment */,
);
productName = SegmentMac;
productReference = 96A12BAA24B3AEE200949804 /* SegmentMac.app */;
Expand Down Expand Up @@ -135,7 +135,6 @@
);
mainGroup = 96A12BA124B3AEE200949804;
packageReferences = (
961C616B24BE5BA200A8B8E3 /* XCRemoteSwiftPackageReference "analytics-ios" */,
);
productRefGroup = 96A12BAB24B3AEE200949804 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -358,21 +357,9 @@
};
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
961C616B24BE5BA200A8B8E3 /* XCRemoteSwiftPackageReference "analytics-ios" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/segmentio/analytics-ios.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 4.1.0;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
96E46DA92547A9090086871C /* Segment */ = {
46B3728E293E699F006B1BFB /* Segment */ = {
isa = XCSwiftPackageProductDependency;
package = 961C616B24BE5BA200A8B8E3 /* XCRemoteSwiftPackageReference "analytics-ios" */;
productName = Segment;
};
/* End XCSwiftPackageProductDependency section */
Expand Down

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
3 changes: 2 additions & 1 deletion Examples/SegmentMac/SegmentMac/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ class ViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()

let configuration = AnalyticsConfiguration(writeKey: "8XpdAWa7qJVBJMK8V4FfXQOrnvCzu3Ie")
let configuration = AnalyticsConfiguration(writeKey: "<WRITE KEY>")

// Enable this to record certain application events automatically!
configuration.trackApplicationLifecycleEvents = true
// Enable this to record screen views automatically!
configuration.recordScreenViews = true
configuration.flushAt = 1
Analytics.setup(with: configuration)


Expand Down
2 changes: 2 additions & 0 deletions Segment/Classes/SEGAnalyticsConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ @interface SEGAnalyticsConfiguration ()
@property (nonatomic, copy, readwrite) NSString *writeKey;
@property (nonatomic, strong, readonly) NSMutableArray *factories;
@property (nonatomic, strong) SEGAnalyticsExperimental *experimental;
@property (nonatomic, strong) NSString *instanceId;

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

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

// get the host we have stored
NSString *host = [SEGUtils getAPIHost];
Expand Down
1 change: 0 additions & 1 deletion Segment/Classes/SEGHTTPClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ - (NSURLSession *)sessionForWriteKey:(NSString *)writeKey
@"Accept-Encoding" : @"gzip",
@"Content-Encoding" : @"gzip",
@"Content-Type" : @"application/json",
@"Authorization" : [@"Basic " stringByAppendingString:[[self class] authorizationHeader:writeKey]],
@"User-Agent" : [NSString stringWithFormat:@"analytics-ios/%@", [SEGAnalytics version]],
};
session = [NSURLSession sessionWithConfiguration:config delegate:self.httpSessionDelegate delegateQueue:NULL];
Expand Down
1 change: 1 addition & 0 deletions Segment/Classes/SEGSegmentIntegration.m
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ - (void)sendData:(NSArray *)batch
{
NSMutableDictionary *payload = [[NSMutableDictionary alloc] init];
[payload setObject:iso8601FormattedString([NSDate date]) forKey:@"sentAt"];
[payload setObject:_configuration.writeKey forKey:@"writeKey"];
[payload setObject:batch forKey:@"batch"];

SEGLog(@"%@ Flushing %lu of %lu queued API calls.", self, (unsigned long)batch.count, (unsigned long)self.queue.count);
Expand Down
6 changes: 6 additions & 0 deletions Segment/Internal/SEGUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

const NSString *segment_apiHost = @"segment_apihost";

@interface SEGAnalyticsConfiguration(InstanceId)
@property (nonatomic, strong) NSString *instanceId;
@end

@implementation SEGUtils

+ (void)saveAPIHost:(nonnull NSString *)apiHost
Expand Down Expand Up @@ -182,6 +186,8 @@ BOOL getAdTrackingEnabled(SEGAnalyticsConfiguration *configuration)
@"name" : @"analytics-ios",
@"version" : [SEGAnalytics version]
};

dict[@"instanceId"] = configuration.instanceId;

NSMutableDictionary *infoDictionary = [[[NSBundle mainBundle] infoDictionary] mutableCopy];
[infoDictionary addEntriesFromDictionary:[[NSBundle mainBundle] localizedInfoDictionary]];
Expand Down

0 comments on commit acd9f97

Please sign in to comment.