diff --git a/contents/docs/libraries/ios/configuration.mdx b/contents/docs/libraries/ios/configuration.mdx index 5db096ca2312..8a9003d1b63e 100644 --- a/contents/docs/libraries/ios/configuration.mdx +++ b/contents/docs/libraries/ios/configuration.mdx @@ -183,6 +183,7 @@ Method swizzling is enabled by default, but can be disabled by setting the relev | Element interactions | Automatically tracks user interactions with UI elements | `config.captureElementInteractions` | | Session replay | Records user sessions | `config.sessionReplay` | | Surveys | Displays surveys at appropriate times | `config.surveys` | +| Push notification subscription | Automatically registers device tokens and captures push notification opened events | `config.capturePushNotificationSubscriptions` | | Advanced metrics tracking | Provides more precise session ID calculation and rotation by detecting user activity and idleness | — | @@ -237,4 +238,5 @@ The [`PostHogConfig` object](https://github.com/PostHog/posthog.com/pull/13379/f | `appGroupIdentifier`

**Type:** String
**Default:** `nil` | The identifier of the App Group that should be used to store shared analytics data. PostHog will try to get the physical location of the App Group's shared container, otherwise fallback to the default location. | | `reuseAnonymousId`

**Type:** Boolean
**Default:** `false` | Whether the SDK should reuse the anonymous Id between user changes. When enabled, a single Id will be used for all anonymous users on this device. | | `surveys`

**Type:** Boolean
**Default:** `true` | Enable Surveys. | +| `capturePushNotificationSubscriptions`

**Type:** Boolean
**Default:** `true` | (iOS/macOS only) When enabled and swizzling is also enabled, the SDK automatically registers device tokens for push notification subscriptions and captures `$push_notification_opened` events when users tap push notifications. See the [push notifications usage guide](/docs/libraries/ios/usage#push-notifications) for more details. | | `setBeforeSend`

**Type:** Function
**Default:** `undefined` | Hook that allows for amending, sampling, or dropping events before they are sent to PostHog. | diff --git a/contents/docs/libraries/ios/usage.mdx b/contents/docs/libraries/ios/usage.mdx index 5e15f714820e..b4b18121110c 100644 --- a/contents/docs/libraries/ios/usage.mdx +++ b/contents/docs/libraries/ios/usage.mdx @@ -212,6 +212,55 @@ Starting with iOS 14, Apple will further restrict apps that track users. Any ref Hence **starting with posthog-ios version 1.2.0** we have removed all references to Apple's AdSupport framework. +## Push notifications + +The PostHog iOS SDK supports push notifications for [Workflows](/docs/workflows). Once configured, the SDK automatically handles device token registration for push notification subscriptions and tracks when users open push notifications. + +### Requesting permission and registering for push notifications + +Call `requestPushNotificationPermission` to prompt the user for notification permission and automatically register for remote notifications: + +```swift +PostHogSDK.shared.requestPushNotificationPermission() +``` + +This method requests notification authorization via `UNUserNotificationCenter` and, if granted, calls `UIApplication.shared.registerForRemoteNotifications()` automatically. + +### Automatic device token handling + +When swizzling is enabled (the default), the SDK automatically intercepts your app delegate's `application(_:didRegisterForRemoteNotificationsWithDeviceToken:)` method and sends the device token to PostHog. No manual wiring is needed. + +If you have swizzling disabled, you need to manually forward the device token: + +```swift +func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { + PostHogSDK.shared.handlePushNotificationDeviceToken(deviceToken) +} +``` + +### Automatic open tracking + +When `capturePushNotificationSubscriptions` is enabled (the default) and swizzling is on, the SDK automatically captures a `$push_notification_opened` event when a user taps a push notification. This event includes the following properties: + +| Property | Description | +|----------|-------------| +| `$notification_title` | The title of the notification | +| `$notification_subtitle` | The subtitle of the notification | +| `$notification_body` | The body text of the notification | +| `$notification_action` | The action identifier, if the user tapped a custom action | + +Any key-value pairs in a `posthog` dictionary within the notification's `userInfo` payload are also captured, prefixed with `$notification_`. + +### Disabling push notification subscription + +To disable automatic push notification subscription and open tracking, set `capturePushNotificationSubscriptions` to `false` in your config: + +```swift +let config = PostHogConfig(apiKey: "", host: "") +config.capturePushNotificationSubscriptions = false +PostHogSDK.shared.setup(config) +``` + ## Session replay > **Note:** Session replay is currently only available on iOS. For future macOS support, please follow and upvote [this GitHub issue](https://github.com/PostHog/posthog-ios/issues/200). diff --git a/contents/docs/workflows/_snippets/channel-platforms.tsx b/contents/docs/workflows/_snippets/channel-platforms.tsx index d00add93f60d..8aa95cff519a 100644 --- a/contents/docs/workflows/_snippets/channel-platforms.tsx +++ b/contents/docs/workflows/_snippets/channel-platforms.tsx @@ -20,8 +20,13 @@ const ChannelPlatforms = () => { image: 'https://res.cloudinary.com/dmukukwp6/image/upload/q_auto,f_auto/twilio_860042a891.png', }, { - label: 'Push', - badge: 'Coming soon', + label: 'Push (APNS)', + url: '/docs/workflows/configure-channels?tab=APNS', + image: 'https://res.cloudinary.com/dmukukwp6/image/upload/push_8ac7759b08.svg', + }, + { + label: 'Push (FCM)', + url: '/docs/workflows/configure-channels?tab=FCM', image: 'https://res.cloudinary.com/dmukukwp6/image/upload/push_8ac7759b08.svg', }, ] diff --git a/contents/docs/workflows/configure-channels.mdx b/contents/docs/workflows/configure-channels.mdx index 7d7d1f01615a..0810a65fdd82 100644 --- a/contents/docs/workflows/configure-channels.mdx +++ b/contents/docs/workflows/configure-channels.mdx @@ -24,11 +24,15 @@ Other than the channels shown below, you can also dispatch to any [realtime dest + 'Twilio', + 'APNS', + 'FCM']}> Email Slack Twilio + APNS + FCM @@ -80,6 +84,42 @@ Twilio enables you to send SMS messages to your users. To configure the channel, Once configured, you'll be able to use the channel in a workflow to send SMS messages to your users. + + + +Apple Push Notification Service (APNS) enables you to send push notifications to iOS and macOS devices. + +To configure the channel, you need the following from your [Apple Developer account](https://developer.apple.com/account/resources/authkeys/list): + +| Field | Example | Description | +|-------------------|-------------------------|--------------------------------------------------| +| **Signing key (.p8)** | Contents of your `.p8` file | The private key used to sign push notification requests. Generate one under **Keys** in your Apple Developer account. | +| **Key ID** | `ABC123DEFG` | The 10-character identifier for your signing key, shown on the key details page. | +| **Apple team ID** | `ABCDE12345` | Your Apple Developer team ID, found in the top-right of the Apple Developer portal. | +| **Bundle ID** | `com.example.app` | Your app's bundle identifier, as configured in Xcode. | + +Once configured, you can use APNS as a dispatch step in the workflow builder to send push notifications to your iOS users. + + + +To deliver push notifications, you need the [PostHog iOS SDK](/docs/libraries/ios) installed in your app. The SDK automatically registers device tokens with PostHog so notifications can be delivered. See the [iOS push notification setup guide](/docs/libraries/ios/usage#push-notifications) for details. + + + + + + +Firebase Cloud Messaging (FCM) enables you to send push notifications to Android devices. + +To configure the channel, you need a **service account key** from your Firebase project: + +1. Go to the [Firebase Console](https://console.firebase.google.com/). +2. Select your project, then navigate to **Project settings** > **Service accounts**. +3. Click **Generate new private key** to download a JSON file. +4. Paste the contents of this JSON file into the **Service account key** field in PostHog. + +Once configured, you can use FCM as a dispatch step in the workflow builder to send push notifications to your Android users. + @@ -88,7 +128,7 @@ Once configured, you'll be able to use the channel in a workflow to send SMS mes -If you plan to send email messages, you can create a template to reuse across your workflows. If you only plan to send Slack and SMS messages, you do not need to create a template. +If you plan to send email messages, you can create a template to reuse across your workflows. If you only plan to send Slack, SMS, or push notification messages, you do not need to create a template. Navigate to **Workflows** > **Library** tab > click **New template**. diff --git a/contents/docs/workflows/installation.mdx b/contents/docs/workflows/installation.mdx index 3a6dcdf4bf20..b36570dfc6bb 100644 --- a/contents/docs/workflows/installation.mdx +++ b/contents/docs/workflows/installation.mdx @@ -36,7 +36,7 @@ Without an SDK, you can still trigger Workflows programmatically using [webhooks ## Set up Workflows -Now that PostHog is installed, any captured or custom event can be used as a [workflow trigger](/docs/workflows/workflow-builder#triggers) to send emails, Slack messages, SMS via Twilio, or call webhooks. +Now that PostHog is installed, any captured or custom event can be used as a [workflow trigger](/docs/workflows/workflow-builder#triggers) to send emails, Slack messages, push notifications, SMS via Twilio, or call webhooks. To get started: diff --git a/contents/docs/workflows/library.mdx b/contents/docs/workflows/library.mdx index 6f4ad676ae89..fd43f0519f9f 100644 --- a/contents/docs/workflows/library.mdx +++ b/contents/docs/workflows/library.mdx @@ -12,7 +12,7 @@ Our library lets you create reusable message templates for your workflows. You c alt="Library" /> -Currently, we support email templates, with push notifications and SMS templates coming soon. +Currently, we support email templates, with push notification and SMS templates coming soon. ## Workflow templates diff --git a/contents/docs/workflows/start-here.mdx b/contents/docs/workflows/start-here.mdx index 5026407af915..ae33dee87906 100644 --- a/contents/docs/workflows/start-here.mdx +++ b/contents/docs/workflows/start-here.mdx @@ -45,7 +45,7 @@ Workflows are made up of the following building blocks: | Component | Description | |-----------|-------------| | [Triggers](/docs/workflows/workflow-builder#triggers) | What starts the workflow. We let you start a workflow when an event is performed (e.g. a user signs up), or programmatically via a webhook. | -| [Dispatches](/docs/workflows/workflow-builder#dispatches) | The messages you send, mail, slack, SMS, webhook, or any PostHog real time destinations. | +| [Dispatches](/docs/workflows/workflow-builder#dispatches) | The messages you send: email, Slack, SMS, push notifications, webhook, or any PostHog real-time destinations. | | [Delays](/docs/workflows/workflow-builder#delays) | Wait steps such as "wait 2 days" or "wait until condition is true." | | [Audience splits](/docs/workflows/workflow-builder#audience-splits) | Target and split the users you message with more specificity or try a/b testing with random branching. | | [PostHog actions](/docs/workflows/workflow-builder#posthog-actions) | Change a person's properties, or trigger other events, once a person reaches a specific point in your workflow. | diff --git a/contents/docs/workflows/workflow-builder.mdx b/contents/docs/workflows/workflow-builder.mdx index 11c1d9080125..07d2cbb887c4 100644 --- a/contents/docs/workflows/workflow-builder.mdx +++ b/contents/docs/workflows/workflow-builder.mdx @@ -16,7 +16,7 @@ Workflows are composed of the following components: | Component | Description | |-----------|-------------| | [Triggers](#triggers) | What starts the workflow. We let you start a workflow when an event is performed (e.g. a user signs up), or programmatically via a webhook. | -| [Dispatches](#dispatches) | The messages you send, mail, slack, SMS, webhook, or any PostHog real time destinations. | +| [Dispatches](#dispatches) | The messages you send: email, Slack, SMS, push notifications, webhook, or any PostHog real-time destinations. | | [Delays](#delays) | Wait steps such as "wait 2 days" or "wait until condition is true." | | [Audience splits](#audience-splits) | Target and split your users so you can automate some action for them or send a message with more specificity. | | [PostHog actions](#posthog-actions) | Change a person's properties, or trigger other events, once a person reaches a specific point in your workflow. | @@ -61,14 +61,15 @@ To filter your events, click on the three lines icon next to the event name and ## Dispatches -Dispatches are the messages you send, mail, slack, SMS, webhook, or any PostHog real time destinations. There are 4 main types of dispatches: +Dispatches are the messages you send: email, Slack, SMS, push notifications, webhook, or any PostHog real-time destinations. There are 5 main types of dispatches: | Dispatch type | Description | |--------------|-------------| | Email | Send an email natively through PostHog. Configured in the [channels](/docs/workflows/configure-channels) section. | -| Slack | Send a message to a slack channel. Configured in the [channels](/docs/workflows/configure-channels) section. | +| Slack | Send a message to a Slack channel. Configured in the [channels](/docs/workflows/configure-channels) section. | +| Push notifications | Send mobile push notifications via Apple Push Notification Service (APNS) or Firebase Cloud Messaging (FCM). Configured in the [channels](/docs/workflows/configure-channels) section. | | Webhook | Call external systems. Configured in the [channels](/docs/workflows/configure-channels) section. | -| CDP destinations | Use any [realtime destination](/docs/cdp/destinations) as an dispatch step to deliver messages to users or other services. | +| CDP destinations | Use any [realtime destination](/docs/cdp/destinations) as a dispatch step to deliver messages to users or other services. | ## Delays