# AppsFlyer integration

<Aside type="caution" icon="setting" title="Developer assistance needed">
 You'll need help from your development team to set up the integration. Please share this guide with them.
</Aside>

## Integration overview 

[AppsFlyer](https://www.appsflyer.com/) is a mobile attribution and marketing analytics platform that helps you analyze user acquisition and engagement. It provides comprehensive data on user behavior within the app and allows you to track user acquisition sources. Using the information obtained from AppsFlyer, you can create effective marketing campaigns in Pushwoosh.

Once the integration is configured, AppsFlyer will send the following information to Pushwoosh:

* User’s in-app behavior as Events and their attributes;
* User acquisition sources as the _Acquisition Source_ Tag values.
### Use cases 

Using this data, you can build user segments and make precisely targeted and personalized campaigns in Pushwoosh. 
Below are two examples of leveraging AppsFlyer data to create effective customer journeys in Pushwoosh.

**1. Create highly targeted campaigns in Pushwoosh using events tracked by AppsFlyer.**

Let’s say you have a news app. You configured AppsFlyer to track the _SubscribedToNews_ event, which fires every time a user subscribes to a news channel. This event has the category attribute indicating the type of news the user subscribes to: _politics_, _business_, or _sports_.

Pushwoosh receives the information about this event with its attribute values. You can create three user segments based on three possible values:

<img src="/integrations-appsflyer-integration-1.webp" alt="User segments based on news category attributes"/>

Now you can create campaigns targeted at users who are interested in a particular type of news:

<img src="/integrations-appsflyer-integration-2.webp" alt="Targeted campaigns for users interested in specific news categories"/>

**2. Personalize messaging based on user behavior data from AppsFlyer.**

In this example, we will use an online shopping app. Let’s say AppsFlyer tracks the _AddToWishlist_ event that fires whenever a user adds an item to their wishlist. This event has the item attribute indicating the name of the item added to the wishlist.

AppsFlyer sends the _AddToWishlist_ event data to Pushwoosh, where you can personalize messages depending on users’ choices. For example, you can create a push preset offering a discount on an item a user has added to their wishlist. Instead of the item name, add a [Dynamic Content placeholder](/developer/guides/personalization/dynamic-content/#personalizing-messages-sent-via-api-with-dynamic-content) with the _item_ attribute:

<img src="/integrations-appsflyer-integration-3.webp" alt="Dynamic content placeholder in Pushwoosh push preset"/>

If a user adds an item to their wishlist, they will receive a push containing information about it. For example, those who select iPhone 14 Pro Max will see this message:

<img src="/integrations-appsflyer-integration-4.webp" alt="Push notification preview for iPhone 14 Pro Max item offer" width="375"/>

## Setting up the integration

<Aside type="note">
The integration process is identical for both Android and iOS platforms.
</Aside>

1. Integrate the Pushwoosh SDK into your app if you haven't already done so. For more detailed instructions, [read the guide](/developer/pushwoosh-sdk/pushwoosh-sdk-overview).

<Aside type="caution">
For correct operation, Pushwoosh iOS SDK version 6.5.7 or later and Pushwoosh Android SDK version 6.6.16 or later are required.
</Aside>

2. To ensure that the correct data is sent to AppsFlyer, integrate this code snippet into your code. Make sure that it is executed after both Pushwoosh SDK and AppsFlyer SDK are initialized.

<Tabs>
<TabItem label="Java">
```
String pwhwid = Pushwoosh.getInstance().getHwid();
String pwuserid = Pushwoosh.getInstance().getUserId();
Map<String, Object> customData = new HashMap<String, Object>();
customData.put("pushwoosh_hwid", pwhwid);
customData.put("pushwoosh_user_id", pwuserid);
AppsFlyerLib.getInstance().setAdditionalData(customData);
```
</TabItem>

<TabItem label="Objective-C">
```
NSString *pwhwid = [[Pushwoosh sharedInstance] getHWID];
NSString *pwuserid = [[Pushwoosh sharedInstance] getUserId];
NSDictionary *customData = [[NSDictionary alloc] initWithObjectsAndKeys:pwuserid, @"pushwoosh_user_id", pwhwid, @"pushwoosh_hwid", nil];
[[AppsFlyerLib shared] setAdditionalData:customData];
```
</TabItem>
</Tabs>

<Aside type="danger">
When using custom Pushwoosh UserID values to identify and target users, make sure to run the code after calling the **setUserId()** method in the Pushwoosh SDK with the custom value.

Track when the Pushwoosh UserID changes according to the logic in your mobile application and send the updated values to AppsFlyer promptly. This is important for the correct mapping of data sent with users in your Pushwoosh database.
</Aside>

3. Configure Pushwoosh integration in AppsFlyer. For this, in your [AppsFlyer account](https://hq1.appsflyer.com/auth/login), go to **Collaborate** > **Partner Marketplace**. In the Partners list, locate and choose Pushwoosh.

<img src="/integrations-appsflyer-integration-5.webp" alt="Locating Pushwoosh in AppsFlyer"/>

4. Click **Set up integration**. Then you will be directed to the integration setup page. There, enable the **Activate partner** toggle.

<img src="/integrations-appsflyer-integration-6.webp" alt="Enabling Activate partner toggle in AppsFlyer"/>

<Aside type="note">
For iOS apps, the Advanced Privacy Mode is enabled by default which allows controlling the availability of user-level attribution data via the AppsFlyer platform. Though AppsFlyer doesn’t send this type of data to Pushwoosh, keeping the Advanced Privacy toggle activated may interfere with data transmission.

To ensure that Pushwoosh receives all the data, we recommend disabling the Advanced Privacy Mode in **App Settings**. Doing so will not compromise the privacy of user data. Pushwoosh is dedicated to managing data securely and responsibly, employing industry-standard security protocols to protect confidentiality.
</Aside>

<img src="/integrations-appsflyer-integration-7.webp" alt="Disabling the Advanced Privacy Mode in AppsFlyer"/>

5. In the **General settings** section, enter your Pushwoosh credentials:

* **API Access Token**. To get the token, in your Pushwoosh account go to **Settings > API Access** and copy the code. You can learn more about the API Access Token [in this guide](/developer/api-reference/api-access-token).
* **Application Code** (XXXXX-XXXXX) that you can find below your application name in your Pushwoosh account.

<img src="/integrations-appsflyer-integration-8.webp" alt="Adding Pushwoosh credentials in AppsFlyer general settings"/>

6. In the **Default postback** section, select **All media sources, including organic**.

<img src="/integrations-appsflyer-integration-9.webp" alt="Configuring the Default postback section"/>

7. In the **In-app event settings** section, enter your Pushwoosh **Application Code** and **API Access Token**.

<img src="/integrations-appsflyer-integration-10.webp" alt="In-app event settings section with Application Code and API token"/>

8. Enable the **In-app event postback** toggle and configure the events and data to be included in the postbacks sent to Pushwoosh.

<img src="/integrations-appsflyer-integration-11.webp" alt="In-app event postback toggle configuration in AppsFlyer"/>

Choose one or more AppsFlyer events to send to Pushwoosh from the drop-down menu, and complete the necessary parameters.

| Parameter                       | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **the mapped to partner event** | Even though this field is mandatory, don't worry about what you type because it won't change how events are named. Pushwoosh will still get the events with the same names as they appear in AppsFlyer.                                                                                                                                                                                                                                                                                                                         |
| **for users from**               | In this field, select whether postbacks are sent exclusively for users attributed to this partner or for all media sources, including organic.                                                                                                                                                                                                                                                                                                                                                                                  |
| **including**                   | <p>Choose how event data is shared with Pushwoosh:</p><ul><li><strong>No values & no revenue:</strong> Only send the event itself without any parameters (values or revenue).</li><li><strong>Values & no revenue:</strong> Send all parameters except the revenue value.</li><li><strong>Values & revenue:</strong> Send all event parameters, including the revenue value (if it exists in the event).<br/>To receive events with additional attributes sent to Pushwoosh, select Values and Revenue.</li></ul> |

9. Once the integration is configured, click **Save**.

<Aside type="note">
Before launching your campaigns, make sure to test the integration. Errors often occur during setup, so a quick test helps prevent wasting resources on campaigns with missing or incorrect data.
</Aside>

## Email click tracking with AppsFlyer ESP 2.0

To use email click tracking and preserve Universal Links / App Links when sending emails through Pushwoosh, you can set up the [AppsFlyer ESP 2.0 email integration](/product/integrations/appsflyer-esp2-email-integration).