Getting started with the iOS SDK

Convertedin SDK for events and push notifications is a powerful tool for developers to create engaging and personalized experiences for your app users. With this SDK, developers can easily track user behavior and send targeted push notifications to drive engagement and increase retention. Push notifications allow developers to reach users even when they're not actively using the app, keeping them up to date with the latest news, updates, and promotions. By leveraging Convertedin SDK for events and push notifications, developers can create more meaningful and impactful experiences for their users, leading to higher engagement, increased user satisfaction, and ultimately, greater success for their app.


Requirements

The Convertedin iOS SDK requires Xcode 10.1 or later and is compatible with apps targeting iOS 13 or above.


SDK Integration

You can easily integrate Convertedin Mobile SDK into your projects using one of the following methods:

Method 1: Using Swift Package Manager

To integrate ConvertedinMobileSDK into your iOS project using Swift Package Manager, follow these simple steps:

  • Open Your Project: In Xcode

  • open your project workspace or project file where you want to add the framework.

  • Go to the "File" menu.

  • Select "Swift Packages."

  • Choose "Add Package Dependency..."

  • Enter the Repository URL:

 https://github.com/iOS-convertedin-eslamali/iOS_ConvertedinMobileSDK.git 
  • Click "Next & Finish"

  • Build and Run:

  • Xcode will automatically resolve and fetch the framework package.

  • Build and run your project to start using ConvertedinMobileSDK in your application

And that's it! You've successfully integrated ConvertedinMobileSDK into your project using Swift Package Manager. 🚀


Method 2: Cocoapods

To effortlessly integrate ConvertedinMobileSDK into your iOS project using CocoaPods, follow these straightforward steps: First you need to install cocaopods, Here's a comprehensive guide on how to install cocoapods Cocoapods documentation

After installing the Cocoapods successfully

  • Open the Podfile in a text editor and add the following line.

 pod 'ConvertedinMobileSDK'
  • Run the following command to install the framework and its dependencies:

pod install

You can now import and use ConvertedinMobileSDK in your iOS project. Xcode will handle the linking and configuration. And that's it! You've successfully integrated ConvertedinMobileSDK into your project using CocoaPods. 🚀


Getting Started

Step 1: Convertedin Mobile SDK Configuration

  • Open your app's AppDelegate.swift file.

  • Import ConvertedinMobileSDK at the top of AppDelegate.swift using the following line of code

 import ConvertedinMobileSDK
  • In the application(_:didFinishLaunchingWithOptions:) method, integrate our framework by adding the following code:

 ConvertedinMobileSDK.configure(pixelId: "Pixel_id", storeUrl: "store@test.com")

Make sure to set the pixelId and storeUrl as the appropriate initialization parameters for your use case. These parameters are crucial for configuring the SDK with your desired settings.


Step 2: Authenticate user by Sending user data

  • The "Identify User" API in the ConvertedinMobileSDK allows developers to track and identify users across different devices and sessions. When a user logs in or creates an account, the developer can use the Identify User API to associate a unique identifier with that user.

  • This identifier can then be used to track the user's actions and behavior throughout their usage of the application. For example, if a user makes a purchase or completes a form, the Identify User API can associate that action with the user's unique identifier.

  • By using the Identify User API, developers can gain valuable insights into their user's behavior, preferences, and interests. This information can then be used to improve the user experience, personalize content, and increase user engagement and retention.

  • Additionally, the Identify User API can also be used to implement security measures such as authentication and authorization, by verifying that a user is who they claim to be and granting them access to certain features or content.

  • Overall, the Identify User API is a powerful tool for developers to understand and optimize their user's experience, as well as provide a more secure and personalized platform for their users.

This function is currently deprecated and will be removed in future versions. Please use the following methods instead:

  • Login(): Use this for logging users into the system.

  • Register(): Use this for new user registrations.

  • SetUserData(): Use this to set or update user information.

