$ npm install react-native-matomo-sdk --save
- Requires React Native version 0.60.0, or later.
- Supports iOS 10.0, or later.
Since the official matomo-sdk-ios
library is written is Swift, you need to have Swift enabled in your iOS project. If you already have any .swift
files, you are good to go. Otherwise create a new empty Swift source file in Xcode, and allow it to create the neccessary bridging header when prompted.
import Matomo from "react-native-matomo-sdk";
Matomo.initialize("https://example.com/piwik.php", 1)
.catch(error => console.warn("Failed to initialize matomo", error))
.then(() => Matomo.setUserId("UniqueUserId"))
.then(() => Matomo.setCustomDimension(1, "1.0.0"))
.then(() => {
Matomo.trackEvent("Application", "Startup").catch(error =>
console.warn("Failed to track event", error)
);
Matomo.trackView(["start"]).catch(error =>
console.warn("Failed to track screen", error)
);
}
);
Initializes the Matomo tracker. This should be called once on application start, after which the other API functions will work. Calling any other functions before the initialize
call has resolved will likely result in an error.
Tracks an event using the previously initialized tracker.
Tracks a screen view using the previously initialized tracker. The path parts will be joined to a path string, with parts separated by /
characters.
Sets the user id for the tracker. Passing null
as the user id will clear any previously set user id.
Sets a custom dimension value for the tracker which will be sent as part of all subsequent tracking calls. Passing null
as the value will clear any previously set value for the given dimension id.
The simplest way to develop the library is through the examples app. First install the
cd example/
npm ci
Open the example project in Android Studio, and edit the react-native-matomo-sdk
Java Module from the sidebar. This will ensure that the SDK build environment matches that of a proper React Native application.
For iOS you need to install the Pod dependencies, and open the XCode workspace to edit with proper compiler support. The Matomo SDK can be found in the project view under example
> Libararies
> RNMatomoSDK.xcodeproj
.
cd example/
# Install pod dependencies
pod install --project-directory=ios/
# Open project in xcode
open ios/example.xcworkspace/
# Switch to master branch
git checkout master
# Set new version
npm version [major | minor | patch]
# Push tag
git push --follow-tags