Skip to content

Commit 0c9c2de

Browse files
authored
Merge pull request #4 from logicwind/dev
Remove setIsOptedOut method and added disableTracking and enableTracking
2 parents c9aa991 + 2370bf2 commit 0c9c2de

File tree

7 files changed

+301
-55
lines changed

7 files changed

+301
-55
lines changed

README.md

Lines changed: 229 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,287 @@
11
# @logicwind/react-native-matomo-tracker
22

3-
@logicwind/react-native-matomo-tracker is a React Native library that provides integration with the Matomo analytics platform for tracking user interactions and events in mobile applications and TV applications.
3+
@logicwind/react-native-matomo-tracker is a React Native library that provides integration with the Matomo analytics platform for tracking user interactions and events in mobile applications and TV applications. This package supported **Android, ios, Android TV, Apple TV, Fire TV**.
44

55
With @logicwind/react-native-matomo-tracker, developers can seamlessly integrate Matomo analytics into their React Native applications, allowing them to track various user interactions such as screen views, button clicks, form submissions, and custom events. This integration enables developers to gain insights into how users interact with their mobile apps, monitor app performance, and make data-driven decisions to improve the user experience.
66

7+
78
## Installation
89

9-
```sh
10-
npm install @logicwind/react-native-matomo-tracker
10+
Using npm:
11+
12+
```shell
13+
npm install @logicwind/react-native-matomo-tracker
14+
```
15+
16+
or using yarn:
17+
18+
```shell
19+
yarn add @logicwind/react-native-matomo-tracker
1120
```
21+
Then follow the instructions for your platform to link @logicwind/react-native-matomo-tracker into your project:
22+
23+
### iOS installation
24+
25+
**React Native 0.70 and above**
26+
27+
Run `npx pod-install`. Linking is not required in React Native 0.70 and above.
28+
29+
### tvOS installation
30+
31+
Run `npx pod-install`. Linking is not required in React Native 0.70 and above.
32+
1233

1334
## Usage
1435

1536
```js
16-
import { createTracker, setUserId, setVisitorId, trackDispatch, trackDownload, trackEvent, trackImpression, trackInteraction, trackOutlink, trackScreen, trackSearch } from '@logicwind/react-native-matomo-tracker';
37+
import {
38+
createTracker,
39+
setUserId,
40+
setVisitorId,
41+
trackDispatch,
42+
trackDownload,
43+
trackEvent,
44+
trackImpression,
45+
trackInteraction,
46+
trackScreen,
47+
trackSearch,
48+
disableTracking,
49+
enableTracking,
50+
startSession,
51+
} from '@logicwind/react-native-matomo-tracker';
1752

1853
```
1954

55+
### createTracker()
56+
57+
The createTracker function is used to instantiate a tracker object for Matomo analytics within a React Native application .It will take `matomo-url` and `siteId` parameter.
58+
#### note
59+
for matomo-url madatory to add `/matomo.php` end of url.
60+
61+
#### Examples
62+
63+
```js
64+
65+
createTracker("https://your-matomo-url/matomo.php","siteId")
66+
67+
```
68+
69+
70+
### startSession()
71+
72+
The MatomoTracker starts a new session whenever the application starts. If you want to start a new session manually, you can use the startSession() function.
73+
74+
#### Examples
75+
76+
```js
77+
78+
startSession()
79+
80+
```
81+
82+
83+
### trackScreen()
84+
85+
The trackScreen method is used to track screen views within a React Native application. It will take `screen name` and `title` parameter.
86+
87+
#### Examples
88+
2089
```js
21-
useEffect(()=>{
22-
createTracker("your-matomo-url","siteid")
23-
},[])
90+
91+
trackScreen("HomeScreen","Navigate to home screen")
2492

2593
```
2694

95+
### trackEvent()
96+
97+
The trackEvent method is used to track custom events within a React Native application. It will take `category`,`action`,`name` and `value` parameter.
98+
99+
#### Examples
100+
27101
```js
28-
trackScreen("HomeScreen","This is test home screen")
29102

30103
trackEvent("test category","test action"," test name",2);
31104

105+
```
106+
107+
108+
#### Custom data traking with track event
109+
110+
```js
111+
32112
trackEvent("basket",JSON.stringify({
33113
id: 3745092,
34114
item: 'mens grey t-shirt',
35115
description: ['round neck', 'long sleeved'],
36116
size: 'L',
37117
}));
38118

119+
```
120+
121+
### trackOutlink()
122+
123+
The trackOutlink method is used to track clicks on outbound links within a React Native application. It will take only `url` parameter.
124+
125+
#### Examples
126+
127+
```js
128+
39129
trackOutlink("https://www.google.com/")
40130

