Skip to content

Deep Linking Integration

Segmentify Push Notifications fully support Deep Linking, allowing you to redirect users to specific content (e.g., a specific product page, a category, or a custom promotion screen) directly when they tap on a notification.

When a Deep Link is defined in your campaign via the Segmentify Dashboard, it is delivered to your application within the notification payload. Your application needs to handle this URL to perform the navigation.


Notification Payload Structure

Segmentify sends the deep link URL inside the payload data.

  • iOS: Custom key in the root dictionary (e.g., deeplink).
  • Android: Inside the data object.

Example Payload:

{
  "to": "device_token",
  "notification": {
    "title": "Super Sale!",
    "body": "Check out this product."
  },
  "data": {
    "deeplink": "myapp://product?id=12345"
  },
  "deeplink": "myapp://product?id=12345"
}

iOS Implementation

To handle deep links on iOS, you must define a URL Scheme and handle the incoming URL in your AppDelegate or SceneDelegate.

  • Step 1: Define URL Scheme Add your custom URL scheme to your Info.plist file. This tells iOS that your app is responsible for opening URLs starting with your scheme (e.g., segmentify:// or myapp://).
<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>myapp</string> 
        </array>
        <key>CFBundleURLName</key>
        <string>com.yourcompany.app.deeplink</string>
    </dict>
</array>
  • Step 2: Handle Notification Click In your AppDelegate, intercept the notification click and instruct the system to open the URL.
// In AppDelegate.swift
import UserNotifications

extension AppDelegate: UNUserNotificationCenterDelegate {

    func userNotificationCenter(_ center: UNUserNotificationCenter,
                                didReceive response: UNNotificationResponse,
                                withCompletionHandler completionHandler: @escaping () -> Void) {

        let userInfo = response.notification.request.content.userInfo

        // Extract the deep link string from the payload
        // Note: Ensure the key matches what is sent from Segmentify (e.g. "deeplink")
        if let deepLinkString = userInfo["deeplink"] as? String,
           let url = URL(string: deepLinkString) {

            // Open the URL (This triggers SceneDelegate or SwiftUI onOpenURL)
            DispatchQueue.main.async {
                UIApplication.shared.open(url, options: [:], completionHandler: nil)
            }
        }
        completionHandler()
    }
}
  • Step 3: Handle Navigation (SwiftUI Example) Listen for the URL in your main entry view using .onOpenURL.
// In ContentView.swift or your App struct

var body: some View {
    ContentView()
        .onOpenURL { url in
            print("Deep link received: \(url)")
            // Add your navigation logic here
            // Example: parse url.query to find Product ID and navigate
        }
}

Android Implementation

On Android, deep links are handled via IntentFilters in your AndroidManifest.xml and parsed within your Activity.

  • Step 1: Configure Manifest Add an to the Activity that should handle the deep link (usually your MainActivity or a specific DeepLinkActivity).
    <activity android:name=".MainActivity" android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
    
            <data android:scheme="myapp" android:host="product" />
        </intent-filter>
    </activity>
    
  • Step 2: Parse Intent Data When the notification is clicked, Segmentify SDK (or your custom service) triggers the Intent. You can retrieve the URL in your Activity's onCreate or onNewIntent method.
// In MainActivity.kt

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    // Check if app was started via a Deep Link Intent
    handleIntent(intent)
}

override fun onNewIntent(intent: Intent) {
    super.onNewIntent(intent)
    // Handle deep link if activity is already running
    handleIntent(intent)
}

private fun handleIntent(intent: Intent?) {
    // 1. Check data from standard Deep Link (Intent Filter)
    if (intent?.action == Intent.ACTION_VIEW) {
        val data: Uri? = intent.data
        navigateToProduct(data)
    }

    // 2. Check data from Notification Extras (if passed as Bundle from push SDK)
    if (intent?.hasExtra("deeplink") == true) {
        val urlString = intent.getStringExtra("deeplink")
        if (urlString != null) {
            val uri = Uri.parse(urlString)
            navigateToProduct(uri)
        }
    }
}

private fun navigateToProduct(uri: Uri?) {
    // Parse parameters and navigate
    val productId = uri?.getQueryParameter("id")

    if (productId != null) {
        // Logic to open Product Detail Fragment/Activity
        Log.d("Segmentify", "Navigating to product: $productId")
    }
}