-
Notifications
You must be signed in to change notification settings - Fork 52
/
MatomoRequest.java
1171 lines (1048 loc) · 35.1 KB
/
MatomoRequest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Matomo Java Tracker
*
* @link https://github.com/matomo/matomo-java-tracker
* @license https://github.com/matomo/matomo-java-tracker/blob/master/LICENSE BSD-3 Clause
*/
package org.matomo.java.tracking;
import edu.umd.cs.findbugs.annotations.Nullable;
import java.nio.charset.Charset;
import java.time.Instant;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.UUID;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Builder.Default;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Tolerate;
import org.matomo.java.tracking.parameters.AcceptLanguage;
import org.matomo.java.tracking.parameters.Country;
import org.matomo.java.tracking.parameters.CustomVariable;
import org.matomo.java.tracking.parameters.CustomVariables;
import org.matomo.java.tracking.parameters.DeviceResolution;
import org.matomo.java.tracking.parameters.EcommerceItem;
import org.matomo.java.tracking.parameters.EcommerceItems;
import org.matomo.java.tracking.parameters.RandomValue;
import org.matomo.java.tracking.parameters.UniqueId;
import org.matomo.java.tracking.parameters.VisitorId;
/**
* A class that implements the <a href="https://developer.matomo.org/api-reference/tracking-api">
* Matomo Tracking HTTP API</a>. These requests can be sent using {@link MatomoTracker}.
*
* @author brettcsorba
*/
@Builder(builderMethodName = "request")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class MatomoRequest {
/**
* The ID of the website we're tracking a visit/action for. Only needed, if no default site id is
* configured.
*/
@TrackingParameter(name = "rec")
@Default
private Boolean required = true;
/**
* The ID of the website we're tracking a visit/action for. Only needed, if no default site id is
* configured.
*/
@TrackingParameter(
name = "idsite",
min = 1
)
private Integer siteId;
/**
* The title of the action being tracked. For page tracks this is used as page title. If enabled
* in your installation you may use the category tree structure in this field. For example, "game
* / register new user" would then create a group "game" and add the item "register new user" in
* it.
*/
@TrackingParameter(name = "action_name")
private String actionName;
/**
* The full URL for the current action.
*/
@TrackingParameter(name = "url")
private String actionUrl;
/**
* Defines the API version to use (default: 1).
*/
@TrackingParameter(name = "apiv")
@Default
private String apiVersion = "1";
/**
* The unique visitor ID. See {@link VisitorId}. Default is {@link VisitorId#random()}
*
* <p>Since version 3.0.0 this parameter is of type {@link VisitorId} and not a String anymore.
* Use {@link VisitorId#fromHex(String)} to create a VisitorId from a hex string,
* {@link VisitorId#fromUUID(UUID)} to create it from a UUID or {@link VisitorId#fromHash(long)}
* to create it from a long value.
*/
@TrackingParameter(name = "_id")
@Default
private VisitorId visitorId = VisitorId.random();
/**
* Tracks if the visitor is a returning visitor.
*
* <p>This is done by storing a visitor ID in a 1st party cookie.
*/
@TrackingParameter(name = "_idn")
private Boolean newVisitor;
/**
* The full HTTP Referrer URL. This value is used to determine how someone got to your website
* (ie, through a website, search engine or campaign)
*/
@TrackingParameter(name = "urlref")
private String referrerUrl;
/**
* Custom variables are custom name-value pairs that you can assign to your visitors (or page
* views).
*/
@TrackingParameter(name = "_cvar")
private CustomVariables visitCustomVariables;
/**
* The current count of visits for this visitor. To set this value correctly, it would be required
* to store the value for each visitor in your application (using sessions or persisting in a
* database). Then you would manually increment the counts by one on each new visit or "session",
* depending on how you choose to define a visit.
*/
@TrackingParameter(name = "_idvc", min = 0)
private Integer visitorVisitCount;
/**
* The UNIX timestamp of this visitor's previous visit. This parameter is used to populate the
* report Visitors > Engagement > Visits by days since last visit.
*/
@TrackingParameter(name = "_viewts")
private Instant visitorPreviousVisitTimestamp;
/**
* The UNIX timestamp of this visitor's first visit. This could be set to the date where the user
* first started using your software/app, or when he/she created an account.
*/
@TrackingParameter(name = "_idts")
private Instant visitorFirstVisitTimestamp;
/**
* The campaign name. This parameter will only be used for the first pageview of a visit.
*/
@TrackingParameter(name = "_rcn")
private String campaignName;
/**
* The campaign keyword (see
* <a href="https://matomo.org/docs/tracking-campaigns/">Tracking Campaigns</a>). Used to
* populate the <em>Referrers > Campaigns</em> report (clicking on a campaign loads all
* keywords for this campaign). This parameter will only be used for the first pageview of a
* visit.
*/
@TrackingParameter(name = "_rck")
private String campaignKeyword;
/**
* The resolution of the device the visitor is using.
*/
@TrackingParameter(name = "res")
private DeviceResolution deviceResolution;
/**
* The current hour (local time).
*/
@TrackingParameter(
name = "h",
min = 0,
max = 23
)
private Integer currentHour;
/**
* The current minute (local time).
*/
@TrackingParameter(
name = "m",
min = 0,
max = 59
)
private Integer currentMinute;
/**
* The current second (local time).
*/
@TrackingParameter(
name = "s",
min = 0,
max = 59
)
private Integer currentSecond;
/**
* Does the visitor use the Adobe Flash Plugin.
*/
@TrackingParameter(name = "fla")
private Boolean pluginFlash;
/**
* Does the visitor use the Java plugin.
*/
@TrackingParameter(name = "java")
private Boolean pluginJava;
/**
* Does the visitor use Director plugin.
*/
@TrackingParameter(name = "dir")
private Boolean pluginDirector;
/**
* Does the visitor use Quicktime plugin.
*/
@TrackingParameter(name = "qt")
private Boolean pluginQuicktime;
/**
* Does the visitor use Realplayer plugin.
*/
@TrackingParameter(name = "realp")
private Boolean pluginRealPlayer;
/**
* Does the visitor use a PDF plugin.
*/
@TrackingParameter(name = "pdf")
private Boolean pluginPDF;
/**
* Does the visitor use a Windows Media plugin.
*/
@TrackingParameter(name = "wma")
private Boolean pluginWindowsMedia;
/**
* Does the visitor use a Gears plugin.
*/
@TrackingParameter(name = "gears")
private Boolean pluginGears;
/**
* Does the visitor use a Silverlight plugin.
*/
@TrackingParameter(name = "ag")
private Boolean pluginSilverlight;
/**
* Does the visitor's client is known to support cookies.
*/
@TrackingParameter(name = "cookie")
private Boolean supportsCookies;
/**
* An override value for the User-Agent HTTP header field.
*/
@TrackingParameter(name = "ua")
private String headerUserAgent;
/**
* An override value for the Accept-Language HTTP header field. This value is used to detect the
* visitor's country if GeoIP is not enabled.
*/
@TrackingParameter(name = "lang")
private AcceptLanguage headerAcceptLanguage;
/**
* Defines the User ID for this request. User ID is any non-empty unique string identifying the
* user (such as an email address or a username). When specified, the User ID will be "enforced".
* This means that if there is no recent visit with this User ID, a new one will be created. If a
* visit is found in the last 30 minutes with your specified User ID, then the new action will be
* recorded to this existing visit.
*/
@TrackingParameter(name = "uid")
private String userId;
/**
* defines the visitor ID for this request.
*/
@TrackingParameter(name = "cid")
private VisitorId visitorCustomId;
/**
* will force a new visit to be created for this action.
*/
@TrackingParameter(name = "new_visit")
private Boolean newVisit;
/**
* Custom variables are custom name-value pairs that you can assign to your visitors (or page
* views).
*/
@TrackingParameter(name = "cvar")
private CustomVariables pageCustomVariables;
/**
* An external URL the user has opened. Used for tracking outlink clicks. We recommend to also set
* the url parameter to this same value.
*/
@TrackingParameter(name = "link")
private String outlinkUrl;
/**
* URL of a file the user has downloaded. Used for tracking downloads. We recommend to also set
* the url parameter to this same value.
*/
@TrackingParameter(name = "download")
private String downloadUrl;
/**
* The Site Search keyword. When specified, the request will not be tracked as a normal pageview
* but will instead be tracked as a Site Search request
*/
@TrackingParameter(name = "search")
private String searchQuery;
/**
* When search is specified, you can optionally specify a search category with this parameter.
*/
@TrackingParameter(name = "search_cat")
private String searchCategory;
/**
* When search is specified, we also recommend setting the search_count to the number of search
* results displayed on the results page. When keywords are tracked with &search_count=0 they will
* appear in the "No Result Search Keyword" report.
*/
@TrackingParameter(
name = "search_count",
min = 0
)
private Long searchResultsCount;
/**
* Accepts a six character unique ID that identifies which actions were performed on a specific
* page view. When a page was viewed, all following tracking requests (such as events) during that
* page view should use the same pageview ID. Once another page was viewed a new unique ID should
* be generated. Use [0-9a-Z] as possible characters for the unique ID.
*/
@TrackingParameter(name = "pv_id")
private UniqueId pageViewId;
/**
* If specified, the tracking request will trigger a conversion for the goal of the website being
* tracked with this ID. The value 0 tracks an ecommerce interaction.
*/
@TrackingParameter(name = "idgoal", min = 0)
private Integer goalId;
/**
* The grand total for the ecommerce order (required when tracking an ecommerce order).
*/
@TrackingParameter(name = "revenue")
private Double ecommerceRevenue;
/**
* The charset of the page being tracked. Specify the charset if the data you send to Matomo is
* encoded in a different character set than the default utf-8
*/
@TrackingParameter(name = "cs")
private Charset characterSet;
/**
* can be optionally sent along any tracking request that isn't a page view. For example, it can
* be sent together with an event tracking request. The advantage being that should you ever
* disable the event plugin, then the event tracking requests will be ignored vs if the parameter
* is not set, a page view would be tracked even though it isn't a page view.
*/
@TrackingParameter(name = "ca")
private Boolean customAction;
/**
* How long it took to connect to server.
*/
@TrackingParameter(name = "pf_net", min = 0)
private Long networkTime;
/**
* How long it took the server to generate page.
*/
@TrackingParameter(name = "pf_srv", min = 0)
private Long serverTime;
/**
* How long it takes the browser to download the response from the server.
*/
@TrackingParameter(name = "pf_tfr", min = 0)
private Long transferTime;
/**
* How long the browser spends loading the webpage after the response was fully received until the
* user can start interacting with it.
*/
@TrackingParameter(name = "pf_dm1", min = 0)
private Long domProcessingTime;
/**
* How long it takes for the browser to load media and execute any Javascript code listening for
* the DOMContentLoaded event.
*/
@TrackingParameter(name = "pf_dm2", min = 0)
private Long domCompletionTime;
/**
* How long it takes the browser to execute Javascript code waiting for the window.load event.
*/
@TrackingParameter(name = "pf_onl", min = 0)
private Long onloadTime;
/**
* eg. Videos, Music, Games...
*/
@TrackingParameter(name = "e_c")
private String eventCategory;
/**
* An event action like Play, Pause, Duration, Add Playlist, Downloaded, Clicked...
*/
@TrackingParameter(name = "e_a")
private String eventAction;
/**
* The event name for example a Movie name, or Song name, or File name...
*/
@TrackingParameter(name = "e_n")
private String eventName;
/**
* Some numeric value that represents the event value.
*/
@TrackingParameter(name = "e_v")
private Double eventValue;
/**
* The name of the content. For instance 'Ad Foo Bar'
*/
@TrackingParameter(name = "c_n")
private String contentName;
/**
* The actual content piece. For instance the path to an image, video, audio, any text
*/
@TrackingParameter(name = "c_p")
private String contentPiece;
/**
* The target of the content. For instance the URL of a landing page
*/
@TrackingParameter(name = "c_t")
private String contentTarget;
/**
* The name of the interaction with the content. For instance a 'click'
*/
@TrackingParameter(name = "c_i")
private String contentInteraction;
/**
* The unique string identifier for the ecommerce order (required when tracking an ecommerce
* order).
*/
@TrackingParameter(name = "ec_id")
private String ecommerceId;
/**
* Items in the Ecommerce order.
*/
@TrackingParameter(name = "ec_items")
private EcommerceItems ecommerceItems;
/**
* The subtotal of the order; excludes shipping.
*/
@TrackingParameter(name = "ec_st")
private Double ecommerceSubtotal;
/**
* Tax amount of the order.
*/
@TrackingParameter(name = "ec_tx")
private Double ecommerceTax;
/**
* Shipping cost of the order.
*/
@TrackingParameter(name = "ec_sh")
private Double ecommerceShippingCost;
/**
* Discount offered.
*/
@TrackingParameter(name = "ec_dt")
private Double ecommerceDiscount;
/**
* The UNIX timestamp of this customer's last ecommerce order. This value is used to process the
* "Days since last order" report.
*/
@TrackingParameter(name = "_ects")
private Instant ecommerceLastOrderTimestamp;
/**
* 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).
*/
@TrackingParameter(
name = "token_auth",
regex = "[a-z0-9]{32}"
)
private String authToken;
/**
* Override value for the visitor IP (both IPv4 and IPv6 notations supported).
*/
@TrackingParameter(name = "cip")
private String visitorIp;
/**
* Override for the datetime of the request (normally the current time is used). This can be used
* to record visits and page views in the past.
*/
@TrackingParameter(name = "cdt")
private Instant requestTimestamp;
/**
* An override value for the country. Must be a two-letter ISO 3166 Alpha-2 country code.
*/
@TrackingParameter(
name = "country",
maxLength = 2
)
private Country visitorCountry;
/**
* An override value for the region. Should be set to a ISO 3166-2 region code, which are used by
* MaxMind's and DB-IP's GeoIP2 databases. See here for a list of them for every country.
*/
@TrackingParameter(
name = "region",
maxLength = 2
)
private String visitorRegion;
/**
* An override value for the city. The name of the city the visitor is located in, eg, Tokyo.
*/
@TrackingParameter(name = "city")
private String visitorCity;
/**
* An override value for the visitor's latitude, eg 22.456.
*/
@TrackingParameter(name = "lat", min = -90, max = 90)
private Double visitorLatitude;
/**
* An override value for the visitor's longitude, eg 22.456.
*/
@TrackingParameter(name = "long", min = -180, max = 180)
private Double visitorLongitude;
/**
* When set to false, 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.
*/
@TrackingParameter(name = "queuedtracking")
private Boolean queuedTracking;
/**
* If set to 0 (send_image=0) Matomo will respond with an 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 (like Chrome Apps). Available since Matomo 2.10.0
*
* <p>Default is {@code false}
*/
@TrackingParameter(name = "send_image")
@Default
private Boolean responseAsImage = false;
/**
* If set to true, 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=1, you fix the issue where the time spent of the last page
* visited is reported as 0 seconds.
*/
@TrackingParameter(name = "ping")
private Boolean ping;
/**
* By default, Matomo does not track bots. If you use the Tracking HTTP API directly, you may be
* interested in tracking bot requests.
*/
@TrackingParameter(name = "bots")
private Boolean trackBotRequests;
/**
* Meant to hold a random value that is generated before each request. Using it helps avoid the
* tracking request being cached by the browser or a proxy.
*/
@TrackingParameter(name = "rand")
@Default
private RandomValue randomValue = RandomValue.random();
/**
* Meant to hold a random value that is generated before each request. Using it helps avoid the
* tracking request being cached by the browser or a proxy.
*/
@TrackingParameter(name = "debug")
private Boolean debug;
/**
* Contains an error message describing the error that occurred during the last tracking request.
*
* <p>Custom action must be enabled for this.
*
* <p>Required for crash analytics
*/
@TrackingParameter(name = "cra")
private String crashMessage;
/**
* The type of exception that occurred during the last tracking request.
*
* <p>Custom action must be enabled for this.
*
* <p>Typically a fully qualified class name of the exception, e.g.
* {@code java.lang.NullPointerException}.
*
* <p>Optional for crash analytics
*/
@TrackingParameter(name = "cra_tp")
private String crashType;
/**
* Category of a crash to group crashes by.
*
* <p>Custom action must be enabled for this.
*
* <p>Optional for crash analytics
*/
@TrackingParameter(name = "cra_ct")
private String crashCategory;
/**
* A stack trace of the exception that occurred during the last tracking request.
*
* <p>Custom action must be enabled for this.
*
* <p>Optional for crash analytics
*/
@TrackingParameter(name = "cra_st")
private String crashStackTrace;
/**
* The originating source of the crash.
*
* <p>Could be a source file URI or something similar
*
* <p>Custom action must be enabled for this.
*
* <p>Optional for crash analytics
*/
@TrackingParameter(name = "cra_ru")
private String crashLocation;
/**
* The line number of the crash source, where the crash occurred.
*
* <p>Custom action must be enabled for this.
*
* <p>Optional for crash analytics
*/
@TrackingParameter(name = "cra_rl", min = 0)
private Integer crashLine;
/**
* The column within the line where the crash occurred.
*
* <p>Optional for crash analytics
*/
@TrackingParameter(name = "cra_rc", min = 0)
private Integer crashColumn;
/**
* The Matomo session ID sent as a cookie {@code MATOMO_SESSID}.
*
* <p>If not null a cookie with the name {@code MATOMO_SESSID} will be sent with the value of
* this parameter.
*/
private String sessionId;
/**
* Custom Dimension values for specific Custom Dimension IDs.
*
* <p><a href="https://plugins.matomo.org/CustomDimensions">Custom Dimensions plugin</a> must be
* installed. See the
* <a href="https://matomo.org/docs/custom-dimensions/">Custom Dimensions guide</a>. Requires
* Matomo at least 2.15.1
*/
private Map<Long, Object> dimensions;
/**
* Allows you to specify additional HTTP request parameters that will be sent to Matomo.
*
* <p>For example, you can use this to set the <em>Accept-Language</em> header, or to set the
* <em>Content-Type</em>.
*/
private Map<String, Object> additionalParameters;
/**
* You can set additional HTTP headers for the request sent to Matomo.
*
* <p>For example, you can use this to set the <em>Accept-Language</em> header, or to set the
* <em>Content-Type</em>.
*/
private Map<String, String> headers;
/**
* Appends additional cookies to the request.
*
* <p>This allows you to add Matomo specific cookies, like {@code _pk_id} or {@code _pk_sess}
* coming from Matomo responses to the request.
*/
private Map<String, String> cookies;
/**
* Create a new request from the id of the site being tracked and the full url for the current
* action. This constructor also sets:
* <pre>
* {@code
* Required = true
* Visior Id = random 16 character hex string
* Random Value = random 20 character hex string
* API version = 1
* Response as Image = false
* }
* </pre>
* Overwrite these values yourself as desired.
*
* @param siteId the id of the website we're tracking a visit/action for
* @param actionUrl the full URL for the current action
*
* @deprecated Please use {@link MatomoRequest#request()}
*/
@Deprecated
public MatomoRequest(int siteId, String actionUrl) {
this.siteId = siteId;
this.actionUrl = actionUrl;
required = true;
visitorId = VisitorId.random();
randomValue = RandomValue.random();
apiVersion = "1";
responseAsImage = false;
}
/**
* Gets the list of objects currently stored at the specified custom tracking parameter. An empty
* list will be returned if there are no objects set at that key.
*
* @param key the key of the parameter whose list of objects to get. Cannot be null
*
* @return the parameter at the specified key, null if nothing at this key
*/
@Nullable
public Object getCustomTrackingParameter(@NonNull String key) {
if (additionalParameters == null || additionalParameters.isEmpty()) {
return null;
}
return additionalParameters.get(key);
}
/**
* Set a custom tracking parameter whose toString() value will be sent to the Matomo server. These
* parameters are stored separately from named Matomo parameters, meaning it is not possible to
* overwrite or clear named Matomo parameters with this method. A custom parameter that has the
* same name as a named Matomo parameter will be sent in addition to that named parameter.
*
* @param key the parameter's key. Cannot be null
* @param value the parameter's value. Removes the parameter if null
*
* @deprecated Use {@link MatomoRequest.MatomoRequestBuilder#additionalParameters(Map)} instead.
*/
@Deprecated
public void setCustomTrackingParameter(
@NonNull String key, @Nullable Object value
) {
if (value == null) {
if (additionalParameters != null) {
additionalParameters.remove(key);
}
} else {
if (additionalParameters == null) {
additionalParameters = new LinkedHashMap<>();
}
additionalParameters.put(key, value);
}
}
/**
* Add a custom tracking parameter to the specified key. If there is already a parameter at this
* key, the new value replaces the old value.
*
* @param key the parameter's key. Cannot be null
* @param value the parameter's value. May be null
*
* @deprecated Use {@link MatomoRequest.MatomoRequestBuilder#additionalParameters(Map)} instead.
*/
@Deprecated
public void addCustomTrackingParameter(@NonNull String key, @Nullable Object value) {
if (additionalParameters == null) {
additionalParameters = new LinkedHashMap<>();
}
additionalParameters.put(key, value);
}
/**
* Removes all custom tracking parameters.
*
* @deprecated Please use {@link MatomoRequest.MatomoRequestBuilder#additionalParameters(Map)}
* instead so that you can manage the map yourself.
*/
@Deprecated
public void clearCustomTrackingParameter() {
additionalParameters.clear();
}
/**
* Sets <em>idgoal=0</em> in the request to track an ecommerce interaction: cart update or an
* ecommerce order.
*
* @deprecated Please use {@link MatomoRequest#setGoalId(Integer)} instead
*/
@Deprecated
public void enableEcommerce() {
setGoalId(0);
}
/**
* Get the {@link EcommerceItem} at the specified index.
*
* @param index the index of the {@link EcommerceItem} to return
*
* @return the {@link EcommerceItem} at the specified index
* @deprecated Use @link {@link MatomoRequest.MatomoRequestBuilder#ecommerceItems(EcommerceItems)}
* instead
*/
@Nullable
@Deprecated
public EcommerceItem getEcommerceItem(int index) {
if (ecommerceItems == null || ecommerceItems.isEmpty()) {
return null;
}
return ecommerceItems.get(index);
}
/**
* Add an {@link EcommerceItem} to this order. Ecommerce must be enabled, and EcommerceId and
* EcommerceRevenue must first be set.
*
* @param item the {@link EcommerceItem} to add. Cannot be null
*
* @deprecated Use @link {@link MatomoRequest.MatomoRequestBuilder#ecommerceItems(EcommerceItems)}
* instead
*/
@Deprecated
public void addEcommerceItem(@NonNull EcommerceItem item) {
if (ecommerceItems == null) {
ecommerceItems = new EcommerceItems();
}
ecommerceItems.add(item);
}
/**
* Clears all {@link EcommerceItem} from this order.
*
* @deprecated Use @link {@link MatomoRequest.MatomoRequestBuilder#ecommerceItems(EcommerceItems)}
* instead
*/
@Deprecated
public void clearEcommerceItems() {
ecommerceItems.clear();
}
/**
* Get the page custom variable at the specified key.
*
* @param key the key of the variable to get
*
* @return the variable at the specified key, null if key is not present
* @deprecated Use the {@link #getPageCustomVariables()} method instead.
*/
@Nullable
@Deprecated
public String getPageCustomVariable(String key) {
if (pageCustomVariables == null) {
return null;
}
return pageCustomVariables.get(key);
}
/**
* Get the page custom variable at the specified index.
*
* @param index the index of the variable to get. Must be greater than 0
*
* @return the variable at the specified key, null if nothing at this index
* @deprecated Use {@link MatomoRequest#getPageCustomVariables()} instead
*/
@Deprecated
@Nullable
public CustomVariable getPageCustomVariable(int index) {
return getCustomVariable(pageCustomVariables, index);
}
@Nullable
@Deprecated
private static CustomVariable getCustomVariable(CustomVariables customVariables, int index) {
if (customVariables == null) {
return null;
}
return customVariables.get(index);
}
/**
* Set a page custom variable with the specified key and value at the first available index. All
* page custom variables with this key will be overwritten or deleted
*
* @param key the key of the variable to set
* @param value the value of the variable to set at the specified key. A null value will remove
* this custom variable
*
* @deprecated Use {@link MatomoRequest#getPageCustomVariables()} instead
*/
@Deprecated
public void setPageCustomVariable(
@NonNull String key, @Nullable String value
) {
if (value == null) {
if (pageCustomVariables == null) {
return;
}
pageCustomVariables.remove(key);
} else {
CustomVariable variable = new CustomVariable(key, value);
if (pageCustomVariables == null) {
pageCustomVariables = new CustomVariables();
}
pageCustomVariables.add(variable);
}
}
/**
* Set a page custom variable at the specified index.
*
* @param customVariable the CustomVariable to set. A null value will remove the CustomVariable
* at the specified index
* @param index the index of he CustomVariable to set
*
* @deprecated Use {@link #getPageCustomVariables()} instead
*/
@Deprecated
public void setPageCustomVariable(
@Nullable CustomVariable customVariable, int index
) {
if (pageCustomVariables == null) {
if (customVariable == null) {
return;
}
pageCustomVariables = new CustomVariables();
}
setCustomVariable(pageCustomVariables, customVariable, index);
}
@Deprecated
private static void setCustomVariable(
CustomVariables customVariables, @Nullable CustomVariable customVariable, int index
) {
if (customVariable == null) {
customVariables.remove(index);
} else {
customVariables.add(customVariable, index);
}
}
/**
* Get the datetime of the request.
*
* @return the datetime of the request