> ## Documentation Index
> Fetch the complete documentation index at: https://docs.permutive.com/llms.txt
> Use this file to discover all available pages before exploring further.

# iOS SDK

> Integrate Permutive into your iOS and tvOS applications for user segmentation, personalization, and ad targeting

export const SDKKeyConcepts = () => <AccordionGroup>
    <Accordion title="Cohorts vs. Activations">
      - **Cohorts**: All segments a user belongs to
      - **Activations**: Cohorts configured for specific ad platforms
    </Accordion>

    <Accordion title="Behavioral vs. Contextual">
      - **Behavioral**: Based on user history (e.g., "sports enthusiast")
      - **Contextual**: Based on current content (e.g., viewing sports article right now)
    </Accordion>

    <Accordion title="Identity Resolution">
      Multiple identifiers (email, user ID, ad ID) linked to single user profile for cross-device tracking.
    </Accordion>
  </AccordionGroup>;

<CardGroup cols={4}>
  <Card title="Quick Start" href="/sdks/mobile/ios/getting-started/quick-start" icon="rocket" />

  <Card title="Features" href="#features" icon="puzzle-piece" />

  <Card title="Integrations" href="#integrations" icon="plug" />

  <Card title="Issues" href="/sdks/mobile/ios/troubleshooting/common-errors" icon="triangle-exclamation" />
</CardGroup>

## Overview

The Permutive iOS SDK enables user segmentation, personalization, and ad targeting in your iOS and tvOS applications. Track user behavior, manage identities across devices, and deliver targeted advertising through integrations with major ad platforms.

**Current Version:** 2.2.0

<Info>
  **Platform Support:** The SDK supports iOS 12.0+ and tvOS 12.0+. Both platforms share the same API with minor differences noted in the documentation.
</Info>

## Getting Started

New to the Permutive iOS SDK? Start here.

<CardGroup cols={2}>
  <Card title="Quick Start Guide" icon="rocket" href="/sdks/mobile/ios/getting-started/quick-start">
    Get up and running with your first page view in minutes
  </Card>

  <Card title="Installation" icon="download" href="/sdks/mobile/ios/getting-started/installation">
    CocoaPods and Swift Package Manager setup
  </Card>

  <Card title="Initialization" icon="gear" href="/sdks/mobile/ios/getting-started/initialization">
    SDK initialization patterns and configuration
  </Card>

  <Card title="Verification" icon="circle-check" href="/sdks/mobile/ios/getting-started/verification">
    Verify your integration is working correctly
  </Card>
</CardGroup>

## Core Concepts

Understand the fundamental concepts of the Permutive SDK.

<CardGroup cols={2}>
  <Card title="Identity Management" icon="user" href="/sdks/mobile/ios/core-concepts/identity-management">
    Track users across devices and sessions
  </Card>

  <Card title="Event Properties" icon="list" href="/sdks/mobile/ios/core-concepts/event-properties">
    Structure and validate event data
  </Card>

  <Card title="Cohorts and Activations" icon="users" href="/sdks/mobile/ios/core-concepts/cohorts-and-activations">
    Understanding user segmentation
  </Card>

  <Card title="Contextual Data" icon="bullseye" href="/sdks/mobile/ios/core-concepts/contextual-data">
    Content-based real-time targeting
  </Card>
</CardGroup>

## Features

Detailed guides for specific SDK features.

<CardGroup cols={2}>
  <Card title="Page Tracking" icon="file" href="/sdks/mobile/ios/features/page-tracking">
    Track pageviews and user engagement (recommended approach)
  </Card>

  <Card title="Event Tracking" icon="bolt" href="/sdks/mobile/ios/features/event-tracking">
    Track custom events
  </Card>

  <Card title="Video Tracking" icon="video" href="/sdks/mobile/ios/features/video-tracking">
    Track video content viewing
  </Card>

  <Card title="Video Ad Tracking" icon="rectangle-ad" href="/sdks/mobile/ios/features/video-ad-tracking">
    Track video advertisement engagement
  </Card>

  <Card title="Triggers Provider" icon="bell" href="/sdks/mobile/ios/features/triggers-provider">
    React to cohort changes in real-time
  </Card>
</CardGroup>

## Integrations

Connect Permutive with ad platforms and other services.

