LogoLogo
SDK ReferenceChangelogBlogStatusGet HelpGo To Dashboard
  • Introduction
  • Basics
    • How ContextDecision Works
    • How ContextPush Works
    • Getting Started
  • Context Decision
    • Logging Conversions
    • Revenue Outcomes
      • Logging Revenue with RevenueCat
    • Adding Entry Points
    • Release Checklist
    • Advanced
      • Custom Signals
      • Alternative Outcomes
      • Custom Outcome Metadata
      • Listening for Good Moments
      • Model Distribution Methods
      • Custom A/B Test Segmentation
      • Analytics & Reporting
  • Context Push
    • Integrating ContextPush
    • Push Notification Providers
      • OneSignal
      • Customer.io
      • Simple Web Request
    • Release Checklist
    • Analytics & Reporting
  • Discover By Use Cases
    • Multivariate Monetization
    • Inline Banners
  • Other Information
    • Glossary
    • Updating Your SDK
    • Minimum SDK Requirements
    • FAQ
    • Get Help
    • Changelog
  • Advanced
    • Custom Configuration
    • Capturing Context In Key Moments
Powered by GitBook
On this page

Was this helpful?

  1. Context Push

Integrating ContextPush

Follow this step-by-step process to integrate ContextPush with your iOS app.

PreviousAnalytics & ReportingNextPush Notification Providers

Last updated 24 days ago

Was this helpful?

ContextPush currently is only supported for iOS. If you’re interested in using ContextPush in other platforms or languages, contact us at .

1

Create a License Key & Install the SDK

Check out Getting Started for details on how to create your license key and install the SDK.

2

Import ContextSDK

AppDelegate.swift
import ContextSDK
3

Ensure Remote Notification Entitlement

In your Xcode project, go to Signing & Capabilities and enable the Remote Notification capability in the Background Modes section.

4

Provide User ID and Push Token

You need to register the user's device with a unique user ID and the device's push token. The user-id may be whatever you use to identify each user in your existing push notification system, e.g. an email address or a user ID from your database.

AppDelegate.swift
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    // Your existing code for handling device token registration

    // Set the device token and user ID with ContextSDK to enable push notifications
    ContextPush.setDeviceToken(deviceToken).setUserId(userId)
}
AppDelegate.swift
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
  // Your existing code for handling device token registration

  // Set the device token with ContextSDK to register the device for push notifications
  ContextPush.setDeviceToken(deviceToken)
}
// Set the user ID once it is available to associate notifications with the correct user
ContextPush.setUserId(userId)
5

Handle Background Notifications

Ensure that your app can handle push notifications received while in the background by implementing the following method:

AppDelegate.swift
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any],fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    // ContextSDK will process the notification if it is a valid ContextPush notification
    // The completion handler will be automatically called if processed
    if ContextPush.applicationDidReceiveRemoteNotification(userInfo, fetchCompletionHandler: completionHandler) {
        return
    }
    // Handle other types of background notifications with your existing code, if needed
}
6

Handle Notification Opens

Track when users open notifications to gather engagement metrics and improve user experience:

AppDelegate.swift
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
    // Process the notification with ContextSDK to track open rates and user interactions
    ContextPush.userNotificationCenterDidReceiveResponse(response)

    // Your existing code
    // Ensure completion handler is called to finalize notification handling
    completionHandler()
}
7

Test Your Setup

  1. Visit your

  2. Select Integrate Push in the menu

    • If this option is still not available to you, request access in Products Info → ContextPush

  3. Upload your push certificate and fill in the necessary information

    • This will grant you access to your API token, which will be used later on.

    • You can either create a new push certificate for ContextPush, or use your existing one.

  4. Test your push setup by using the Test Push Integration feature

8

Integrate With Your Push Notification Provider

You're now done integrating with the iOS app. Next, integrate with your existing push provider:

If you can't find your provider in this list, don't worry: you can integrate ContextPush with any provider, as long as it supports webhooks. Reach out to us to let us know which provider you use and we'll guide you through the integration steps.

support@contextsdk.com
dashboard
OneSignal
Customer.io
Simple Web Request