Skip to content

Commit

Permalink
feat: segment compatibility (#685)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shahroz16 committed May 7, 2024
1 parent 4c4af15 commit 7298783
Show file tree
Hide file tree
Showing 25 changed files with 40 additions and 60 deletions.
2 changes: 2 additions & 0 deletions Apps/APN-UIKit/APN UIKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,8 @@
Base,
);
mainGroup = 46D5D97429E459D600EAF40B;
packageReferences = (
);
productRefGroup = 46D5D97E29E459D600EAF40B /* Products */;
projectDirPath = "";
projectRoot = "";
Expand Down
2 changes: 1 addition & 1 deletion CustomerIODataPipelines.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ Pod::Spec.new do |spec|
spec.dependency "CustomerIOTrackingMigration", "= #{spec.version.to_s}"

# Add Segment SDK as a dependency, as this module is designed to be compatible with it.
spec.dependency 'AnalyticsSwiftCIO', '= 1.5.11+cio.1'
spec.dependency 'AnalyticsSwiftCIO', '= 1.5.12+cio.1'
end
8 changes: 4 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ let package = Package(
.package(name: "Firebase", url: "https://github.com/firebase/firebase-ios-sdk.git", "8.7.0"..<"11.0.0"),

// Make sure the version number is same for DataPipelines cocoapods.
.package(name: "Segment", url: "https://github.com/customerio/cdp-analytics-swift.git", .exact("1.5.11+cio.1"))
.package(name: "CioAnalytics", url: "https://github.com/customerio/cdp-analytics-swift.git", .exact("1.5.12+cio.1"))
],
targets: [
// Common - Code used by multiple modules in the SDK project.
Expand Down Expand Up @@ -81,9 +81,9 @@ let package = Package(

// Data Pipeline
.target(name: "CioDataPipelines",
dependencies: ["CioInternalCommon", "CioTrackingMigration", .product(name: "Segment", package: "Segment")],
path: "Sources/DataPipeline",
resources: [
dependencies: ["CioInternalCommon", "CioTrackingMigration",
.product(name: "CioAnalytics", package: "CioAnalytics")],
path: "Sources/DataPipeline", resources: [
.process("Resources/PrivacyInfo.xcprivacy"),
]),
.testTarget(name: "DataPipelineTests",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import CioAnalytics
import CioInternalCommon
import Foundation
import Segment

/// Defines configuration options for the Customer.io Data Pipeline module.
///
Expand Down
2 changes: 1 addition & 1 deletion Sources/DataPipeline/Config/SDKConfigBuilder.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import CioAnalytics
import CioInternalCommon
import Foundation
import Segment
#if canImport(UIKit)
import UIKit
#endif
Expand Down
2 changes: 1 addition & 1 deletion Sources/DataPipeline/CustomerIO+Plugins.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import CioAnalytics
import CioInternalCommon
import Foundation
import Segment

public extension CustomerIO {
/**
Expand Down
2 changes: 1 addition & 1 deletion Sources/DataPipeline/CustomerIO+Segment.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import CioAnalytics
import CioInternalCommon
import Foundation
import Segment

// MARK: - System Modifiers

Expand Down
4 changes: 2 additions & 2 deletions Sources/DataPipeline/DataPipeline.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import CioAnalytics
import CioInternalCommon
import CioTrackingMigration
import Segment

public protocol DataPipelineInstance: CustomerIOInstance, DataPipelineMigrationAction {
var analytics: Analytics { get }
Expand All @@ -11,7 +11,7 @@ public class DataPipeline: ModuleTopLevelObject<DataPipelineInstance>, DataPipel
ModuleTopLevelObject is intentionally designed to allow null implementations, matching our requirements overall. Customer who have correctly initialized the SDK will consistently find the implementation set correctly and operational. However, customers who attempt to use functions dependent on this implementation without initializing the SDK may not see the desired results, which is an expected behavior. To align our SDK with Segment API practices (e.g., add(Plugin)), which require returning non-null objects, we face a challenge when the SDK is not initialized.
To avoid force unwrapping and to maintain consistency with Segment APIs, we’ve introduced a ‘dead instance’ to handle these edge cases. This implementation acts as a safeguard, capturing calls made without SDK initialization and logging a warning, yet it does not perform any operations for these calls. This approach ensures stability and consistency in the API’s behavior.
*/
public var analytics: Segment.Analytics {
public var analytics: CioAnalytics.Analytics {
implementation?.analytics ?? Analytics(configuration: Configuration(writeKey: "DEADINSTANCE"))
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/DataPipeline/DataPipelineImplementation.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import CioAnalytics
import CioInternalCommon
import Segment

class DataPipelineImplementation: DataPipelineInstance {
private let moduleConfig: DataPipelineConfigOptions
Expand Down
4 changes: 2 additions & 2 deletions Sources/DataPipeline/Plugins/AutoTrackingScreenViews.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import CioAnalytics
import CioInternalCommon
import Foundation
import Segment
#if canImport(UIKit)
import UIKit
#endif
Expand All @@ -11,7 +11,7 @@ import UIKit
public class AutoTrackingScreenViews: UtilityPlugin {
public let type = PluginType.utility

public var analytics: Segment.Analytics?
public var analytics: CioAnalytics.Analytics?
public var diGraph: DIGraphShared {
DIGraphShared.shared
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/DataPipeline/Plugins/Context.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import CioAnalytics
import CioInternalCommon
import Segment

/// Plugin class that update the context properties in the request payload
class Context: Plugin {
Expand Down
2 changes: 1 addition & 1 deletion Sources/DataPipeline/Plugins/CustomerIODestination.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Segment
import CioAnalytics

// inherits from SegmentDestination and is used to send events to Customer.io servers
public class CustomerIODestination: SegmentDestination {}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import CioAnalytics
import CioInternalCommon
import Foundation
import Segment

/// This class serves as a centralized hub for dispatching events generated from DataPipeline module.
/// It is designed to reduce redundancy and enhance maintainability by funneling these operations through a single plugin.
/// This plugin allows for decoupled modules to subscribe and react to these events.
class DataPipelinePublishedEvents: EventPlugin {
var type: Segment.PluginType = .before
var type: CioAnalytics.PluginType = .before

var analytics: Segment.Analytics?
var analytics: CioAnalytics.Analytics?
var eventBusHandler: EventBusHandler

public required init(diGraph: DIGraphShared) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import CioAnalytics
import Foundation
import Segment

// This plugin is used to add contextual data to the device attributes
class DeviceContexualAttributes: EventPlugin {
Expand Down
2 changes: 1 addition & 1 deletion Sources/DataPipeline/Plugins/Logger.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import CioAnalytics
import CioInternalCommon
import Segment

/// Logger plugin for logging all requests sent to analytics
class ConsoleLogger: Plugin {
Expand Down
28 changes: 3 additions & 25 deletions Sources/DataPipeline/Type/Aliases.swift
Original file line number Diff line number Diff line change
@@ -1,33 +1,11 @@
import CioAnalytics
import CioInternalCommon
import Foundation
import Segment

/*
Contains public aliases to expose public structures/protocols from the 'Segment' module
to the 'DataPipeline' module. The goal is that customers do not need to import
the 'Segment' module in their code.
Contains public aliases to expose public structures/protocols from the 'CioInternalCommon' module
to the 'DataPipeline' module.
*/

public typealias Plugin = Segment.Plugin
public typealias PluginType = Segment.PluginType
public typealias EventPlugin = Segment.EventPlugin
public typealias DestinationPlugin = Segment.DestinationPlugin
public typealias UtilityPlugin = Segment.UtilityPlugin
public typealias VersionedPlugin = Segment.VersionedPlugin

public typealias Analytics = Segment.Analytics

public typealias RawEvent = Segment.RawEvent
public typealias TrackEvent = Segment.TrackEvent
public typealias ScreenEvent = Segment.ScreenEvent
public typealias AliasEvent = Segment.AliasEvent
public typealias GroupEvent = Segment.GroupEvent
public typealias IdentifyEvent = Segment.IdentifyEvent

public typealias Settings = Segment.Settings
public typealias FlushPolicy = Segment.FlushPolicy
public typealias OperatingMode = Segment.OperatingMode

public typealias Metric = CioInternalCommon.Metric
public typealias CustomerIO = CioInternalCommon.CustomerIO
public typealias CioLogLevel = CioInternalCommon.CioLogLevel
Expand Down
2 changes: 1 addition & 1 deletion Tests/DataPipeline/APITest.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import CioAnalytics
import CioDataPipelines // do not use `@testable` so we can test functions are made public and not `internal`.
import Foundation
import Segment
import SharedTests
import XCTest

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@testable import CioAnalytics
@testable import CioDataPipelines
@testable import Segment
import SharedTests
import XCTest

Expand Down
2 changes: 1 addition & 1 deletion Tests/DataPipeline/Config/SDKConfigBuilderTest.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@testable import CioAnalytics
@testable import CioDataPipelines
@testable import Segment
import SharedTests
import XCTest

Expand Down
2 changes: 1 addition & 1 deletion Tests/DataPipeline/Core/UnitTest.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@testable import CioAnalytics
@testable import CioDataPipelines
@testable import CioInternalCommon
import Foundation
@testable import Segment
import SharedTests

/// Base class for unit testing within the module, extending `UnitTestBase` with setup and utilities
Expand Down
2 changes: 1 addition & 1 deletion Tests/DataPipeline/DataPipelineCompatibilityTests.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@testable import CioAnalytics
@testable import CioDataPipelines
@testable import CioInternalCommon
import Foundation
@testable import Segment
@testable import SharedTests
import XCTest

Expand Down
2 changes: 1 addition & 1 deletion Tests/DataPipeline/DataPipelineEventBustTests.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@testable import CioAnalytics
@testable import CioDataPipelines
@testable import CioInternalCommon
import Foundation
@testable import Segment
@testable import SharedTests
import XCTest

Expand Down
2 changes: 1 addition & 1 deletion Tests/DataPipeline/DataPipelineInteractionTests.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@testable import CioAnalytics
@testable import CioDataPipelines
@testable import CioInternalCommon
import Foundation
@testable import Segment
@testable import SharedTests
import XCTest

Expand Down
12 changes: 6 additions & 6 deletions Tests/DataPipeline/Support/MockPlugins.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import CioAnalytics
import CioDataPipelines
import Foundation
import Segment

// This file contains mock plugins for testing purposes.
// These plugins can be used as placeholders for testing APIs that use plugins.

class UtilityPluginMock: Plugin {
let type: Segment.PluginType = .utility
var analytics: Segment.Analytics?
let type: PluginType = .utility
var analytics: Analytics?
}

class DestinationPluginMock: DestinationPlugin {
let key: String = "Mock"
let timeline: Segment.Timeline = .init()
let type: Segment.PluginType = .destination
var analytics: Segment.Analytics?
let timeline: Timeline = .init()
let type: PluginType = .destination
var analytics: Analytics?
}
2 changes: 1 addition & 1 deletion Tests/DataPipeline/Support/Segment.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@testable import CioAnalytics
@testable import CioDataPipelines
import Foundation
@testable import Segment
import XCTest

// MARK: - Helper Plugins
Expand Down

0 comments on commit 7298783

Please sign in to comment.