<CardGroup cols={2}>
  <Card title="View All Integrations" icon="plug" href="/sdks/mobile/ios/integrations/overview">
    Google Ad Manager, Xandr, and more
  </Card>

  <Card title="IDFA Provider" icon="fingerprint" href="/sdks/mobile/ios/integrations/idfa-provider">
    Apple advertising identifier tracking
  </Card>
</CardGroup>

## Common Tasks

<AccordionGroup>
  <Accordion title="Track a Page View (Recommended)" icon="file">
    **PageTracker is the recommended approach** for tracking user interactions as it integrates with Permutive's standard events and provides richer insights.

    <CodeGroup>
      ```swift Swift theme={"dark"}
      import UIKit
      import Permutive_iOS

      class ArticleViewController: UIViewController {
          private var pageTracker: PageTrackerProtocol?

          override func viewDidLoad() {
              super.viewDidLoad()

              let properties = try? EventProperties([
                  "category": "sports",
                  "author": "John Doe"
              ])

              let context = Context(
                  title: "Article Title",
                  url: URL(string: "https://example.com/article"),
                  referrer: nil
              )

              pageTracker = try? Permutive.shared.createPageTracker(
                  properties: properties,
                  context: context
              )
          }

          override func viewDidAppear(_ animated: Bool) {
              super.viewDidAppear(animated)
              try? pageTracker?.resume()
          }

          override func viewDidDisappear(_ animated: Bool) {
              super.viewDidDisappear(animated)
              pageTracker?.pause()
          }

          deinit {
              pageTracker?.stop()
          }
      }
      ```

      ```objectivec Objective-C theme={"dark"}
      #import "ArticleViewController.h"
      @import Permutive_iOS;

      @interface ArticleViewController ()
      @property (nonatomic, strong) NSObject<PermutivePageTrackerProtocol> *pageTracker;
      @end

      @implementation ArticleViewController

      - (void)viewDidLoad {
          [super viewDidLoad];

          NSError *error = nil;
          PermutiveEventProperties *properties = [[PermutiveEventProperties alloc]
              init:@{@"category": @"sports", @"author": @"John Doe"}
              error:&error];

          PermutiveContext *context = [[PermutiveContext alloc]
              initWithTitle:@"Article Title"
              url:[NSURL URLWithString:@"https://example.com/article"]
              referrer:nil];

          self.pageTracker = [Permutive.shared
              createPageTrackerWithProperties:properties
              context:context
              error:&error];
      }

      - (void)viewDidAppear:(BOOL)animated {
          [super viewDidAppear:animated];
          [self.pageTracker resumeAndReturnError:nil];
      }

      - (void)viewDidDisappear:(BOOL)animated {
          [super viewDidDisappear:animated];
          [self.pageTracker pause];
      }

      - (void)dealloc {
          [self.pageTracker stop];
      }

      @end
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Set User Identity" icon="user">
    <CodeGroup>
      ```swift Swift theme={"dark"}
      let aliases = [
          Alias(tag: "email_sha256", identity: emailHash),
          Alias(tag: "internal_id", identity: userId, priority: 1)
      ]
      try? Permutive.shared.setIdentities(aliases: aliases)
      ```

      ```objectivec Objective-C theme={"dark"}
      PermutiveAlias *emailAlias = [[PermutiveAlias alloc]
          initWithTag:@"email_sha256" identity:emailHash];
      PermutiveAlias *idAlias = [[PermutiveAlias alloc]
          initWithTag:@"internal_id" identity:userId priority:1];

      [Permutive.shared setIdentitiesWithAliases:@[emailAlias, idAlias] error:nil];
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="React to Cohort Changes" icon="bell">
    <CodeGroup>
      ```swift Swift theme={"dark"}
      var trigger: TriggerAction?

      func watchCohort() {
          trigger = Permutive.shared.triggerProvider?.action(
              boolFor: ["premium_user"],
              action: { query, isInCohort in
                  if isInCohort {
                      self.showPremiumFeatures()
                  }
              }
          )
      }

      // Release trigger when done
      deinit {
          trigger = nil
      }
      ```

      ```objectivec Objective-C theme={"dark"}
      // Hold strong reference
      @property (nonatomic, strong) PermutiveTriggerAction *trigger;

      - (void)watchCohort {
          NSSet *cohorts = [NSSet setWithObject:@"premium_user"];
          self.trigger = [Permutive.shared.triggerProvider
              actionWithBoolFor:cohorts
              action:^(NSString *cohort, BOOL result) {
                  if (result) {
                      [self showPremiumFeatures];
                  }
              }];
      }
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Target Google Ads" icon="bullseye">
    <CodeGroup>
      ```swift Swift theme={"dark"}
      let adRequest = GAMRequest()
      adRequest.customTargeting = Permutive.shared.googleCustomTargeting(
          adTargetable: pageTracker
      )
      bannerView.load(adRequest)
      ```

      ```objectivec Objective-C theme={"dark"}
      GAMRequest *adRequest = [GAMRequest request];
      adRequest.customTargeting = [Permutive.shared
          googleCustomTargetingWithAdTargetable:self.pageTracker];
      [self.bannerView loadRequest:adRequest];
      ```
    </CodeGroup>
  </Accordion>
</AccordionGroup>

## Requirements

| Requirement | Version |
| ----------- | ------- |
| iOS         | 12.0+   |
| tvOS        | 12.0+   |
| Xcode       | 13.0+   |
| Swift       | 5.0+    |

<Tabs>
  <Tab title="Swift Package Manager">
    Add the package URL in Xcode:

    ```
    https://github.com/permutive-engineering/permutive-ios-spm
    ```

    Select `Permutive_iOS` as the package product.
  </Tab>

  <Tab title="CocoaPods">
    ```ruby theme={"dark"}
    target 'YourApp' do
      platform :ios, '12.0'
      pod 'Permutive_iOS', '~> 2.2.0'
    end
    ```
  </Tab>
</Tabs>

## Key Concepts

<SDKKeyConcepts />

## Additional Resources

<Tabs>
  <Tab title="Reference">
    API documentation and technical reference.

    * **[API Reference](https://storage.googleapis.com/permutive-ios-refdocs/html/index.html)** - Complete API documentation
    * **[Apple Privacy Information](/sdks/mobile/ios/integrations/idfa-provider#apple-privacy)** - App Store privacy requirements
  </Tab>

  <Tab title="Platform Notes">
    <Info>
      **tvOS Differences:** The tvOS SDK shares the same API as iOS, with the following exceptions:

      * IDFA/App Tracking Transparency is not available on tvOS
      * UI patterns use focus-based navigation instead of touch
    </Info>
  </Tab>
</Tabs>

## FAQ

<AccordionGroup>
  <Accordion title="What's the difference between PageTracker and direct event tracking?">
    **PageTracker** is the recommended approach for most use cases. It automatically tracks Pageview events, measures engagement time, and enables contextual cohorts when URLs are provided.

    **Direct event tracking** via `track(event:properties:)` is for specialized cases where you need to track custom events that don't fit the page model.
  </Accordion>

  <Accordion title="How do I enable debug logging?">
    Enable logging in your initialization options:

    ```swift theme={"dark"}
    let options = Options(
        apiKey: "<your api key>",
        organisationId: "<your org id>"
    )
    options.logModes = LogMode.all
    ```

    Messages will appear in the Xcode console.
  </Accordion>

  <Accordion title="What identifiers should I use for identity management?">
    Use hashed emails (SHA-256), internal user IDs, or the vendor identifier (`identifierForVendor`). Never send plain text PII. See the [Identity Management](/sdks/mobile/ios/core-concepts/identity-management) guide for details.
  </Accordion>

  <Accordion title="Should I use IDFA?">
    Permutive recommends against using IDFA due to Apple's App Tracking Transparency requirements. Consider using `identifierForVendor` or hashed email addresses instead. See the [IDFA Provider](/sdks/mobile/ios/integrations/idfa-provider) guide if you do need IDFA.
  </Accordion>
</AccordionGroup>

## Getting Help

* **[Troubleshooting Guide](/sdks/mobile/ios/troubleshooting/common-errors)** - Solutions to common issues
* **Customer Success Manager (CSM)** - For enabling features and exploring use cases
* **[Technical Services](mailto:technical-services@permutive.com)** - For technical setup and configuration
* **[Support](mailto:support@permutive.com)** - For troubleshooting and help

## Privacy & Compliance

Permutive is designed with privacy in mind: GDPR compliant, CCPA compliant, no PII storage, user consent respected, and transparent data usage.
