init static method
- String siteUrl,
- int idSite, {
- String? id,
- String? apiV,
- bool rec = true,
- MatomoForeverMethod method = MatomoForeverMethod.post,
- int bulkSize = 0,
- String? tokenAuth,
- bool? queuedTracking,
- bool? sendImage,
- bool? ping,
- bool? bots,
- bool? debug,
- Map<
String, String> ? headers, - Map<
String, String> ? persistentParameters, - Future<
bool> sendThroughGetMethod(})?, - Future<
bool> sendThroughPostMethod(})?, - BaseClient? client,
init Initializes the global _matomoForever object with:
siteUrl
The Matomo or piwik URL such as
https://matomo.example.com/matomo.php
idSite
The ID of the website we're tracking a visit/action for.
id
The unique visitor ID, must be a 16 characters hexadecimal string.
Every unique visitor must be assigned a different ID and this ID must not
change after it is assigned. If this value is not set Matomo (formerly
Piwik) will still track visits, but the unique visitors metric might be
less accurate.
Corresponds to _id in
https://developer.matomo.org/api-reference/tracking-api
apiV
The parameter &apiv=1 defines the api version to use (currently
always set to 1)
rec
Required for tracking, must be set to true.
method
Can be either post or get except for bulk sending which must be
sent through post method.
bulkSize
Max size the local queue can reach before sending the bulk of
requests. If <= 0, no bulk mechanism. requests are sent straight away.
Bulk sending requires tokenAuth
to be set.
tokenAuth
32 character authorization key used to authenticate the API
request. We recommend to create a user specifically for accessing the
Tracking API, and give the user only write permission on the website(s).
queuedTracking
When set to false (0), the queued tracking handler won't
be used and instead the tracking request will be executed directly. This
can be useful when you need to debug a tracking problem or want to test
that the tracking works in general.
sendImage
If set to false (send_image=0) Matomo will respond with HTTP
204 response code instead of a GIF image. This improves performance and
can fix errors if images are not allowed to be obtained directly (eg
Chrome Apps). Available since Matomo 2.10.0
ping
If set to true (ping=1), the request will be a Heartbeat request
which will not track any new activity (such as a new visit, new action or
new goal). The heartbeat request will only update the visit's total time
to provide accurate "Visit duration" metric when this parameter is set.
It won't record any other data. This means by sending an additional
tracking request when the user leaves your site or app with ping set to
true (&ping=1), you fix the issue where the time spent of the last page
visited is reported as 0 seconds.
bots
By default Matomo does not track bots. If you use the Tracking HTTP
API directly, you may be interested in tracking bot requests. To enable
Bot Tracking in Matomo, set the parameter bots to true (&bots=1) in your
requests to matomo.php.
debug
If Matomo server is configured with debug_on_demand = 1, debug can
be set to true (1)
headers
The headers to be sent along with request.
persistentParameters
Custom parameters sent at each call.
Refer to: https://developer.matomo.org/api-reference/tracking-api
sendThroughGetMethod
Function used to send the data to the server.
There is a fallback in case it is not initialized through the init call.
Returns true for success.
urlWithoutParameters
The matomo.php URL without the parameters.
urlParameters
The parameters String formatted for a GET request.
headers
The headers to be sent along with request.
sendThroughPostMethod
Function used to send the data to the server.
There is a fallback in case it is not initialized through the init call.
Returns true for success.
urlWithoutParameters
The matomo.php URL without the parameters.
data
The parameters to be sent by post.
headers
The headers to be sent along with request.
client
To be used instead of the default one to communicate with the
server.
Implementation
static void init(
String siteUrl,
int idSite, {
String? id,
String? apiV,
bool rec = true,
MatomoForeverMethod method = MatomoForeverMethod.post,
int bulkSize = 0,
String? tokenAuth,
bool? queuedTracking,
bool? sendImage,
bool? ping,
bool? bots,
bool? debug,
Map<String, String>? headers,
Map<String, String>? persistentParameters,
Future<bool> Function(
String urlWithoutParameters,
String urlParameters, {
Map<String, String>? headers,
})? sendThroughGetMethod,
Future<bool> Function(
String urlWithoutParameters,
Object data, {
Map<String, String>? headers,
})? sendThroughPostMethod,
http.BaseClient? client,
}) {
assert(bulkSize <= 0 || (tokenAuth ?? "").isNotEmpty,
"bulk sending is only possible with authToken");
assert(bulkSize <= 0 || method == MatomoForeverMethod.post,
"bulk sending possible only through POST method");
_matomoForever.siteUrl = siteUrl;
_matomoForever.idSite = idSite;
_matomoForever.id = id;
_matomoForever.apiV = apiV;
_matomoForever.rec = rec;
_matomoForever.method = method;
_matomoForever.bulkSize = bulkSize;
_matomoForever.tokenAuth = tokenAuth;
_matomoForever.queuedTracking = queuedTracking;
_matomoForever.sendImage = sendImage;
_matomoForever.ping = ping;
_matomoForever.bots = bots;
_matomoForever.debug = debug;
_matomoForever.headers = headers;
_matomoForever.persistentParameters = persistentParameters;
if (sendThroughGetMethod != null) {
_matomoForever.sendThroughGetMethod = sendThroughGetMethod;
}
if (sendThroughPostMethod != null) {
_matomoForever.sendThroughPostMethod = sendThroughPostMethod;
}
_matomoForever.client = client;
_matomoForever._initialized = true;
}