在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:matomo-org/matomo-sdk-ios开源软件地址:https://github.com/matomo-org/matomo-sdk-ios开源编程语言:Swift 86.1%开源软件介绍:MatomoTracker (former PiwikTracker) iOS SDKThe MatomoTracker is an iOS, tvOS and macOS SDK for sending app analytics to a Matomo server. MatomoTracker can be used from Swift and Objective-C. Fancy help improve this SDK? Check this list to see what is left and can be improved. InstallationThe MatomoTracker can be installed via CocoaPods, Carthage and the Swift Package Manager. In every file you want to use the MatomoTracker, don't forget to import the framework with CocoaPodsUse the following in your Podfile.
Then run CarthageCarthage is a non intrusive way to install MatomoTracker to your project. It makes no changes to your Xcode project and workspace. Add the following to your Cartfile:
Swift Package ManagerYou can use the Swift Package Manager as integration method. If you want to use the Swift Package Manager as integration method, either use Xcode to add the package dependency or add the following dependency to your Package.swift:
UsageMatomo InstanceThe Matomo iOS SDK doesn't provide a instance of the PiwikTracker. In order to be able to track data you have to create an instance first. let matomoTracker = MatomoTracker(siteId: "23", baseURL: URL(string: "https://demo2.matomo.org/piwik.php")!) The You can either pass around this instance, or add an extension to the extension MatomoTracker {
static let shared: MatomoTracker = MatomoTracker(siteId: "1", baseURL: URL(string: "https://example.com/piwik.php")!)
} The You can use multiple instances within one application. Opting OutThe MatomoTracker SDK supports opting out of tracking. Please use the matomoTracker.isOptedOut = true Tracking Page ViewsThe MatomoTracker can track hierarchical screen names, e.g. screen/settings/register. Use this to create a hierarchical and logical grouping of screen views in the Matomo web interface. matomoTracker.track(view: ["path","to","your","page"]) You can also set the url of the page. let url = URL(string: "https://matomo.org/get-involved/")
matomoTracker.track(view: ["community","get-involved"], url: url) Tracking EventsEvents can be used to track user interactions such as taps on a button. An event consists of four parts:
matomoTracker.track(eventWithCategory: "player", action: "slide", name: "volume", value: 35.1) This will log that the user slid the volume slider on the player to 35.1%. Tracking searchThe matomoTracker.trackSearch(query: "Best mobile tracking", category: "Technology", resultCount: 15) Custom DimensionThe Matomo SDK currently supports Custom Dimensions for the Visit Scope. Using Custom Dimensions you can add properties to the whole visit, such as "Did the user finish the tutorial?", "Is the user a paying user?" or "Which version of the Application is being used?" and such. Before sending custom dimensions please make sure Custom Dimensions are properly installed and configured. You will need the After that you can set a new Dimension, matomoTracker.set(value: "1.0.0-beta2", forIndex: 1) or remove an already set dimension. matomoTracker.remove(dimensionAtIndex: 1) Dimensions in the Visit Scope will be sent along every Page View or Event. Custom Dimensions are not persisted by the SDK and have to be re-configured upon application startup. Custom User IDTo add a custom User ID, simply set the value you'd like to use on the matomoTracker.userId = "coolUsername123" All future events being tracked by the SDK will be associated with this userID, as opposed to the default UUID created for each Visitor. Custom Visitor ID persisted on app startsMatomoTracker will generate an If you want to set your own visitor id, you can set your own visitor id with the matomoTracker.forcedVisitorId = "0123456789abcdef" Because the SDK persists this visitor id on app start, then we recommend to ask users for consent before tracking your app users. Campaign TrackingThe Matomo iOS SDK supports campaign tracking. matomoTracker.trackCampaign(name: "campaign_name", keyword: "campaign_keyword") Content TrackingThe Matomo iOS SDK supports content tracking. matomoTracker.trackContentImpression(name: "preview-liveaboard", piece: "Malaysia", target: "https://dummy.matomo.org/liveaboard/malaysia")
matomoTracker.trackContentInteraction(name: "preview-liveaboard", interaction: "tap", piece: "Malaysia", target: "https://dummy.matomo.org/liveaboard/malaysia") Goal TrackingThe Matomo iOS SDK supports goal tracking. matomoTracker.trackGoal(id: 1, revenue: 99.99) Order TrackingThe Matomo iOS SDK supports order tracking. let items = [
OrderItem(sku: "product_sku_1", name: "iPhone Xs", category: "phone", price: 999.99, quantity: 1),
OrderItem(sku: "product_sku_2", name: "iPhone Xs Max", category: "phone", price: 1199.99, quantity: 1)
]
matomoTracker.trackOrder(id: "order_id_1234", items: items, revenue: 2199.98, subTotal: 2000, tax: 190.98, shippingCost: 9) Advanced UsageManual dispatchingThe MatomoTracker will dispatch events every 30 seconds automatically. If you want to dispatch events manually, you can use the Session ManagementThe MatomoTracker starts a new session whenever the application starts. If you want to start a new session manually, you can use the func applicationWillEnterForeground(_ application: UIApplication) {
matomoTracker.startNewSession()
} LoggingThe MatomoTracker per default logs matomoTracker.logger = DefaultLogger(minLevel: .verbose)
matomoTracker.logger = DefaultLogger(minLevel: .debug)
matomoTracker.logger = DefaultLogger(minLevel: .info)
matomoTracker.logger = DefaultLogger(minLevel: .warning)
matomoTracker.logger = DefaultLogger(minLevel: .error) You can also write your own Custom User AgentThe let matomoTracker = MatomoTracker(siteId: "5", baseURL: URL(string: "http://your.server.org/path-to-matomo/piwik.php")!, userAgent: "Your custom user agent") Sending custom eventsInstead of using the convenience functions for events and screen views for example you can create your event manually and even send custom tracking parameters. This feature isn't available from Objective-C. func sendCustomEvent() {
guard let matomoTracker = MatomoTracker.shared else { return }
let downloadURL = URL(string: "https://builds.matomo.org/piwik.zip")!
let event = Event(tracker: matomoTracker, action: ["menu", "custom tracking parameters"], url: downloadURL, customTrackingParameters: ["download": downloadURL.absoluteString])
matomoTracker.track(event)
} All custom events will be URL-encoded and dispatched along with the default Event parameters. Please read the Tracking API Documentation for more information on which parameters can be used. Also: You cannot override Custom Parameter keys that are already defined by the Event itself. If you set those keys in the Automatic url generationYou can define the url property on every Event dispatchingWhenever you track an event or a page view it is stored in memory first. In every dispatch run a batch of those events are sent to the server. If the device is offline or the server doesn't respond these events will be kept and resent at a later time. Events currently aren't stored on disk and will be lost if the application is terminated. #137 ContributingPlease read CONTRIBUTING.md for details. LicenseMatomoTracker is available under the MIT license. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论