// This function currently deprecated and will be removed in future versions.
ConvertedinMobileSDK.identifyUser(email: "test@converted.in", countryCode: nil, phone: nil)

In this code snippet, you have the option to identify the user using either their email or phone number. Replace "test@converted.in" with the user's email address and provide the appropriate country code if you are identifying the user by phone number.


Register Action

Overview

This function is typically triggered when a user signs up for an account or registers their information. By tracking Register events, developers can gain insights into user acquisition and onboarding processes and optimize their registration flow accordingly.

Parameters

  • email: The user's email address (required if registering by email).

  • phone: The user's phone number (required if registering by phone).

Example Usage

 ConvertedinMobileSDK.register(email: "test@converted.in")
 ConvertedinMobileSDK.register(phone: "1234567890", countryCode: "+20")

Note: Please replace the example email or phone number with real user data to successfully register the user.


Login Action

Overview

This function is typically triggered when a user login into your app. By tracking login action, developers can gain insights into user acquisition and onboarding processes and optimize their login flow accordingly.

Parameters

  • email: The user's email address (required if logging by email).

  • phone: The user's phone number (required if logging by phone).

Example Usage

 ConvertedinMobileSDK.login(email: "test@converted.in")
 ConvertedinMobileSDK.login(phone: "1234567890", countryCode: "+20")

Note: Please replace the example email or phone number with real user data to successfully login the user.

SerUserData Action

Overview

This function is commonly used to set the current customer data, for example email or phone and should be used in the first screen of the app.

Parameters

  • email: The user's email address (required if seting user email).

  • phone: The user's phone number (required if setting user phone).

Example Usage

 ConvertedinMobileSDK.setUserData(phone: "1234567890", countryCode: "+20")
 ConvertedinMobileSDK.setUserData(email: "test@converted.in")

Note: Please replace the example email or phone number with real user data to successfully register the user.


Step 3: Track user events and actions through your app.

ConvertedinMobileSDK offers a set of predefined events that are commonly used in most e-commerce applications. These predefined events include:

  • ViewContent: To track when a user views content, such as a product.

  • PageView: To track when a user views a specific page.

  • AddToCart: To track when a user adds an item to their cart.

  • InitiateCheckout: To track when a user initiates the checkout process.

  • Purchase: To track when a user completes a purchase.

You can use these predefined events to gather valuable data and insights about user interactions in your application effortlessly.

If the predefined events do not fully meet your tracking needs, don't worry! ConvertedinMobileSDK allows you to create your own custom events using unique identifiers. This flexibility enables you to tailor event tracking to the specific actions and interactions that matter most to your application.

By leveraging both predefined and custom events, you can gain a comprehensive understanding of user behavior and make data-driven decisions to enhance your e-commerce application.

you can use a predefined events with the following code:

ConvertedinMobileSDK.pageViewEvent()
ConvertedinMobileSDK.viewContentEvent()
ConvertedinMobileSDK.AddToCartEvent()
ConvertedinMobileSDK.InitiateCheckoutEvent()
ConvertedinMobileSDK.PurchaseEvent()

or you can create your custom events using the following code:

ConvertedinMobileSDK.addEvent()
  • Please, be mindful of methods that require parameters related to currency, total price, and a set of products. These parameters are crucial for accurate event tracking and analytics in your e-commerce application.


Step 4: Configure Push Notifications

