Pular para o conteúdo principal

Requirements

  • iOS Target: 13+
  • Swift Version: 5.1
  • Minimum Xcode: XCode 11

Installation

To install our SDK in your Swift application, there are 2 options:
  1. Go to File > Add Packages…
  2. Enter the SDK repository URL https://github.com/nemu-brazil/nemu-swift-sdk.git
  3. Choose version From 1.0.0
Xcode will automatically import the library and allow the import: import NemuTrackingLib

Or via Package.swift (When using SPM in the manifest):

After including the SDK in the project, initialize the SDK in your main application file, passing the Nemu pixel ID and your Nemu SDK key as arguments. ⚠️ Note: For security measures, we recommend that your Nemu SDK key be stored as an environment variable. As a recommendation, we can use Info.plist to find it: build settings in XcodeInfo.plist. In your Info.plist, add:
In your code, add environment variables as in the example below:

Registering UID to the SDK session

For total security and integrity of your application user data, all UIDs registered by our SDK are encrypted before being stored on our servers.
During the application login process, add a call to the setUserId() method, passing the defined UID of the user who just completed the login process as an argument. Example:
It is important to ensure that users who were already logged in before the SDK installation or update are also correctly tracked. To do this, you can define the UID as soon as it is available in the application, normally right after loading the locally saved user.

Example: UIKit applications with AppDelegate

In AppDelegate, after recovering the user from the session (for example, via UserSessionManager), call the SDK’s setUserId method:

Retrieving UTMs when sending sale event to Nemu API

The getLastSessionHistory() method returns an object containing the UTMs from the user’s last session. Use this object when sending the sale information to the Nemu API.

Testing the SDK and ensuring everything is right – Swift SDK

To test the complete integration flow and ensure everything is working correctly with Nemu’s SDK in Swift, follow the steps below:

1. Initialize the SDK in Debug mode

To view detailed SDK logs, enable debug mode when initializing it. Simply pass the isDebugMode parameter as true during initialization:
⚠️ Make sure to call this method at the start of the application, for example in AppDelegate or in the SwiftUI @main struct. If your application is not yet configured to receive deep links, follow our guide to configure Universal Links on iOS. Use a link like this (with UTMs) to perform the test:
You can simulate the access in the device’s Safari or in a terminal with the command:

3. Check application logs

With the SDK correctly configured and debug mode enabled, you should see the following logs in the console when opening the app via deep link:

Log explanation:

  1. Connection to Nemu: The SDK was successfully initialized and validated the token and pixel ID.
  2. UTM Extraction: The SDK correctly read and stored the deep link parameters.
  3. UID Registered: The app passed the user’s unique identifier using setUserId.

4. Check the recovery of UTMs with getLastSessionHistory()

As a final step, call the getLastSessionHistory() method and validate if the UTM data is being correctly retrieved.
In debug mode, the SDK also automatically prints:
Note: The value "||nemu_xiI85afzrP" at the end of utm_content is Nemu’s internal session identifier. It must be sent exactly like this when registering sales in the Nemu API.