Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions contents/docs/libraries/ios/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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 | — |


Expand Down Expand Up @@ -237,4 +238,5 @@ The [`PostHogConfig` object](https://github.com/PostHog/posthog.com/pull/13379/f
| `appGroupIdentifier`<br/><br/>**Type:** String<br/>**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`<br/><br/>**Type:** Boolean<br/>**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`<br/><br/>**Type:** Boolean<br/>**Default:** `true` | Enable Surveys. |
| `capturePushNotificationSubscriptions`<br/><br/>**Type:** Boolean<br/>**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`<br/><br/>**Type:** Function<br/>**Default:** `undefined` | Hook that allows for amending, sampling, or dropping events before they are sent to PostHog. |
49 changes: 49 additions & 0 deletions contents/docs/libraries/ios/usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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: "<ph_project_token>", host: "<ph_client_api_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).
Expand Down
9 changes: 7 additions & 2 deletions contents/docs/workflows/_snippets/channel-platforms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
]
Expand Down
44 changes: 42 additions & 2 deletions contents/docs/workflows/configure-channels.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ Other than the channels shown below, you can also dispatch to any [realtime dest
<Tab.Group tabs={[
'Email',
'Slack',
'Twilio']}>
'Twilio',
'APNS',
'FCM']}>
<Tab.List>
<Tab>Email</Tab>
<Tab>Slack</Tab>
<Tab>Twilio</Tab>
<Tab>APNS</Tab>
<Tab>FCM</Tab>
</Tab.List>
<Tab.Panels>
<Tab.Panel>
Expand Down Expand Up @@ -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.

</Tab.Panel>
<Tab.Panel>

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.

<CalloutBox icon="IconInfo" title="iOS SDK setup required" type="fyi">

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.

</CalloutBox>

</Tab.Panel>
<Tab.Panel>

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.

</Tab.Panel>
</Tab.Panels>
</Tab.Group>
Expand All @@ -88,7 +128,7 @@ Once configured, you'll be able to use the channel in a workflow to send SMS mes

<Step title="Create a template" badge="recommended">

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**.

Expand Down
2 changes: 1 addition & 1 deletion contents/docs/workflows/installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion contents/docs/workflows/library.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion contents/docs/workflows/start-here.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
9 changes: 5 additions & 4 deletions contents/docs/workflows/workflow-builder.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down Expand Up @@ -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

Expand Down
Loading