41-
trackSearch("Logicwind")
131+
```
132+
133+
### trackSearch()
134+
135+
The trackSearch method is used to track search keyword within a React Native application. It will take only `keyword` parameter.
136+
137+
#### Examples
138+
139+
```js
140+
141+
trackImpression("Logicwind")
142+
143+
```
144+
145+
### trackImpression()
146+
147+
The trackImpression method is used to track specific content or elements within a React Native application. It will take only `contentName` parameter.
148+
149+
#### Examples
150+
151+
```js
42152

43153
trackImpression("Test Track Impression")
44154

155+
```
156+
157+
### trackInteraction()
158+
159+
The trackInteraction method is used to track users engage with specific elements or perform actions within a React Native application. It will take `contentName` and `contentInteraction` parameter.
160+
161+
#### Examples
162+
163+
```js
164+
45165
trackInteraction("Test Track interaction","test inetraction")
46166

167+
```
168+
169+
### trackDownload()
170+
171+
The trackDownload method is used to track the download of files or resources within a React Native application. It will take `category`,`action` and `download-url` parameter.
172+
173+
#### Examples
174+
175+
```js
176+
47177
trackDownload("Download","PDF Download","https://example.com/download.pdf")
48178

179+
```
180+
181+
### setUserId()
182+
183+
The setUserId function is used to assign a unique identifier to a user in a React Native application. It will take `id` parameter.
184+
185+
#### Examples
186+
187+
```js
188+
49189
setUserId("[email protected]")
50190

51-
if(Platform.OS=="ios"){
191+
```
192+
193+
194+
### setVisitorId()
195+
196+
By default matomo generate the unique visitor id but if you want custom vistor id then setVisitorId function allows you to manually set a custom visitor ID for tracking purposes within a React Native application . It will take `visitor-id` parameter.
197+
198+
#### Examples
199+
200+
#### ios
201+
202+
```js
203+
52204
setVisitorId("123e4567-e89b-12d3-a456-426614174000")
53-
}
54-
else{
205+
206+
```
207+
#### Android
208+
209+
```js
210+
55211
setVisitorId("2c534f55fba6cf6e")
56-
}
57212

58-
setIsOptedOut(true)
213+
```
214+
215+
### trackDispatch()
59216

60-
setLogger()
217+
The MatomoTracker will dispatch events every 30 seconds automatically. If you want to dispatch events manually, you can use the trackDispatch() function.
218+
219+
#### Examples
220+
221+
```js
61222

62223
trackDispatch()
63224

