Skip to content

Commit a208e98

Browse files
authored
Migs647/exampledestination2 (#62)
* Fixed flush test * Added example destination * Updated Mixpanel destination to match Example
1 parent 96ec36a commit a208e98

File tree

10 files changed

+389
-79
lines changed

10 files changed

+389
-79
lines changed

Examples/apps/DestinationsExample/DestinationsExample.xcodeproj/project.pbxproj

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
965DC1232669947F00DDF9C7 /* FirebaseDestination.swift in Sources */ = {isa = PBXBuildFile; fileRef = 965DC1222669947F00DDF9C7 /* FirebaseDestination.swift */; };
2727
965DC1262671656C00DDF9C7 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 965DC1252671656C00DDF9C7 /* GoogleService-Info.plist */; };
2828
9697C1F52679156C00B87EC1 /* Segment_Logo_Avatar_Grey-1024.png in Resources */ = {isa = PBXBuildFile; fileRef = 9697C1F42679156C00B87EC1 /* Segment_Logo_Avatar_Grey-1024.png */; };
29+
96D8F16F26EFFA09007F8B28 /* ExampleDestination.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D8F16E26EFFA09007F8B28 /* ExampleDestination.swift */; };
2930
BA384C9826824F3700AFEA1B /* AppsFlyerLib in Frameworks */ = {isa = PBXBuildFile; productRef = BA384C9726824F3700AFEA1B /* AppsFlyerLib */; };
3031
BA384C9A2682973300AFEA1B /* AppsFlyerDestination.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA384C992682973300AFEA1B /* AppsFlyerDestination.swift */; };
3132
/* End PBXBuildFile section */
@@ -48,6 +49,7 @@
4849
965DC1222669947F00DDF9C7 /* FirebaseDestination.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirebaseDestination.swift; sourceTree = "<group>"; };
4950
965DC1252671656C00DDF9C7 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
5051
9697C1F42679156C00B87EC1 /* Segment_Logo_Avatar_Grey-1024.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Segment_Logo_Avatar_Grey-1024.png"; sourceTree = "<group>"; };
52+
96D8F16E26EFFA09007F8B28 /* ExampleDestination.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExampleDestination.swift; sourceTree = "<group>"; };
5153
BA384C992682973300AFEA1B /* AppsFlyerDestination.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppsFlyerDestination.swift; sourceTree = "<group>"; };
5254
BA384C9D2686609000AFEA1B /* DestinationsExample.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = DestinationsExample.entitlements; sourceTree = "<group>"; };
5355
/* End PBXFileReference section */
@@ -119,6 +121,7 @@
119121
BA384C992682973300AFEA1B /* AppsFlyerDestination.swift */,
120122
469F7B24266013320038E773 /* AdjustDestination.swift */,
121123
965DC0F92668077400DDF9C7 /* AmplitudeSession.swift */,
124+
96D8F16E26EFFA09007F8B28 /* ExampleDestination.swift */,
122125
965DC1222669947F00DDF9C7 /* FirebaseDestination.swift */,
123126
469F7B1F266012CB0038E773 /* FlurryDestination.swift */,
124127
965DC0F82668077400DDF9C7 /* MixpanelDestination.swift */,
@@ -226,6 +229,7 @@
226229
BA384C9A2682973300AFEA1B /* AppsFlyerDestination.swift in Sources */,
227230
469F7B20266012CB0038E773 /* FlurryDestination.swift in Sources */,
228231
469F7B0C266011690038E773 /* ViewController.swift in Sources */,
232+
96D8F16F26EFFA09007F8B28 /* ExampleDestination.swift in Sources */,
229233
965DC0FA2668077400DDF9C7 /* MixpanelDestination.swift in Sources */,
230234
965DC0FB2668077400DDF9C7 /* AmplitudeSession.swift in Sources */,
231235
469F7B08266011690038E773 /* AppDelegate.swift in Sources */,
@@ -455,32 +459,32 @@
455459
isa = XCRemoteSwiftPackageReference;
456460
repositoryURL = "https://github.com/adjust/ios_sdk.git";
457461
requirement = {
458-
kind = upToNextMajorVersion;
459-
minimumVersion = 4.29.2;
462+
kind = exactVersion;
463+
version = 4.29.6;
460464
};
461465
};
462466
965DC0FC2668079400DDF9C7 /* XCRemoteSwiftPackageReference "mixpanel-swift" */ = {
463467
isa = XCRemoteSwiftPackageReference;
464468
repositoryURL = "[email protected]:mixpanel/mixpanel-swift.git";
465469
requirement = {
466-
kind = upToNextMajorVersion;
467-
minimumVersion = 2.9.3;
470+
kind = exactVersion;
471+
version = 2.9.3;
468472
};
469473
};
470474
965DC11F2669942800DDF9C7 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */ = {
471475
isa = XCRemoteSwiftPackageReference;
472476
repositoryURL = "https://github.com/firebase/firebase-ios-sdk.git";
473477
requirement = {
474-
kind = upToNextMajorVersion;
475-
minimumVersion = 8.1.0;
478+
kind = exactVersion;
479+
version = 8.1.0;
476480
};
477481
};
478482
BA384C9626824F3700AFEA1B /* XCRemoteSwiftPackageReference "AppsFlyerFramework" */ = {
479483
isa = XCRemoteSwiftPackageReference;
480484
repositoryURL = "https://github.com/AppsFlyerSDK/AppsFlyerFramework";
481485
requirement = {
482-
kind = upToNextMajorVersion;
483-
minimumVersion = 6.3.2;
486+
kind = exactVersion;
487+
version = 6.3.2;
484488
};
485489
};
486490
/* End XCRemoteSwiftPackageReference section */
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
//
2+
// ExampleDestination.swift
3+
// ExampleDestination
4+
//
5+
// Created by Cody Garvin on 9/13/21.
6+
//
7+
8+
// NOTE: You can see this plugin in use in the DestinationsExample application.
9+
//
10+
// This plugin is NOT SUPPORTED by Segment. It is here merely as an example,
11+
// and for your convenience should you find it useful.
12+
//
13+
14+
// MIT License
15+
//
16+
// Copyright (c) 2021 Segment
17+
//
18+
// Permission is hereby granted, free of charge, to any person obtaining a copy
19+
// of this software and associated documentation files (the "Software"), to deal
20+
// in the Software without restriction, including without limitation the rights
21+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
22+
// copies of the Software, and to permit persons to whom the Software is
23+
// furnished to do so, subject to the following conditions:
24+
//
25+
// The above copyright notice and this permission notice shall be included in all
26+
// copies or substantial portions of the Software.
27+
//
28+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
31+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
32+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
33+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34+
// SOFTWARE.
35+
36+
import Foundation
37+
import Segment
38+
//import ExampleModule // TODO: Import partner SDK module here
39+
40+
/**
41+
An implementation of the Example Analytics device mode destination as a plugin.
42+
*/
43+
44+
class ExampleDestination: DestinationPlugin {
45+
let timeline = Timeline()
46+
let type = PluginType.destination
47+
// TODO: Fill this out with your settings key that matches your destination in the Segment App
48+
let key = "Example"
49+
var analytics: Analytics? = nil
50+
51+
private var exampleSettings: ExampleSettings?
52+
53+
func update(settings: Settings, type: UpdateType) {
54+
// Skip if you have a singleton and don't want to keep updating via settings.
55+
guard type == .initial else { return }
56+
57+
// Grab the settings and assign them for potential later usage.
58+
// Note: Since integrationSettings is generic, strongly type the variable.
59+
guard let tempSettings: ExampleSettings = settings.integrationSettings(forPlugin: self) else { return }
60+
exampleSettings = tempSettings
61+
62+
// TODO: initialize partner SDK here
63+
}
64+
65+
func identify(event: IdentifyEvent) -> IdentifyEvent? {
66+
67+
if let _ = event.traits?.dictionaryValue {
68+
// TODO: Do something with traits if they exist
69+
}
70+
71+
// TODO: Do something with userId & traits in partner SDK
72+
73+
return event
74+
}
75+
76+
func track(event: TrackEvent) -> TrackEvent? {
77+
78+
var returnEvent = event
79+
80+
// !!!: Sample of how to convert property keys
81+
if let mappedProperties = try? event.properties?.mapTransform(ExampleDestination.eventNameMap,
82+
valueTransform: ExampleDestination.eventValueConversion) {
83+
returnEvent.properties = mappedProperties
84+
}
85+
86+
// TODO: Do something with event & properties in partner SDK from returnEvent
87+
88+
return returnEvent
89+
}
90+
91+
func screen(event: ScreenEvent) -> ScreenEvent? {
92+
93+
if let _ = event.properties?.dictionaryValue {
94+
// TODO: Do something with properties if they exist
95+
}
96+
97+
// TODO: Do something with name, category & properties in partner SDK
98+
99+
return event
100+
}
101+
102+
func group(event: GroupEvent) -> GroupEvent? {
103+
104+
if let _ = event.traits?.dictionaryValue {
105+
// TODO: Do something with traits if they exist
106+
}
107+
108+
// TODO: Do something with groupId & traits in partner SDK
109+
110+
return event
111+
}
112+
113+
func alias(event: AliasEvent) -> AliasEvent? {
114+
115+
// TODO: Do something with previousId & userId in partner SDK
116+
117+
return event
118+
}
119+
120+
func reset() {
121+
// TODO: Do something with resetting partner SDK
122+
}
123+
}
124+
125+
// Example of what settings may look like.
126+
private struct ExampleSettings: Codable {
127+
let apiKey: String
128+
let configB: Int?
129+
let configC: Bool?
130+
}
131+
132+
// Rules for converting keys and values to the proper formats that bridge
133+
// from Segment to the Partner SDK. These are only examples.
134+
private extension ExampleDestination {
135+
136+
static var eventNameMap = ["ADD_TO_CART": "Product Added",
137+
"PRODUCT_TAPPED": "Product Tapped"]
138+
139+
static var eventValueConversion: ((_ key: String, _ value: Any) -> Any) = { (key, value) in
140+
if let valueString = value as? String {
141+
return valueString
142+
.replacingOccurrences(of: "-", with: "_")
143+
.replacingOccurrences(of: " ", with: "_")
144+
} else {
145+
return value
146+
}
147+
}
148+
}

Examples/destination_plugins/FlurryDestination.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import Segment
3939
import FlurryAnalytics
4040

4141
/**
42-
An implmentation of the Flurry Analytics device mode destination as a plugin.
42+
An implementation of the Flurry Analytics device mode destination as a plugin.
4343
*/
4444

4545
private struct FlurrySettings: Codable {

0 commit comments

Comments
 (0)