To enable notifications in this framework, you need to integrate it with Google Firebase services. Firebase provides a robust platform for handling notifications, making it easy to send and receive messages in your application.

  1. Create a Firebase Project:

    • If you haven't already, create a Firebase project in the Firebase console.

    • Add your iOS app to the Firebase project by following the steps in the Firebase console.

  2. Add the Firebase SDK to Your iOS App Using Swift Package Manager

  • Open Your Project: In Xcode

  • open your project workspace or project file where you want to add the framework.

  • Go to the "File" menu.

  • Select "Swift Packages."

  • Choose "Add Package Dependency..."

  • Enter the Repository URL:

 https://github.com/firebase/firebase-ios-sdk.
  • Select the following Firebase packages: (FirebaseCore, FirebaseMessaging )

  • Click Add Package.

  1. Configure Firebase in Your App:

  • Download the GoogleService-Info.plist file from the Firebase console.

  • Add the GoogleService-Info.plist file to your Xcode project by dragging it into the project navigator.

  1. Open your AppDelegate.swift and configure Firebase by adding the following code:

  • Open your app's AppDelegate.swift file.

  • Import Firebase at the top of AppDelegate.swift using the following line of code

 import Firebase
  • In the application(_:didFinishLaunchingWithOptions:) method, integrate our framework by adding the following code:

 FirebaseApp.configure()

Step 5: Save Device Token

  • After Setup the Push Notification successfully, Implement the didReceiveRegistrationToken method in your AppDelegate.swift file to receive the FCM device token. This method is called when a new token is generated or an existing token is updated, with the following code

 func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
        if let fcmToken = fcmToken {
           ConvertedinMobileSDK.setFcmToken(token: fcmToken )
        }
    }

Step 6: Pass Campaign ID

  • When a user clicks on a push notification, you need to pass the campaign ID to the SDK's onPushNotificationClicked()

  • function. The campaign ID can be found in the payload of the push notification, typically under the key "campaign_id".

Here's how to implement this:

  1. Retrieve the Campaign ID: In the userNotificationCenter(_:didReceive:withCompletionHandler:)method, access the userInfo dictionary from the notification response.

  2. Pass the Campaign ID: If the campaign ID exists in the userInfo, pass it to onPushNotificationClicked().

    func userNotificationCenter(_ center: UNUserNotificationCenter,
                                didReceive response: UNNotificationResponse,
                                withCompletionHandler completionHandler: @escaping () -> Void) {
        
        let userInfo = response.notification.request.content.userInfo
        if let campaingId = userInfo["campaign_id"] as? String {
            ConvertedinMobileSDK.onPushNotificationClicked(campaignId: campaingId)
        }
        completionHandler()
    }

Logging Out or Notification Cessation

  • If you want to stop geting our notification or when the user logout, call our ConvertedinMobileSDK's deleteDeviceToken method to unregister the device for notifications. This ensures that the user no longer receives notifications from your app.

ConvertedinMobileSDK.deleteDeviceToken()

Integrating Firebase for In-App Messages

step 1: Integrate with Firebase via Swift Package Manage

To enable Firebase In-App Messages in your application, it is recommended to install Firebase via a swift package manager. Follow the steps below to seamlessly integrate Firebase and create a new campaign with an in-app message:

  • Open Your Project: In Xcode

  • open your project workspace or project file where you want to add the framework.

  • Go to the "File" menu.

  • Select "Swift Packages."

  • Choose "Add Package Dependency"

  • Enter the Repository URL:

 https://github.com/firebase/firebase-ios-sdk.git 

step 2: Import Firebase in AppDelegate File and Configure

import Firebase

Inside the application(_:didFinishLaunchingWithOptions:) method, add the following code to configure Firebase:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 
    FirebaseApp.configure()
}

Step 3: Create a New In-App Message Campaign and Customize Style

Now that you have integrated Firebase In-App Messaging, you can create a new in-app message campaign and customize the style to deliver a personalized experience to your users.

  • Navigate to the Firebase Console.

  • Select your project.

  • In the left menu, click on "In-App Messaging."

  • Click on the "New Campaign" button.

  • Follow the on-screen instructions to set up your campaign, including targeting options, triggers, and scheduling.

Congratulations! By diligently following the steps outlined above, you have successfully integrated Firebase In-App Messaging into your iOS app. Your users are now ready to receive targeted and visually appealing in-app messages.

License

This project is licensed under the MIT License - see the LICENSE file for details.

in the Feedback rate the number 1: mean very bad rate the number 5: mean Excellent rate

Last updated