Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
965DC1232669947F00DDF9C7 /* FirebaseDestination.swift in Sources */ = {isa = PBXBuildFile; fileRef = 965DC1222669947F00DDF9C7 /* FirebaseDestination.swift */; };
965DC1262671656C00DDF9C7 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 965DC1252671656C00DDF9C7 /* GoogleService-Info.plist */; };
9697C1F52679156C00B87EC1 /* Segment_Logo_Avatar_Grey-1024.png in Resources */ = {isa = PBXBuildFile; fileRef = 9697C1F42679156C00B87EC1 /* Segment_Logo_Avatar_Grey-1024.png */; };
96D8F16F26EFFA09007F8B28 /* ExampleDestination.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D8F16E26EFFA09007F8B28 /* ExampleDestination.swift */; };
BA384C9826824F3700AFEA1B /* AppsFlyerLib in Frameworks */ = {isa = PBXBuildFile; productRef = BA384C9726824F3700AFEA1B /* AppsFlyerLib */; };
BA384C9A2682973300AFEA1B /* AppsFlyerDestination.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA384C992682973300AFEA1B /* AppsFlyerDestination.swift */; };
/* End PBXBuildFile section */
Expand All @@ -48,6 +49,7 @@
965DC1222669947F00DDF9C7 /* FirebaseDestination.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirebaseDestination.swift; sourceTree = "<group>"; };
965DC1252671656C00DDF9C7 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
9697C1F42679156C00B87EC1 /* Segment_Logo_Avatar_Grey-1024.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Segment_Logo_Avatar_Grey-1024.png"; sourceTree = "<group>"; };
96D8F16E26EFFA09007F8B28 /* ExampleDestination.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExampleDestination.swift; sourceTree = "<group>"; };
BA384C992682973300AFEA1B /* AppsFlyerDestination.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppsFlyerDestination.swift; sourceTree = "<group>"; };
BA384C9D2686609000AFEA1B /* DestinationsExample.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = DestinationsExample.entitlements; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -119,6 +121,7 @@
BA384C992682973300AFEA1B /* AppsFlyerDestination.swift */,
469F7B24266013320038E773 /* AdjustDestination.swift */,
965DC0F92668077400DDF9C7 /* AmplitudeSession.swift */,
96D8F16E26EFFA09007F8B28 /* ExampleDestination.swift */,
965DC1222669947F00DDF9C7 /* FirebaseDestination.swift */,
469F7B1F266012CB0038E773 /* FlurryDestination.swift */,
965DC0F82668077400DDF9C7 /* MixpanelDestination.swift */,
Expand Down Expand Up @@ -226,6 +229,7 @@
BA384C9A2682973300AFEA1B /* AppsFlyerDestination.swift in Sources */,
469F7B20266012CB0038E773 /* FlurryDestination.swift in Sources */,
469F7B0C266011690038E773 /* ViewController.swift in Sources */,
96D8F16F26EFFA09007F8B28 /* ExampleDestination.swift in Sources */,
965DC0FA2668077400DDF9C7 /* MixpanelDestination.swift in Sources */,
965DC0FB2668077400DDF9C7 /* AmplitudeSession.swift in Sources */,
469F7B08266011690038E773 /* AppDelegate.swift in Sources */,
Expand Down Expand Up @@ -455,32 +459,32 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/adjust/ios_sdk.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 4.29.2;
kind = exactVersion;
version = 4.29.6;
};
};
965DC0FC2668079400DDF9C7 /* XCRemoteSwiftPackageReference "mixpanel-swift" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "[email protected]:mixpanel/mixpanel-swift.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 2.9.3;
kind = exactVersion;
version = 2.9.3;
};
};
965DC11F2669942800DDF9C7 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/firebase/firebase-ios-sdk.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 8.1.0;
kind = exactVersion;
version = 8.1.0;
};
};
BA384C9626824F3700AFEA1B /* XCRemoteSwiftPackageReference "AppsFlyerFramework" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/AppsFlyerSDK/AppsFlyerFramework";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 6.3.2;
kind = exactVersion;
version = 6.3.2;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down
148 changes: 148 additions & 0 deletions Examples/destination_plugins/ExampleDestination.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
//
// ExampleDestination.swift
// ExampleDestination
//
// Created by Cody Garvin on 9/13/21.
//

// NOTE: You can see this plugin in use in the DestinationsExample application.
//
// This plugin is NOT SUPPORTED by Segment. It is here merely as an example,
// and for your convenience should you find it useful.
//

// MIT License
//
// Copyright (c) 2021 Segment
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import Foundation
import Segment
//import ExampleModule // TODO: Import partner SDK module here

/**
An implementation of the Example Analytics device mode destination as a plugin.
*/

