3rd Party Integrations
Product Journal Integrations

Swift

Instructions for adding Appfit to an application written in Swift

Add AppFit to Your Swift Application

Set Up an AppFit Account

If you haven’t already, create an account on AppFit.

During setup, select the appropriate Industry, Platform, and Focus for your company. AppFit will suggest metrics to track based on these selections.

Obtain Your API Key

Navigate to the "Integrations" section on the AppFit dashboard.

Retrieve your API Key from an integration like Amplitude or Segment by copying it from there.

Use Swift Package Manager to install RepresentableKit.

Use Xcode and add this repository as a dependency. Alternatively, add this repository as a dependency to your Package.swift.

dependencies: [
    .package(url: "https://github.com/uptech/appfit-swift-sdk.git", .upToNextMajor(from: "1.0.0"))
]

The AppFit SDK is Open Source. Find it on GitHub here

Configure the AppFit SDK

To configure the AppFit SDK, simply construct an AppFitConfiguration class and insert your API Key you obtained from AppFit.

let configuration = AppFitConfiguration(apiKey: "API_KEY")
let appFit = AppFit(configuration: configuration)

Once you have the client constructed, tracking an event is as simple as calling trackEvent

import AppFit

// Create the AppFitConfiguration
let configuration = AppFitConfiguration(apiKey: "API_KEY")

// Create the AppFit Client
let appFit = AppFit(configuration: configuration)

// Use the client to track events
appFit.trackEvent(name: "event_name", properties: {"key": "value"})

Identifying Users

The AppFit SDK includes an identify call, that you can use to identify users in your analytic events. This method supports any String-based identifier.

appfit.identifyUser("<id>")

Setting this to null, will remove all events going forward from including the userId.

Cached Events

We cache all events locally in the SDK. This allows us to rety failed events. If a device is experiencing network issues, we will retry the saved events later to help avoid losing any metrics.

Save Changes and Publish

After inserting the code, save the changes to your app and run it to verify that data is flowing into AppFit.

Verify the Integration

Monitor your AppFit dashboard to confirm that events from your application are being tracked and metrics are updating.