Getting started
Our SDK for iOS lets you collect user data from iOS mobile apps. It contains over 30 methods that make it easy to track screen views, goals, ecommerce orders and more. To get started, you need to set up your account in Piwik PRO, install our library and set up the tracker.
Set up Piwik PRO
Before you install our library for iOS, you need to set up Piwik PRO. Here's what you need to do:
- Log in to Piwik PRO.
- Go to Menu > Administration.
- Navigate to Sites & apps.
- Click Add a site or app.
- Type the app name and address and click Save.
- Set the time zone and currency.
- Note the site/app ID. The ID is under the app name. Example:
00000000-0000-0000-0000-000000000000
. - Note your account address. Example:
https://example.piwik.pro
.
Install the library (CocaPods)
To install the library on CocaPods, follow these steps:
- In your
Podfile
, use the following command:
pod 'PiwikPROSDK', '~> VERSION'
Note: ReplaceVERSION
with the latest release name. Example: 1.1.6. (Where to find it?) - Run
pod install
. ImportPiwikPROSDK
to each file you want to use it for. - Set up the SDK and add tracking methods (like screen views or custom events) to your application.
Install the library (Swift Package Manager)
Available from 1.1.4
To install the library on Swift Package Manager, follow these steps:
- Make sure you're using the Xcode version +12.
- If you are migrating a project from CocoaPods, run the command pod deintegrate to remove CocoaPods from your Xcode project. Then remove the remaining Piwik PRO SDK files.
- In Xcode, navigate to File > Add Packages. (Or go to your project’s settings, click Package Dependencies and click on the + button.)
- Enter the URL of our Piwik PRO SDK GitHub repository:
https://github.com/PiwikPRO/piwik-pro-sdk-framework-ios
- Choose the version of Piwik PRO SDK you would like to use. For new projects, we recommend using the latest version.
Note: Don't use versions below 1.1.4 because Swift Package Manager is only supported for version +1.1.4.
- Click Add Package. Then wait for Xcode to finish downloading the Swift Package into your project.
- In Project Navigator, choose your project.
- In the target list, select the target that builds the application and click Build Settings.
- Click Other Linker Flags. If the -ObjC flag is not in the list, click + and add it.
Note: If you don't add the-ObjC
flag, some parts of our API may not be visible and our SDK may behave incorrectly. For example, you may see error messages that are hard to understand (“+[NSString visitorID]: unrecognized selector sent to class 0x1ef0739a8”) or experience other issues.
Set up the tracker
To set up the Piwik PRO tracker, follow these steps:
-
Open the
AppDelegate.m
file and add the SDK import:
#import<PiwikPROSDK/PiwikPROSDK.h>
. -
In the application delegate, set up the tracker. Use your account address (Example:
https://example.piwik.pro/
) and the site/app ID (Where to find it?)- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Configure the tracker in your application delegate [PiwikTracker sharedInstanceWithSiteID:@"site-id" baseURL:[NSURL URLWithString:@"account-address"]]; return YES; }
Swift
Our SDK is written in Objective-C but can also be used with Swift. If you refer to any of our methods in Swift, they will automatically appear as Swift syntax.
Here's an example of the sendView method in both languages:
[[PiwikTracker sharedInstance]
sendView:@"Menu"
];
import PiwikPROSDK
PiwikTracker.sharedInstance()?
.sendView(view: "Menu")
Note: If you need to create a bridging header, see the tutorial from Apple called “Importing Objective-C into Swift”. It'll give you more information.
Updated 15 days ago