class ExampleDestination: DestinationPlugin {
let timeline = Timeline()
let type = PluginType.destination
// TODO: Fill this out with your settings key that matches your destination in the Segment App
let key = "Example"
var analytics: Analytics? = nil

private var exampleSettings: ExampleSettings?

func update(settings: Settings, type: UpdateType) {
// Skip if you have a singleton and don't want to keep updating via settings.
guard type == .initial else { return }

// Grab the settings and assign them for potential later usage.
// Note: Since integrationSettings is generic, strongly type the variable.
guard let tempSettings: ExampleSettings = settings.integrationSettings(forPlugin: self) else { return }
exampleSettings = tempSettings

// TODO: initialize partner SDK here
}

func identify(event: IdentifyEvent) -> IdentifyEvent? {

if let _ = event.traits?.dictionaryValue {
// TODO: Do something with traits if they exist
}

// TODO: Do something with userId & traits in partner SDK

return event
}

func track(event: TrackEvent) -> TrackEvent? {

var returnEvent = event

// !!!: Sample of how to convert property keys
if let mappedProperties = try? event.properties?.mapTransform(ExampleDestination.eventNameMap,
valueTransform: ExampleDestination.eventValueConversion) {
returnEvent.properties = mappedProperties
}

// TODO: Do something with event & properties in partner SDK from returnEvent

return returnEvent
}

func screen(event: ScreenEvent) -> ScreenEvent? {

if let _ = event.properties?.dictionaryValue {
// TODO: Do something with properties if they exist
}

// TODO: Do something with name, category & properties in partner SDK

return event
}

func group(event: GroupEvent) -> GroupEvent? {

if let _ = event.traits?.dictionaryValue {
// TODO: Do something with traits if they exist
}

// TODO: Do something with groupId & traits in partner SDK

return event
}

func alias(event: AliasEvent) -> AliasEvent? {

// TODO: Do something with previousId & userId in partner SDK

return event
}

func reset() {
// TODO: Do something with resetting partner SDK
}
}

// Example of what settings may look like.
private struct ExampleSettings: Codable {
let apiKey: String
let configB: Int?
let configC: Bool?
}

// Rules for converting keys and values to the proper formats that bridge
// from Segment to the Partner SDK. These are only examples.
private extension ExampleDestination {

static var eventNameMap = ["ADD_TO_CART": "Product Added",
"PRODUCT_TAPPED": "Product Tapped"]

static var eventValueConversion: ((_ key: String, _ value: Any) -> Any) = { (key, value) in
if let valueString = value as? String {
return valueString
.replacingOccurrences(of: "-", with: "_")
.replacingOccurrences(of: " ", with: "_")
} else {
return value
}
}
}
2 changes: 1 addition & 1 deletion Examples/destination_plugins/FlurryDestination.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import Segment
import FlurryAnalytics

/**
An implmentation of the Flurry Analytics device mode destination as a plugin.
An implementation of the Flurry Analytics device mode destination as a plugin.
*/

private struct FlurrySettings: Codable {
Expand Down
Loading