# Reduce App Churn with Notifications

This guide will walk you through using the Critical Moments SDK to send your users notifications, which can increase your app’s activation rates and reduce churn.

{% hint style="info" %}
This is a step by step developer guide with examples. Our technical docs for notifications can be [found here](https://docs.criticalmoments.io/notifications/intro-to-notifications).
{% endhint %}

## Benefits over other notification systems

Critical Moments Notifications have several major benefits over other notification systems:

* [**Smart Notifications**](https://criticalmoments.io/features/notifications)**:** Delivered when users are actively holding their unlocked device, increasing visibility and click-through rates.
* **No Push Servers Required**: less infrastructure to manage and more reliable delivery with local notifications.
* **No Per-Message Cost**: unlimited notifications included
* **Notifications Without Code**: after integrating, new notifications and targeting can be done completely in config.
* [**Over the air updates**](https://docs.criticalmoments.io/remote-control-service): change notification messaging, targeting and timing over the air.
* **Scheduling/Timezones**: deliver notifications at the perfect time, whether that's in the user's local time zone, specific times of the day, or certain days of the week.

## Step 1: Install Critical Moments

Follow our [quick start guide](https://docs.criticalmoments.io/quick-start) to integrate Critical Moments into your app. The initial integration takes about 15 minutes.

## Step 2: Request Notification Permissions

Your app needs to get the user’s permission to show notifications.

You’ll want to request permission somewhere that feels natural, such as during onboarding flow. It’s important to ask early enough in your app’s user experience that most users see it. One of the primary use cases of notifications is to prevent early churn/abandonment; notifications can’t help reduce churn if the user churns before the permission request.

Requesting permission requires just one line of code:

{% tabs %}
{% tab title="Swift Example" %}

```swift
CriticalMoments.shared().requestNotificationPermission()
```

{% endtab %}

{% tab title="Objective-C Example" %}

```objectivec
[CriticalMoments.shared
        requestNotificationPermissionWithCompletionHandler:nil];
```

{% endtab %}
{% endtabs %}

## Step 3: Log important events and properties

[Instrument event](https://docs.criticalmoments.io/events/recommended-events) and [set properties](https://docs.criticalmoments.io/conditional-targeting/custom-properties) in your app so your notifications can fire at the right moment, and target the right users.

The following events and properties are particularly helpful for targeting notifications:

* `completed_onboarding` event: Trigger when the user completes onboarding, used to reduce abandonment (see below).
* `user_signed_in` property: is the user signed in (for apps that require accounts)
* `has_paid_subscription` property: is the user a subscriber (for apps with subscriptions)

## Step 4: Add Notifications to Reduce Churn

After integration, notifications can be added entirely in your [app’s config file](https://docs.criticalmoments.io/config-file-structure), no additional code needed!

We suggest three notifications below that can be easily added to any app.

### Increase Activation Rate

Many users download an app, only to never launch it again. Timely reminders can help them remember to complete onboarding and discover what your app has to offer.

The [config](https://docs.criticalmoments.io/config-file-structure) below will remind users to complete onboarding, 15 minutes after they leave. It will be canceled when the `completed_onboarding` event is fired. It will only be sent between 10am and 8pm local time, and will only be sent once.

```json
"notifications": {
  "onboardingReminder": {
    "title": "Complete APP_NAME Setup",
    "body": "It only takes 3 minutes to start APP_VALUE.",
    "cancelationEvents": [
      "completed_onboarding"
    ],
    "deliveryTimeOfDayStart": "10:00",
    "deliveryTimeOfDayEnd": "20:00",
    "deliveryTime": {
      "eventName": "app_entered_background",
      "eventInstance": "latest-once",
      "eventOffsetSeconds": 900
    }
  }
}
```

### Reduce Short-Term Churn

Some users never complete onboarding. Remind users to complete onboarding tasks within the first week to boost activation rates and reduce average active user acquisition cost.

The [config](https://docs.criticalmoments.io/config-file-structure) below will remind users to complete onboarding between day 3 and day 7 after initial app use. It will use smart notifications to attempt delivery when the user is holding their device and their screen is on. It will be canceled when the `completed_onboarding` event is fired. It will only be sent between 10am and 8pm local time, and will only be sent once.

```json
"notifications": {
  "title": "Complete APP_NAME Setup",
  "body": "It only takes 3 minutes to start APP_VALUE.",
  "cancelationEvents": [
    "completed_onboarding"
  ],
  "deliveryTimeOfDayStart": "10:00",
  "deliveryTimeOfDayEnd": "20:00",
  "deliveryTime": {
    "eventName": "app_entered_background",
    "eventInstance": "latest-once",
    "eventOffsetSeconds": 259200
  },
  "idealDeliveryConditions": {
    "condition": "screen_brightness > 0.01 && device_orientation != 'face_up' && device_orientation != 'face_down'",
    "maxWaitTimeSeconds": 345600
  }
}
```

### Reduce Long-Term Churn

Some users might churn after using an app for a while. Setting up reminders after a few weeks or months of inactivity can keep bring them back and reduce long-term churn.&#x20;

The [config](https://docs.criticalmoments.io/config-file-structure) below will remind users who have not launched the app in 30 days to return. It will use smart notifications to attempt delivery when the user is holding their device and their screen is on, and fall back to a standard delivery time if that condition is not met in 4 days. It will only be sent between 10am and 8pm local time. If the user uses the app, this notification is pushed out again (eventInstance: "latest").

```json
"notifications": {
  "churnNotification": {
    "title": "APP_VALUE",
    "body": "APP_VALUE_2",
    "deliveryTimeOfDayStart": "10:00",
    "deliveryTimeOfDayEnd": "20:00",
    "deliveryTime": {
      "eventName": "app_entered_foreground",
      "eventInstance": "latest",
      "eventOffsetSeconds": 2592000
    },
    "idealDeliveryConditions": {
      "condition": "screen_brightness > 0.01 && device_orientation != 'face_up' && device_orientation != 'face_down'",
      "maxWaitTimeSeconds": 345600
    }
  }
}
```

Some apps add a second churn notification, a few weeks after the first one.

## Step 5: Add Custom Notification

Each app has their own unique needs and user experience. Our robust targeting options can deliver notifications to the right users at the right time.

The [example config](https://docs.criticalmoments.io/config-file-structure) below reminds users of a hypothetical workout app to train. It's sent 3 days after their last workout event (training\_session\_end). It uses smart notifications to attempt delivery when the user is holding their device and their screen is on. It delivers in the morning. It will recur after every workout (eventInstance: "latest").

```json
"notifications": {
  "churnNotification": {
    "title": "Time to Train!",
    "body": "It's been a few days since your last workout. Time to get back in shape!",
    "deliveryTimeOfDayStart": "7:00",
    "deliveryTimeOfDayEnd": "12:00",
    "deliveryTime": {
      "eventName": "training_session_end",
      "eventInstance": "latest",
      "eventOffsetSeconds": 259200
    },
    "idealDeliveryConditions": {
      "condition": "screen_brightness > 0.01 && device_orientation != 'face_up' && device_orientation != 'face_down'",
      "maxWaitTimeSeconds": 86400
    }
  }
}
```

## You're done! ✅

Everything should now work!

You’ll want to test that the notifications appears in your app at the expected times. It can be helpful to set the `eventOffsetSeconds` and `maxWaitTimeSeconds` to lower values (like 10 seconds) during testing. If notifications aren’t appearing, ensure the conditions you set are met.

{% hint style="warning" %}
By default notifications only appear when an app isn’t in the foreground. To test, you’ll want to trigger a notification with a delay via `eventOffsetSeconds`, then move the app to the background before that delay fires to see it work in testing.
{% endhint %}

## Optional Enhancement: Deeplinks

If you want your notifications to open a specific screen of your app instead of just launching it, implement [iOS deeplinks](https://developer.apple.com/documentation/xcode/defining-a-custom-url-scheme-for-your-app), or [universal links](https://developer.apple.com/ios/universal-links/) to those parts of your app.

You can use the `actionName` [property of notifications](https://docs.criticalmoments.io/notifications/notifications-spec) to trigger this screen when a notification is tapped.
