Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK-5238 Delayed init android docs #8397

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
---
nav_title: Delayed Initialization
article_title: Delayed Initialization for Android and FireOS
platform:
- Android
- FireOS
page_order: 10
description: "This article covers how to implement delayed initialization on the Android SDK and optionally preserve push notification analytics when delayed initialization is enabled."

---

# Delayed initialization for the Braze Android SDK

> Learn how to enable delayed initialization and opt in to preserve push notification analytics when it is enabled. This can be useful when you need to set up other services before initializing the SDK, such as fetching configuration data from a server or waiting for user consent.

While delayed initialization is enabled, all network connections will be canceled, and the Braze SDK will not pass any data to Braze servers.

{% alert important %}
Delayed initialization is available starting in Android SDK version xxxx.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just going to comment here to make sure we don't forget to add the Android version once we have it.

{% endalert %}

## Enabling Delayed Initialization
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are your thoughts on adding numbers to the subtitles? For example, Step 1: Enabling Delayed Initialization or 1. Enabling Delayed Initialization

I think this would help the reader understand that the steps flow together. This is also helpful for parity, because the Swift Docs uses numbered Steps)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not really steps where they all need to be done. Each section is a different part of the feature. If there's numbers, I think users will think they need to do all the steps.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right that's true! Since there are cases where a user may never init afterwards, etc. I agree with having no numbers then

Copy link
Contributor

@internetisaiah internetisaiah Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up: are certain steps required before completing other steps? i.e., maybe doing something like this:

# Title

Description

## Enabling delayed initialization

...

## Optional configurations

### Push analytics

...

### Initialization after delay

...

(or something similar?)


Delayed initialization is disabled by default. In order to delay initialization, update your `braze.xml` file to include `com_braze_enable_delayed_initialization` and confirm its value is set to `true`:

```xml
<bool name="com_braze_enable_delayed_initialization">true</bool>
```

This can additionally be done at runtime via:
internetisaiah marked this conversation as resolved.
Show resolved Hide resolved

{% tabs %}
{% tab JAVA %}

```java
Braze.enableDelayedInitialization(context);
```

{% endtab %}
{% tab KOTLIN %}

```kotlin
Braze.enableDelayedInitialization(context)
```

{% endtab %}
{% endtabs %}

## Setting Delayed Initialization Push Analytics Behavior
internetisaiah marked this conversation as resolved.
Show resolved Hide resolved

When delayed initialization is enabled, you have the option to queue or drop push analytics. If push analytics are queued, these events will be logged once delayed initialization is disabled.

By default, push analytics are queued when delayed initialization is enabled. In order to drop push analytics, update your `braze.xml` file to include `com_braze_delayed_initialization_analytics_behavior` as follows:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me, this line:

By default, push analytics are queued when delayed initialization is enabled.

seems to conflict with the line above it:

If push analytics are queued, these events will be logged once delayed initialization is disabled. 

could i get some clarity here when you get the chance @chshapiro ? thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*Note: this has been removed it in the current commit. Please be sure to double-check my changes to ensure I'm still representing the original idea properly 👍🏽


```xml
<string name="com_braze_delayed_initialization_analytics_behavior">DROP</string>
```

To explicitly queue push analytics, update your `braze.xml` file to include `com_braze_delayed_initialization_analytics_behavior` as follows:

```xml
<string name="com_braze_delayed_initialization_analytics_behavior">QUEUE</string>
```

Additionaly, the push analytics behavior can be set during runtime in the [`Braze.enableDelayedInitialization()`](set link after release) method by using one of the following code snippets:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commenting to remember to add link after release


{% tabs %}
{% tab JAVA %}

```java
// Drop all push analytics
Braze.enableDelayedInitialization(context, DelayedInitializationAnalyticsBehavior.DROP);

// Queue push analytics
Braze.enableDelayedInitialization(context, DelayedInitializationAnalyticsBehavior.QUEUE);
```

{% endtab %}
{% tab KOTLIN %}

```kotlin
// Drop all push analytics
Braze.enableDelayedInitialization(context, DelayedInitializationAnalyticsBehavior.DROP)

// Queue push analytics
Braze.enableDelayedInitialization(context, DelayedInitializationAnalyticsBehavior.QUEUE)
```

{% endtab %}
{% endtabs %}

## Initializing After Delay

To initialize the SDK once the delay period is over, use the [`Braze.disableDelayedInitialization()`](set link after release) method:

{% tabs %}
internetisaiah marked this conversation as resolved.
Show resolved Hide resolved
{% tab JAVA %}

```java
Braze.disableDelayedInitialization(context);
```

{% endtab %}
{% tab KOTLIN %}

```kotlin
Braze.disableDelayedInitialization(context)
```

{% endtab %}
{% endtabs %}
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,7 @@ Braze will now be able to collect [specified data from your application]({{site.

Visit the following articles in order to enable [custom event tracking]({{site.baseurl}}/developer_guide/platform_integration_guides/android/analytics/tracking_custom_events/), [push messaging]({{site.baseurl}}/developer_guide/platform_integration_guides/android/push_notifications/android/integration/standard_integration/), [Content Cards]({{site.baseurl}}/developer_guide/platform_integration_guides/android/content_cards/integration/) and the complete suite of Braze features.

{% alert warning %}
If your application requires additional setup before initializing the SDK, such as fetching configuration data from a server or waiting for user consent, please refer to the [Delayed Initialization]({{site.baseurl}}/developer_guide/platform_integration_guides/android/advanced_use_cases/delayed_initialization/) documentation page.
internetisaiah marked this conversation as resolved.
Show resolved Hide resolved
{% endalert %}