# Installing the Freshpaint iOS SDK

To install the Freshpaint iOS SDK, add the following to your app's Podfile:

```ruby
pod 'Freshpaint', '0.5.0'
```

Then run:

```bash
pod install --repo-update
```

To import the Freshpaint SDK use:

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

```swift
import FreshpaintSDK
```

{% endtab %}

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

```objectivec
#import <FreshpaintSDK/FPAnalytics.h>
```

{% endtab %}
{% endtabs %}

Then to initialize the SDK, add the following code to your application delegate's `didFinishLaunchingWithOptions`:

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

```swift
func application(
    _ application: UIApplication, 
    didFinishLaunchingWithOptions 
    launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    ...
    let config = FreshpaintConfiguration(writeKey: "<your environment id>");
    config.trackApplicationLifecycleEvents = true
    config.recordScreenViews = true
    Freshpaint.setup(with: config)
    ...
}
```

{% endtab %}

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

```objectivec
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    ...
    FPAnalyticsConfiguration *configuration = [FPAnalyticsConfiguration configurationWithWriteKey:@"<your environment id>"];
    configuration.trackApplicationLifecycleEvents = YES;
    configuration.recordScreenViews = YES;
    [FPAnalytics setupWithConfiguration:configuration];
    ...
}
```

{% endtab %}
{% endtabs %}

You can get your environment id by going to the [Freshpaint sources page](https://app.freshpaint.io/sources).

## Deep Link Tracking

Freshpaint can automatically track deep links when your app is opened from a custom URL scheme or Universal Link. When enabled, the SDK sends a `Deep Link Opened` event and includes the opened URL in the event properties.

First, enable deep link tracking when you configure the SDK:

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

```swift
let config = FreshpaintConfiguration(writeKey: "<your environment id>")
config.trackDeepLinks = true
Freshpaint.setup(with: config)
```

{% endtab %}

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

```objectivec
FPAnalyticsConfiguration *configuration = [FPAnalyticsConfiguration configurationWithWriteKey:@"<your environment id>"];
configuration.trackDeepLinks = YES;
[FPAnalytics setupWithConfiguration:configuration];
```

{% endtab %}
{% endtabs %}

Then forward deep link callbacks from your app to Freshpaint.

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

```swift
@main
struct MyApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
                .onOpenURL { url in
                    Freshpaint.shared().open(url, options: [:])
                }
                .onContinueUserActivity(NSUserActivityTypeBrowsingWeb) { activity in
                    Freshpaint.shared().continueUserActivity(activity)
                }
        }
    }
}
```

{% endtab %}

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

```objectivec
- (BOOL)application:(UIApplication *)app
            openURL:(NSURL *)url
            options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options
{
    [[FPAnalytics sharedAnalytics] openURL:url options:options];
    return YES;
}
- (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
 restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler
{
    [[FPAnalytics sharedAnalytics] continueUserActivity:userActivity];
    return YES;
}
```

{% endtab %}
{% endtabs %}

For Universal Links, Freshpaint records the `url`, the activity `title` when available, and any values from the activity's `userInfo`. For custom URL scheme links, Freshpaint records the `url` and any values passed in the `options` dictionary.

## User Consent

Freshpaint gives you control over when analytics data is collected and when advertising identifiers are included. If your app requires user consent before analytics collection, wait to initialize Freshpaint until after consent is granted, or disable tracking immediately after setup and enable it only after the user opts in.

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

```swift
@main
struct MyApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
                .onOpenURL { url in
                    Freshpaint.shared().open(url, options: [:])
                }
                .onContinueUserActivity(NSUserActivityTypeBrowsingWeb) { activity in
                    Freshpaint.shared().continueUserActivity(activity)
                }
        }
    }
}
```

{% endtab %}

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

```objectivec
- (BOOL)application:(UIApplication *)app
            openURL:(NSURL *)url
            options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options
{
    [[FPAnalytics sharedAnalytics] openURL:url options:options];
    return YES;
}
- (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
 restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler
{
    [[FPAnalytics sharedAnalytics] continueUserActivity:userActivity];
    return YES;
}
```

{% endtab %}
{% endtabs %}

Calling `disable()` stops Freshpaint from processing new analytics calls. Calling `enable()` allows tracking calls to be processed again.

#### Advertising Consent and ATT

The SDK also supports Apple's App Tracking Transparency (ATT) flow. Freshpaint does not request ATT permission automatically by default. If you want the SDK to request ATT automatically when the app becomes active, set `autoRequestATT` to `true`.

Freshpaint only includes the advertising identifier through its ATT-aware APIs when ATT is authorized. If you provide an `adSupportBlock`, make sure your app has the required user permission before returning an advertising identifier.

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

```swift
let config = FreshpaintConfiguration(writeKey: "<your environment id>")
config.autoRequestATT = true
config.adSupportBlock = {
    Freshpaint.advertisingIdentifier()
}
Freshpaint.setup(with: config)
```

{% endtab %}

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

```objectivec
FPAnalyticsConfiguration *configuration = [FPAnalyticsConfiguration configurationWithWriteKey:@"<your environment id>"];
configuration.autoRequestATT = YES;
configuration.adSupportBlock = ^{
    return [FPAnalytics advertisingIdentifier];
};
[FPAnalytics setupWithConfiguration:configuration];
```

{% endtab %}
{% endtabs %}

You can also request ATT permission yourself and enable Freshpaint only after your consent flow is complete.

## Verifying Your Instrumentation

To verify your Freshpaint installation, navigate to the Freshpaint [Live View](https://app.freshpaint.io/events/liveview). After opening your app, you should see an `Application Opened` event show up in Live View:

![](/files/-MQTFujhym67mQlXhxP9)

Note, the Freshpaint SDK batches events, so it can take a minute for the event to show up.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://documentation.freshpaint.io/readme/guides/ios-quickstart-guide/installing-the-freshpaint-ios-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
