diff --git a/MIGRATION_GUIDE.md b/MIGRATION_GUIDE.md
index c43cca836..7482f6dad 100644
--- a/MIGRATION_GUIDE.md
+++ b/MIGRATION_GUIDE.md
@@ -2,6 +2,17 @@
This document provides guidance on how to migrate from the old version of the SDK to a newer version.
It will be updated as new versions are released including deprecations or breaking changes.
+## 2.1.0 Deprecations
+#### Deprecated `Klaviyo.lifecycleCallbacks`
+In an effort to reduce setup code required to integrate the Klaviyo Android SDK, we have deprecated the public property
+`Klaviyo.lifecycleCallbacks` and will now register for lifecycle callbacks automatically upon `initialize`.
+It is no longer required to have this line in your `Application.onCreate()` method:
+```kotlin
+registerActivityLifecycleCallbacks(Klaviyo.lifecycleCallbacks)
+```
+For version 2.1.x, `Klaviyo.lifecycleCallbacks` has been replaced with a no-op implementation to avoid duplicative
+listeners, and will be removed altogether in the next major release.
+
## 2.0.0 Breaking Changes
#### Removed `EventType` in favor of `EventMetric`.
The reasoning is explained below, see [1.4.0 Deprecations](#140-deprecations) for details and code samples.
diff --git a/README.md b/README.md
index 543374ac8..58205ac78 100644
--- a/README.md
+++ b/README.md
@@ -73,9 +73,12 @@ send them timely push notifications via [FCM (Firebase Cloud Messaging)](https:/
The SDK must be initialized with the short alphanumeric
[public API key](https://help.klaviyo.com/hc/en-us/articles/115005062267#difference-between-public-and-private-api-keys1)
for your Klaviyo account, also known as your Site ID. We require access to the `applicationContext` so the
-SDK can be responsive to changes in network conditions and persist data via
-`SharedPreferences`. You must also register the Klaviyo SDK for activity lifecycle
-callbacks per the example code, so we can gracefully manage background processes.
+SDK can be responsive to changes in application state and network conditions, and access `SharedPreferences` to
+persist data. Upon initialize, the SDK registers listeners for your application's activity lifecycle callbacks,
+to gracefully manage background processes.
+
+`Klaviyo.initialize()` **must** be called before any other SDK methods can be invoked. We recommend initializing from
+the earliest point in your application code, such as the `Application.onCreate()` method.
```kotlin
// Application subclass
@@ -90,18 +93,10 @@ class YourApplication : Application() {
// Initialize is required before invoking any other Klaviyo SDK functionality
Klaviyo.initialize("KLAVIYO_PUBLIC_API_KEY", applicationContext)
-
- // Required for the SDK to properly respond to lifecycle changes such as app backgrounding
- registerActivityLifecycleCallbacks(Klaviyo.lifecycleCallbacks)
}
}
```
-`Klaviyo.initialize()` **must** be called before any other SDK methods can be invoked.
-Because we require lifecycle callbacks, it is necessary to subclass
-[`Application`](https://developer.android.com/reference/android/app/Application)
-to initialize and register callbacks in `Application.onCreate`.
-
## Profile Identification
The SDK provides methods to identify profiles via the
[Create Client Profile API](https://developers.klaviyo.com/en/reference/create_client_profile).
@@ -449,6 +444,31 @@ extensions such as `import com.klaviyo.pushFcm.KlaviyoRemoteMessage.body` to acc
We also provide an `Intent.appendKlaviyoExtras(RemoteMessage)` extension method, which attaches the data to your
notification intent that the Klaviyo SDK requires in order to track opens when you call `Klaviyo.handlePush(intent)`.
+## Troubleshooting
+The SDK contains logging at different levels from `verbose` to `assert`. By default, the SDK logs at the `error` level
+in a production environment and at the `warning` level in a debug environment. You can change the log level by adding
+the following metadata tag to your manifest file.
+* `0` = disable logging entirely
+* `1` = `Verbose` and above
+* `2` = `Debug` and above
+* `3` = `Info` and above
+* `4` = `Warning` and above
+* `5` = `Error` and above
+* `6` = `Assert` only
+
+```xml
+
+
The SDK must be initialized with the short alphanumeric public API key for your Klaviyo account, also known as your Site ID. We require access to the applicationContext
so the SDK can be responsive to changes in network conditions and persist data via SharedPreferences
. You must also register the Klaviyo SDK for activity lifecycle callbacks per the example code, so we can gracefully manage background processes.
The SDK must be initialized with the short alphanumeric public API key for your Klaviyo account, also known as your Site ID. We require access to the applicationContext
so the SDK can be responsive to changes in application state and network conditions, and access SharedPreferences
to persist data. Upon initialize, the SDK registers listeners for your application's activity lifecycle callbacks, to gracefully manage background processes.
Klaviyo.initialize()
must be called before any other SDK methods can be invoked. We recommend initializing from the earliest point in your application code, such as the Application.onCreate()
method.
// Application subclass
import android.app.Application
import com.klaviyo.analytics.Klaviyo
class YourApplication : Application() {
override fun onCreate() {
super.onCreate()
/* ... */
// Initialize is required before invoking any other Klaviyo SDK functionality
Klaviyo.initialize("KLAVIYO_PUBLIC_API_KEY", applicationContext)
// Required for the SDK to properly respond to lifecycle changes such as app backgrounding
registerActivityLifecycleCallbacks(Klaviyo.lifecycleCallbacks)
}
}
+ // Application subclass
import android.app.Application
import com.klaviyo.analytics.Klaviyo
class YourApplication : Application() {
override fun onCreate() {
super.onCreate()
/* ... */
// Initialize is required before invoking any other Klaviyo SDK functionality
Klaviyo.initialize("KLAVIYO_PUBLIC_API_KEY", applicationContext)
}
}
Klaviyo.initialize()
must be called before any other SDK methods can be invoked. Because we require lifecycle callbacks, it is necessary to subclass Application
to initialize and register callbacks in Application.onCreate
.
The SDK provides methods to identify profiles via the Create Client Profile API. A profile can be identified by any combination of the following:
Note: Klaviyo uses data messages to provide consistent notification formatting. As a result, all Klaviyo notifications are handled via onMessageReceived
regardless of the app being in the background or foreground. If you are working with multiple remote sources, you can check whether a message originated from Klaviyo with the extension method RemoteMessage.isKlaviyoNotification
.
If you wish to fully customize the display of notifications, we provide a set of RemoteMessage
extensions such as import com.klaviyo.pushFcm.KlaviyoRemoteMessage.body
to access all the properties sent from Klaviyo. We also provide an Intent.appendKlaviyoExtras(RemoteMessage)
extension method, which attaches the data to your notification intent that the Klaviyo SDK requires in order to track opens when you call Klaviyo.handlePush(intent)
.
The SDK contains logging at different levels from verbose
to assert
. By default, the SDK logs at the error
level in a production environment and at the warning
level in a debug environment. You can change the log level by adding the following metadata tag to your manifest file.
0
= disable logging entirely
1
= Verbose
and above
2
= Debug
and above
3
= Info
and above
4
= Warning
and above
5
= Error
and above
6
= Assert
only
<!-- AndroidManifest.xml -->
<manifest>
<!-- ... -->
<application>
<!-- Enable SDK debug logging -->
<meta-data
android:name="com.klaviyo.core.log_level"
android:value="2" />
</application>
</manifest>
+
+ See the .github/CONTRIBUTING.md to learn how to contribute to the Klaviyo Android SDK. We welcome your feedback in the discussion and issues sections of our public GitHub repository.
Convert this data model into a simple map
Convert this data model into a simple map
Adds a custom property to the map. Custom attributes can define any key name that isn't already reserved by Klaviyo
Add a custom property to the map. Custom attributes can define any key name that isn't already reserved by Klaviyo
Adds a custom property to the map. Custom attributes can define any key name that isn't already reserved by Klaviyo
Add a custom property to the map. Custom attributes can define any key name that isn't already reserved by Klaviyo
Adds a custom property to the map. Custom attributes can define any key name that isn't already reserved by Klaviyo
Add a custom property to the map. Custom attributes can define any key name that isn't already reserved by Klaviyo
Adds a custom property to the map. Custom attributes can define any key name that isn't already reserved by Klaviyo
Add a custom property to the map. Custom attributes can define any key name that isn't already reserved by Klaviyo
Adds a custom property to the map. Custom attributes can define any key name that isn't already reserved by Klaviyo
Add a custom property to the map. Custom attributes can define any key name that isn't already reserved by Klaviyo
Adds a custom property to the map. Custom attributes can define any key name that isn't already reserved by Klaviyo
Add a custom property to the map. Custom attributes can define any key name that isn't already reserved by Klaviyo
Adds a custom property to the map. Custom attributes can define any key name that isn't already reserved by Klaviyo
Add a custom property to the map. Custom attributes can define any key name that isn't already reserved by Klaviyo
Adds a custom property to the map. Custom attributes can define any key name that isn't already reserved by Klaviyo
Add a custom property to the map. Custom attributes can define any key name that isn't already reserved by Klaviyo
Adds a custom property to the map. Custom attributes can define any key name that isn't already reserved by Klaviyo
Add a custom property to the map. Custom attributes can define any key name that isn't already reserved by Klaviyo
Adds a custom property to the map. Custom attributes can define any key name that isn't already reserved by Klaviyo
Add a custom property to the map. Custom attributes can define any key name that isn't already reserved by Klaviyo
Controls the data that can be input into a map of event attributes recognised by Klaviyo
Controls the data that can be input into a map of event attributes recognised by Klaviyo
Controls the data that can be input into a map of profile attributes recognised by Klaviyo
Controls the data that can be input into a map of profile attributes recognised by Klaviyo
Klaviyo lifecycle monitor which must be attached by the parent application so that the SDK can respond to environment changes such as internet availability and application termination
Configure Klaviyo SDK with your account's public API Key and application context. This must be called to before using any other SDK functionality
Configure Klaviyo SDK with your account's public API Key and application context. This must be called to before using any other SDK functionality
Clears all stored profile identifiers (e.g. email or phone) and starts a new tracked profile
Clears all stored profile identifiers (e.g. email or phone) and starts a new tracked profile
Configure Klaviyo SDK with your account's public API Key and application context. This must be called to before using any other SDK functionality
Your Klaviyo account's public API Key
Configure Klaviyo SDK with your account's public API Key and application context. This must be called to before using any other SDK functionality
Your Klaviyo account's public API Key
Returns a representation of an immutable list of all enum entries, in the order they're declared.
This method may be used to iterate over the enum entries.
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
if this enum type has no constant with the specified name
Returns a representation of an immutable list of all enum entries, in the order they're declared.
This method may be used to iterate over the enum entries.
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
if this enum type has no constant with the specified name
Extension method since there is no support for this in yet in PackageManagerCompat
NOTE: There is no other option than the deprecated method below Tiramisu
Extension method to get an integer value from the manifest metadata
Exception that is thrown when the application context is missing from the config
Extension method since there is no support for this in yet in PackageManagerCompat
Extension method to get an integer value from the manifest metadata
A no-op implementation of ActivityLifecycleCallbacks to temporarily replace the public property Klaviyo.lifecycleCallbacks and prevent duplicate registration of the KlaviyoLifecycleMonitor until next major release when we can make the breaking change to remove that public property
A no-op implementation of ActivityLifecycleCallbacks to temporarily replace the public property Klaviyo.lifecycleCallbacks and prevent duplicate registration of the KlaviyoLifecycleMonitor until next major release when we can make the breaking change to remove that public property
Exceptions that automatically hook into our logger
Exceptions that automatically hook into our logger
Remove registered service by type, specified by generic parameter
Remove registered service by type, specified by generic parameter
Type, usually an interface, to register under