-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add Objective-C wrapper for Facebook integration #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SKannaniOS
wants to merge
3
commits into
develop
Choose a base branch
from
feature/sdk-4373-expose-facebook-swift-integration-to-objective-c
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+193
−0
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
191 changes: 191 additions & 0 deletions
191
Sources/RudderIntegrationFacebook/ObjCFacebookIntegration.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,191 @@ | ||
| // | ||
| // ObjCFacebookIntegration.swift | ||
| // RudderIntegrationFacebook | ||
| // | ||
| // Created by RudderStack on 11/01/26. | ||
| // | ||
|
|
||
| import Foundation | ||
| import RudderStackAnalytics | ||
|
|
||
| // MARK: - ObjCFacebookIntegration | ||
| /** | ||
| An Objective-C compatible wrapper for the Facebook Integration. | ||
|
|
||
| This class provides an Objective-C interface to the Facebook integration, | ||
| allowing Objective-C apps to use the Facebook App Events device mode integration with RudderStack. | ||
|
|
||
| ## Usage in Objective-C: | ||
| ```objc | ||
| RSSConfigurationBuilder *builder = [[RSSConfigurationBuilder alloc] initWithWriteKey:@"<WriteKey>" | ||
| dataPlaneUrl:@"<DataPlaneUrl>"]; | ||
| RSSAnalytics *analytics = [[RSSAnalytics alloc] initWithConfiguration:[builder build]]; | ||
|
|
||
| RSSFacebookIntegration *facebookIntegration = [[RSSFacebookIntegration alloc] init]; | ||
| [analytics addPlugin:facebookIntegration]; | ||
| ``` | ||
| */ | ||
| @objc(RSSFacebookIntegration) | ||
| public class ObjCFacebookIntegration: NSObject, ObjCIntegrationPlugin, ObjCStandardIntegration { | ||
|
|
||
| // MARK: - ObjCPlugin Properties | ||
|
|
||
| public var pluginType: PluginType { | ||
| get { facebookIntegration.pluginType } | ||
| set { facebookIntegration.pluginType = newValue } | ||
| } | ||
|
|
||
| // MARK: - ObjCIntegrationPlugin Properties | ||
|
|
||
| public var key: String { | ||
| get { facebookIntegration.key } | ||
| set { facebookIntegration.key = newValue } | ||
| } | ||
|
|
||
| // MARK: - Private Properties | ||
|
|
||
| private let facebookIntegration: FacebookIntegration | ||
|
|
||
| // MARK: - Initializers | ||
|
|
||
| /** | ||
| Initializes a new Facebook integration instance. | ||
|
|
||
| Use this initializer to create a Facebook integration that can be added to the analytics client. | ||
| */ | ||
| @objc | ||
| public override init() { | ||
| self.facebookIntegration = FacebookIntegration() | ||
| super.init() | ||
| } | ||
|
|
||
| // MARK: - ObjCIntegrationPlugin Methods | ||
|
|
||
| /** | ||
| Returns the Facebook App Events SDK instance. | ||
|
|
||
| - Returns: The Facebook App Events SDK instance, or nil if not initialized. | ||
| */ | ||
| @objc | ||
| public func getDestinationInstance() -> Any? { | ||
| return facebookIntegration.getDestinationInstance() | ||
| } | ||
|
|
||
| /** | ||
| Creates and configures the Facebook SDK with the provided destination configuration. | ||
|
|
||
| - Parameters: | ||
| - destinationConfig: Configuration dictionary from RudderStack dashboard. | ||
| - errorPointer: A pointer to an NSError that will be set if initialization fails. | ||
| - Returns: `true` if initialization succeeded, `false` otherwise. | ||
| */ | ||
| @objc | ||
| public func createWithDestinationConfig(_ destinationConfig: [String: Any], error errorPointer: NSErrorPointer) -> Bool { | ||
| do { | ||
| try facebookIntegration.create(destinationConfig: destinationConfig) | ||
| return true | ||
| } catch let err as NSError { | ||
| errorPointer?.pointee = err | ||
| return false | ||
| } catch { | ||
| errorPointer?.pointee = NSError( | ||
| domain: "com.rudderstack.FacebookIntegration", | ||
| code: -1, | ||
| userInfo: [NSLocalizedDescriptionKey: error.localizedDescription] | ||
| ) | ||
| return false | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| Updates the Facebook SDK configuration with the provided destination configuration. | ||
|
|
||
| - Parameters: | ||
| - destinationConfig: Updated configuration dictionary from RudderStack dashboard. | ||
| - errorPointer: A pointer to an NSError that will be set if update fails. | ||
| - Returns: `true` if update succeeded, `false` otherwise. | ||
| */ | ||
| @objc | ||
| public func updateWithDestinationConfig(_ destinationConfig: [String: Any], error errorPointer: NSErrorPointer) -> Bool { | ||
| do { | ||
| try facebookIntegration.update(destinationConfig: destinationConfig) | ||
| return true | ||
| } catch let err as NSError { | ||
| errorPointer?.pointee = err | ||
| return false | ||
| } catch { | ||
| errorPointer?.pointee = NSError( | ||
| domain: "com.rudderstack.FacebookIntegration", | ||
| code: -1, | ||
| userInfo: [NSLocalizedDescriptionKey: error.localizedDescription] | ||
| ) | ||
| return false | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| Resets the integration state. | ||
|
|
||
| This clears the user ID and user data from Facebook App Events. | ||
| */ | ||
| @objc | ||
| public func reset() { | ||
| facebookIntegration.reset() | ||
| } | ||
|
|
||
| // MARK: - ObjCEventPlugin Methods | ||
|
|
||
| /** | ||
| Processes a track event and forwards it to the underlying Facebook integration. | ||
|
|
||
| - Parameter payload: The ObjC track event payload. | ||
| */ | ||
| @objc | ||
| public func track(_ payload: ObjCTrackEvent) { | ||
| var trackEvent = TrackEvent( | ||
| event: payload.eventName, | ||
| properties: payload.properties, | ||
| options: payload.options | ||
| ) | ||
| trackEvent.anonymousId = payload.anonymousId | ||
| trackEvent.userId = payload.userId | ||
|
|
||
| facebookIntegration.track(payload: trackEvent) | ||
| } | ||
|
|
||
| /** | ||
| Processes an identify event and forwards it to the underlying Facebook integration. | ||
|
|
||
| - Parameter payload: The ObjC identify event payload. | ||
| */ | ||
| @objc | ||
| public func identify(_ payload: ObjCIdentifyEvent) { | ||
| var identifyEvent = IdentifyEvent(options: payload.options) | ||
| identifyEvent.anonymousId = payload.anonymousId | ||
| identifyEvent.userId = payload.userId | ||
| if let context = payload.context { | ||
| identifyEvent.context = context.mapValues { AnyCodable($0) } | ||
| } | ||
|
|
||
| facebookIntegration.identify(payload: identifyEvent) | ||
| } | ||
|
|
||
| /** | ||
| Processes a screen event and forwards it to the underlying Facebook integration. | ||
|
|
||
| - Parameter payload: The ObjC screen event payload. | ||
| */ | ||
| @objc | ||
| public func screen(_ payload: ObjCScreenEvent) { | ||
| var screenEvent = ScreenEvent( | ||
| screenName: payload.screenName, | ||
| category: payload.category, | ||
| properties: payload.properties, | ||
| options: payload.options | ||
| ) | ||
| screenEvent.anonymousId = payload.anonymousId | ||
| screenEvent.userId = payload.userId | ||
|
|
||
| facebookIntegration.screen(payload: screenEvent) | ||
| } | ||
| } | ||
SKannaniOS marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.