64225
```
65226

227+
### disableTracking()
228+
229+
By default the tracking is enable. If you want to disable traking, you can use the disableTracking() function.
230+
231+
#### Examples
232+
233+
```js
234+
235+
disableTracking()
236+
237+
```
238+
239+
### enableTracking()
240+
241+
The enableTracking function is used for enable traking.
242+
243+
#### Examples
244+
245+
```js
246+
247+
enableTracking()
248+
249+
```
250+
251+
### setLogger()
252+
253+
To enable logging for debugging purposes in the Matomo Android SDK and IOS SDK, you can set a custom logger. This is useful to see detailed logs of the SDK’s operations, which can help during development and troubleshooting.
254+
255+
#### Examples
256+
257+
```js
258+
259+
setLogger()
260+
261+
```
262+
66263

67264

68265
## Methods
69266

70267

71-
| Name | Description |
72-
|-----------------|-----------------|
73-
| createTracker | The createTracker function is used to instantiate a tracker object for Matomo analytics within a React Native application. This tracker instance allows developers to track various user interactions and events within their mobile app. |
74-
| startSession | The startSession method is used to start a new session explicitly within a React Native application.|
75-
| trackScreen | The trackScreen method is used to track screen views within a React Native application. Screen tracking allows developers to monitor user navigation and engagement by recording when users view specific screens or pages within the app.|
76-
| trackEvent | The trackEvent method is used to track custom events within a React Native application. Event tracking allows developers to monitor and analyze user interactions, such as button clicks, form submissions, or any other custom actions performed by users within the app. |
77-
| trackOutlink | The trackOutlink method is used to track clicks on outbound links within a React Native application. Outbound link tracking allows developers to monitor when users click on links that navigate them away from the app to external websites or resources. |
78-
| trackSearch | Tracking user searches in a React Native application involves capturing search queries entered by users and sending this data to your analytics platform. This enables you to understand what users are searching for within your app and how they interact with search results. |
79-
| trackImpression | Tracking impressions in a React Native application involves capturing instances where users are exposed to specific content or elements within the app's interface. This could include advertisements, product listings, promotional banners, or any other items that are displayed to users. |
80-
| trackInteraction | Tracking user interactions in a React Native application involves capturing instances where users engage with specific elements or perform actions within the app's interface. These interactions could include clicks on buttons, taps on links, form submissions, or any other user actions that you want to monitor. |
81-
| trackDownload | Tracking downloads in a React Native application involves capturing instances where users initiate and complete the download of files or resources. These downloads could include documents, media files, app updates, or any other downloadable content provided within the app.|
82-
| setUserId | The setUserId function is used to assign a unique identifier to a user in a React Native application. This identifier can be used to track user-specific actions, behavior, and engagement within the app. |
83-
| setVisitorId | The setVisitorId function allows you to manually set a custom visitor ID for tracking purposes within a React Native application. |
84-
| trackDispatch | The trackDispatch methods for tracking events, interactions, and other analytics-related functionalities within a React Native application. However, there isn't a standard trackDispatch method in Matomo tracking libraries, including the one provided by this package |
85-
| setIsOptedOut | setIsOptedOut method for disabling Matomo tracking in a React Native application. |
86-
| setLogger | setLogger method use for set up logging for Matomo SDK |
268+
| Method | Require Paramter | Android | ios | Android TV | Apple TV |
269+
|--------------------------------------|-----------------------------------------------------------|:-------:|:---:|:----------:|:--------:|
270+
| [createTracker](#createtracker) | uri: String, siteId: Number |||||
271+
| [startSession](#startsession) | - |||||
272+
| [trackScreen](#trackscreen) | screenName: String, title: String |||||
273+
| [trackEvent](#trackevent) | category:String, action:String, name:String, value:Number |||||
274+
| [trackOutlink](#trackoutlink) | url:String |||||
275+
| [trackSearch](#tracksearch) | keyword:String |||||
276+
| [trackImpression](#trackimpression) | contentName:String |||||
277+
| [trackInteraction](#trackinteraction)| contentName:String, contentInteraction:String |||||
278+
| [trackDownload](#trackdownload) | category:String, action:String, url:String |||||
279+
| [setUserId](#setuserid) | id:String |||||
280+
| [setVisitorId](#setvisitorid) | visitorId:String |||||
281+
| [trackDispatch](#trackdispatch) | - |||||
282+
| [disableTracking](#disabletracking) | - |||||
283+
| [enableTracking](#enabletracking) | - |||||
284+
| [setLogger](#setlogger) | - |||||
87285

88286

89287
<!-- ## Contributing
@@ -98,6 +296,3 @@ This project is licensed under the MIT License - see the [LICENSE.md](LICENSE) f
98296
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
99297

100298

101-
## Keywords
102-
103-
React-Native, Android, ios, Android TV, Apple TV, Fire TV

android/src/main/java/com/logicwind/reactnativematomotracker/ReactNativeMatomoTrackerModule.kt

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import com.facebook.react.bridge.ReactApplicationContext
44
import com.facebook.react.bridge.ReactContextBaseJavaModule
55
import com.facebook.react.bridge.ReactMethod
66
import com.facebook.react.bridge.Promise
7+
import com.facebook.react.bridge.ReadableArray
8+
import com.facebook.react.bridge.ReadableMap
9+
import com.facebook.react.bridge.ReadableMapKeySetIterator
710
import timber.log.Timber
811
import org.matomo.sdk.Matomo
912
import org.matomo.sdk.Tracker
@@ -13,6 +16,7 @@ import java.net.URL
1316
import android.content.ContentValues.TAG
1417
import android.util.Log
1518
import android.app.Application
19+
import org.matomo.sdk.extra.DownloadTracker
1620

1721

1822
class ReactNativeMatomoTrackerModule(reactContext: ReactApplicationContext) :
@@ -121,7 +125,9 @@ class ReactNativeMatomoTrackerModule(reactContext: ReactApplicationContext) :
121125
fun trackDownload(category: String,action: String,url: String) {
122126
if (tracker != null) {
123127
TrackHelper.track().event(category, action).name(url).with(tracker);
124-
// TrackHelper.track().download().with(tracker);
128+
129+
TrackHelper.track().download().with(tracker);
130+
125131
}
126132
}
127133

@@ -159,16 +165,27 @@ class ReactNativeMatomoTrackerModule(reactContext: ReactApplicationContext) :
159165
}
160166

161167

168+
@ReactMethod
169+
fun disableTracking() {
170+
171+
if (tracker != null) {
172+
tracker?.setOptOut(true);
173+
}
174+
}
175+
162176
@ReactMethod
163-
fun setIsOptedOut(isOptedOut:Boolean) {
164-
Log.e(TAG, "An error occurred: ${isOptedOut}")
177+
fun enableTracking() {
178+
165179
if (tracker != null) {
166-
tracker?.setOptOut(isOptedOut);
180+
tracker?.setOptOut(false);
167181
}
168182
}
169183

170184

171-
companion object {
185+
186+
187+
188+
companion object {
172189
const val NAME = "ReactNativeMatomoTracker"
173190
}
174191
}

0 commit comments

Comments
 (0)