The PiwikTracker is an iOS SDK for sending app analytics to a Piwik server.
This is not the final and stable version but a prerelease of the Swift rewrite. Please check this list to see what is left and can be improved.
Use the following in your Podfile.
pod 'PiwikTracker', '~> 4.0.0-beta'
Then run pod install. In every file you want to use the PiwikTracker, don't forget to import the framwork with import PiwikTracker.
Befor the first usage, the PiwikTracker has to be configured. This is best to be done in the application(_:, didFinishLaunchingWithOptions:) method in the AppDelegate.
PiwikTracker.configureSharedInstance(withSiteID: "5", baseURL: URL(string: "http://your.server.org/path-to-piwik/piwik.php")!)
The siteId is the id that you can get if you add a website within the Piwik web interface. The baseURL it the URL to your Piwik web instance and has to include the "piwik.php" string.
The PiwikTracker SDK supports opting out of tracking. Please use the isOptedOut property of the PiwikTracker to define if the user opted out of tracking.
PiwikTracker.shared?.isOptedOut = true
The PiwikTracker can track hierarchical screen names, e.g. screen/settings/register. Use this to create a hierarchical and logical grouping of screen views in the Piwik web interface.
PiwikTracker.shared?.track(view: ["path","to","your","page"])
You can also set the url of the page.
let url = URL(string: "https://piwik.org/get-involved/")
PiwikTracker.shared?.track(view: ["community","get-involved"], url: url)
Events can be used to track user interactions such as taps on a button. An event consists of four parts:
- Category
- Action
- Name (optional, recommended)
- Value (optional)
PiwikTracker.shared?.track(eventWithCategory: "player", action: "slide", name: "volume", value: 35.1)
This will log that the user slided the volume slider on the player to 35.1%.
The PiwikTracker will dispatch events every 30 seconds automatically. If you want to dispatch events manually, you can use the dispatch() function. You can, for example, dispatch whenever the application enter the background.
func applicationDidEnterBackground(_ application: UIApplication) {
PiwikTracker.shared?.dispatch()
}
The PiwikTracker starts a new session whenever the application starts. If you want to start a new session manually, you can use the startNewSession() function. You can, for example, start a new session whenever the user enters the application.
func applicationWillEnterForeground(_ application: UIApplication) {
PiwikTracker.shared?.startNewSession()
}
Please read CONTRIBUTING.md for details.
- Basic functionality
- Tracking of more things
- Exceptions
- Social Interactions
- Search
- Goals and Conversions
- Outlinks
- Downloads
- Ecommerce Transactions
- Campaigns
- Content Impressions / Content Interactions
- Customizing the tracker
PiwikTracker is available under the MIT license.
