Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Statistics.java « statistics « util « mapswithme « com « src « android - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 42db9632d163ae091e99deacd6103a91e15a5491 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
package com.mapswithme.util.statistics;

import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.text.TextUtils;
import android.util.Pair;

import com.android.billingclient.api.BillingClient;
import com.facebook.ads.AdError;
import com.facebook.appevents.AppEventsLogger;
import com.mapswithme.maps.BuildConfig;
import com.mapswithme.maps.Framework;
import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.PrivateVariables;
import com.mapswithme.maps.ads.MwmNativeAd;
import com.mapswithme.maps.ads.NativeAdError;
import com.mapswithme.maps.analytics.ExternalLibrariesMediator;
import com.mapswithme.maps.api.ParsedMwmRequest;
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
import com.mapswithme.maps.bookmarks.data.MapObject;
import com.mapswithme.maps.downloader.MapManager;
import com.mapswithme.maps.editor.Editor;
import com.mapswithme.maps.editor.OsmOAuth;
import com.mapswithme.maps.location.LocationHelper;
import com.mapswithme.maps.purchase.ValidationStatus;
import com.mapswithme.maps.routing.RoutePointInfo;
import com.mapswithme.maps.routing.RoutingOptions;
import com.mapswithme.maps.settings.RoadType;
import com.mapswithme.maps.taxi.TaxiInfoError;
import com.mapswithme.maps.taxi.TaxiManager;
import com.mapswithme.maps.widget.menu.MainMenu;
import com.mapswithme.maps.widget.placepage.Sponsored;
import com.mapswithme.util.BatteryState;
import com.mapswithme.util.Config;
import com.mapswithme.util.ConnectionState;
import com.mapswithme.util.Counters;
import com.mapswithme.util.PowerManagment;
import com.mapswithme.util.SharedPropertiesUtils;
import com.my.tracker.MyTracker;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.mapswithme.util.BatteryState.CHARGING_STATUS_PLUGGED;
import static com.mapswithme.util.BatteryState.CHARGING_STATUS_UNKNOWN;
import static com.mapswithme.util.BatteryState.CHARGING_STATUS_UNPLUGGED;
import static com.mapswithme.util.statistics.Statistics.EventName.APPLICATION_COLD_STARTUP_INFO;
import static com.mapswithme.util.statistics.Statistics.EventName.BM_GUIDES_DOWNLOADDIALOGUE_CLICK;
import static com.mapswithme.util.statistics.Statistics.EventName.BM_RESTORE_PROPOSAL_CLICK;
import static com.mapswithme.util.statistics.Statistics.EventName.BM_RESTORE_PROPOSAL_ERROR;
import static com.mapswithme.util.statistics.Statistics.EventName.BM_RESTORE_PROPOSAL_SUCCESS;
import static com.mapswithme.util.statistics.Statistics.EventName.BM_SYNC_ERROR;
import static com.mapswithme.util.statistics.Statistics.EventName.BM_SYNC_PROPOSAL_APPROVED;
import static com.mapswithme.util.statistics.Statistics.EventName.BM_SYNC_PROPOSAL_ERROR;
import static com.mapswithme.util.statistics.Statistics.EventName.BM_SYNC_PROPOSAL_SHOWN;
import static com.mapswithme.util.statistics.Statistics.EventName.BM_SYNC_PROPOSAL_TOGGLE;
import static com.mapswithme.util.statistics.Statistics.EventName.BM_SYNC_SUCCESS;
import static com.mapswithme.util.statistics.Statistics.EventName.DOWNLOADER_DIALOG_ERROR;
import static com.mapswithme.util.statistics.Statistics.EventName.GUIDES_BOOKMARK_SELECT;
import static com.mapswithme.util.statistics.Statistics.EventName.GUIDES_SHOWN;
import static com.mapswithme.util.statistics.Statistics.EventName.GUIDES_OPEN;
import static com.mapswithme.util.statistics.Statistics.EventName.GUIDES_TRACK_SELECT;
import static com.mapswithme.util.statistics.Statistics.EventName.INAPP_PURCHASE_PREVIEW_SELECT;
import static com.mapswithme.util.statistics.Statistics.EventName.INAPP_PURCHASE_PREVIEW_SHOW;
import static com.mapswithme.util.statistics.Statistics.EventName.INAPP_PURCHASE_PRODUCT_DELIVERED;
import static com.mapswithme.util.statistics.Statistics.EventName.INAPP_PURCHASE_STORE_ERROR;
import static com.mapswithme.util.statistics.Statistics.EventName.INAPP_PURCHASE_VALIDATION_ERROR;
import static com.mapswithme.util.statistics.Statistics.EventName.PP_BANNER_BLANK;
import static com.mapswithme.util.statistics.Statistics.EventName.PP_BANNER_CLOSE;
import static com.mapswithme.util.statistics.Statistics.EventName.PP_BANNER_ERROR;
import static com.mapswithme.util.statistics.Statistics.EventName.PP_BANNER_SHOW;
import static com.mapswithme.util.statistics.Statistics.EventName.PP_OWNERSHIP_BUTTON_CLICK;
import static com.mapswithme.util.statistics.Statistics.EventName.PP_SPONSORED_BOOK;
import static com.mapswithme.util.statistics.Statistics.EventName.PP_SPONSORED_ERROR;
import static com.mapswithme.util.statistics.Statistics.EventName.PP_SPONSORED_OPEN;
import static com.mapswithme.util.statistics.Statistics.EventName.PP_SPONSORED_SHOWN;
import static com.mapswithme.util.statistics.Statistics.EventName.PP_SPONSOR_ITEM_SELECTED;
import static com.mapswithme.util.statistics.Statistics.EventName.ROUTING_PLAN_TOOLTIP_CLICK;
import static com.mapswithme.util.statistics.Statistics.EventName.ROUTING_ROUTE_FINISH;
import static com.mapswithme.util.statistics.Statistics.EventName.ROUTING_ROUTE_START;
import static com.mapswithme.util.statistics.Statistics.EventName.SEARCH_FILTER_CLICK;
import static com.mapswithme.util.statistics.Statistics.EventName.TIPS_TRICKS_CLOSE;
import static com.mapswithme.util.statistics.Statistics.EventName.TOOLBAR_CLICK;
import static com.mapswithme.util.statistics.Statistics.EventName.TOOLBAR_MENU_CLICK;
import static com.mapswithme.util.statistics.Statistics.EventName.UGC_AUTH_ERROR;
import static com.mapswithme.util.statistics.Statistics.EventName.UGC_AUTH_EXTERNAL_REQUEST_SUCCESS;
import static com.mapswithme.util.statistics.Statistics.EventName.UGC_AUTH_SHOWN;
import static com.mapswithme.util.statistics.Statistics.EventName.UGC_REVIEW_START;
import static com.mapswithme.util.statistics.Statistics.EventParam.ACTION;
import static com.mapswithme.util.statistics.Statistics.EventParam.BANNER;
import static com.mapswithme.util.statistics.Statistics.EventParam.BATTERY;
import static com.mapswithme.util.statistics.Statistics.EventParam.BUTTON;
import static com.mapswithme.util.statistics.Statistics.EventParam.CATEGORY;
import static com.mapswithme.util.statistics.Statistics.EventParam.CHARGING;
import static com.mapswithme.util.statistics.Statistics.EventParam.COUNT_LOWERCASE;
import static com.mapswithme.util.statistics.Statistics.EventParam.DESTINATION;
import static com.mapswithme.util.statistics.Statistics.EventParam.ERROR;
import static com.mapswithme.util.statistics.Statistics.EventParam.ERROR_CODE;
import static com.mapswithme.util.statistics.Statistics.EventParam.ERROR_MESSAGE;
import static com.mapswithme.util.statistics.Statistics.EventParam.FEATURE_ID;
import static com.mapswithme.util.statistics.Statistics.EventParam.FROM;
import static com.mapswithme.util.statistics.Statistics.EventParam.HAS_AUTH;
import static com.mapswithme.util.statistics.Statistics.EventParam.HOTEL;
import static com.mapswithme.util.statistics.Statistics.EventParam.HOTEL_LAT;
import static com.mapswithme.util.statistics.Statistics.EventParam.HOTEL_LON;
import static com.mapswithme.util.statistics.Statistics.EventParam.INTERRUPTED;
import static com.mapswithme.util.statistics.Statistics.EventParam.ITEM;
import static com.mapswithme.util.statistics.Statistics.EventParam.MAP_DATA_SIZE;
import static com.mapswithme.util.statistics.Statistics.EventParam.METHOD;
import static com.mapswithme.util.statistics.Statistics.EventParam.MODE;
import static com.mapswithme.util.statistics.Statistics.EventParam.MWM_NAME;
import static com.mapswithme.util.statistics.Statistics.EventParam.MWM_VERSION;
import static com.mapswithme.util.statistics.Statistics.EventParam.NETWORK;
import static com.mapswithme.util.statistics.Statistics.EventParam.OBJECT_LAT;
import static com.mapswithme.util.statistics.Statistics.EventParam.OBJECT_LON;
import static com.mapswithme.util.statistics.Statistics.EventParam.OPTION;
import static com.mapswithme.util.statistics.Statistics.EventParam.PLACEMENT;
import static com.mapswithme.util.statistics.Statistics.EventParam.PRODUCT;
import static com.mapswithme.util.statistics.Statistics.EventParam.PROVIDER;
import static com.mapswithme.util.statistics.Statistics.EventParam.PURCHASE;
import static com.mapswithme.util.statistics.Statistics.EventParam.RESTAURANT;
import static com.mapswithme.util.statistics.Statistics.EventParam.RESTAURANT_LAT;
import static com.mapswithme.util.statistics.Statistics.EventParam.RESTAURANT_LON;
import static com.mapswithme.util.statistics.Statistics.EventParam.SERVER_ID;
import static com.mapswithme.util.statistics.Statistics.EventParam.SERVER_IDS;
import static com.mapswithme.util.statistics.Statistics.EventParam.STATE;
import static com.mapswithme.util.statistics.Statistics.EventParam.TYPE;
import static com.mapswithme.util.statistics.Statistics.EventParam.VALUE;
import static com.mapswithme.util.statistics.Statistics.EventParam.VENDOR;
import static com.mapswithme.util.statistics.Statistics.ParamValue.BACKUP;
import static com.mapswithme.util.statistics.Statistics.ParamValue.BICYCLE;
import static com.mapswithme.util.statistics.Statistics.ParamValue.BOOKING_COM;
import static com.mapswithme.util.statistics.Statistics.ParamValue.DISK_NO_SPACE;
import static com.mapswithme.util.statistics.Statistics.ParamValue.FACEBOOK;
import static com.mapswithme.util.statistics.Statistics.ParamValue.GOOGLE;
import static com.mapswithme.util.statistics.Statistics.ParamValue.HOLIDAY;
import static com.mapswithme.util.statistics.Statistics.ParamValue.MAPSME;
import static com.mapswithme.util.statistics.Statistics.ParamValue.NO_BACKUP;
import static com.mapswithme.util.statistics.Statistics.ParamValue.OFFSCREEEN;
import static com.mapswithme.util.statistics.Statistics.ParamValue.OPENTABLE;
import static com.mapswithme.util.statistics.Statistics.ParamValue.PEDESTRIAN;
import static com.mapswithme.util.statistics.Statistics.ParamValue.PHONE;
import static com.mapswithme.util.statistics.Statistics.ParamValue.RESTORE;
import static com.mapswithme.util.statistics.Statistics.ParamValue.SEARCH_BOOKING_COM;
import static com.mapswithme.util.statistics.Statistics.ParamValue.TAXI;
import static com.mapswithme.util.statistics.Statistics.ParamValue.TRAFFIC;
import static com.mapswithme.util.statistics.Statistics.ParamValue.TRANSIT;
import static com.mapswithme.util.statistics.Statistics.ParamValue.UNKNOWN;
import static com.mapswithme.util.statistics.Statistics.ParamValue.VEHICLE;
import static com.mapswithme.util.statistics.Statistics.ParamValue.MAPSME_GUIDES;
import static com.mapswithme.util.statistics.Statistics.ParamValue.PARTNER;

public enum Statistics
{
  INSTANCE;

  @NonNull
  public static ParameterBuilder makeInAppSuggestionParamBuilder()
  {
    return new ParameterBuilder()
        .add(EventParam.SCENARIO, BOOKING_COM)
        .add(PROVIDER, MAPSME_GUIDES);
  }

  @NonNull
  public static ParameterBuilder makeDownloaderBannerParamBuilder(@NonNull String provider)
  {
    return new ParameterBuilder()
            .add(EventParam.FROM, ParamValue.MAP)
            .add(PROVIDER, provider);
  }

  @NonNull
  public static ParameterBuilder makeGuidesSubscriptionBuilder()
  {
    return new ParameterBuilder().add(EventParam.TARGET,
                                      ParamValue.GUIDES_SUBSCRIPTION);
  }

  public void trackCategoryDescChanged()
  {
    trackEditSettingsScreenOptionClick(ParamValue.ADD_DESC);
  }

  public void trackSharingOptionsClick(@NonNull String value)
  {
    ParameterBuilder builder = new ParameterBuilder().add(OPTION, value);
    trackEvent(EventName.BM_SHARING_OPTIONS_CLICK, builder);
  }

  public void trackSharingOptionsError(@NonNull String error,
                                              @NonNull NetworkErrorType value)
  {
    trackSharingOptionsError(error, value.ordinal());
  }

  public void trackSharingOptionsError(@NonNull String error, int value)
  {
    ParameterBuilder builder = new ParameterBuilder().add(EventParam.ERROR, value);
    trackEvent(error, builder);
  }

  public void trackSharingOptionsUploadSuccess(@NonNull BookmarkCategory category)
  {
    ParameterBuilder builder = new ParameterBuilder().add(EventParam.TRACKS, category.getTracksCount())
                                                     .add(EventParam.POINTS, category.getBookmarksCount());
    trackEvent(EventName.BM_SHARING_OPTIONS_UPLOAD_SUCCESS, builder);
  }

  public void trackBookmarkListSettingsClick(@NonNull Analytics analytics)
  {
    ParameterBuilder builder = ParameterBuilder.from(OPTION, analytics);
    trackEvent(EventName.BM_BOOKMARKS_LIST_SETTINGS_CLICK, builder);
  }

  @NonNull
  private static String getStatisticsSortingType(@BookmarkManager.SortingType int sortingType)
  {
    switch (sortingType)
    {
      case BookmarkManager.SORT_BY_TYPE:
        return Statistics.ParamValue.BY_TYPE;
      case BookmarkManager.SORT_BY_DISTANCE:
        return Statistics.ParamValue.BY_DISTANCE;
      case BookmarkManager.SORT_BY_TIME:
        return Statistics.ParamValue.BY_DATE;
    }
    throw new AssertionError("Invalid sorting type");
  }

  public void trackBookmarksListSort(@BookmarkManager.SortingType int sortingType)
  {
    trackBookmarksListSort(getStatisticsSortingType(sortingType));
  }

  public void trackBookmarksListResetSort()
  {
    trackBookmarksListSort(Statistics.ParamValue.BY_DEFAULT);
  }

  private void trackBookmarksListSort(@NonNull String value)
  {
    ParameterBuilder builder = new ParameterBuilder().add(EventParam.OPTION, value);
    trackEvent(EventName.BM_BOOKMARKS_LIST_SORT, builder);
  }

  public void trackBookmarksListSearch()
  {
    trackBookmarksSearch(ParamValue.BOOKMARKS_LIST);
  }

  private void trackBookmarksSearch(@NonNull String value)
  {
    ParameterBuilder builder = new ParameterBuilder().add(EventParam.FROM, value);
    trackEvent(EventName.BM_BOOKMARKS_SEARCH, builder);
  }

  public void trackBookmarksListSearchResultSelected()
  {
    trackBookmarksSearchResultSelected(ParamValue.BOOKMARKS_LIST);
  }

  private void trackBookmarksSearchResultSelected(@NonNull String value)
  {
    ParameterBuilder builder = new ParameterBuilder().add(EventParam.FROM, value);
    trackEvent(EventName.BM_BOOKMARKS_SEARCH_RESULT_SELECTED, builder);
  }

  private void trackEditSettingsScreenOptionClick(@NonNull String value)
  {
    ParameterBuilder builder = new ParameterBuilder().add(OPTION, value);
    trackEvent(EventName.BM_EDIT_SETTINGS_CLICK, builder);
  }

  public void trackEditSettingsCancel()
  {
    trackEvent(EventName.BM_EDIT_SETTINGS_CANCEL);
  }

  public void trackEditSettingsConfirm()
  {
    trackEvent(EventName.BM_EDIT_SETTINGS_CONFIRM);
  }

  public void trackEditSettingsSharingOptionsClick()
  {
    trackEditSettingsScreenOptionClick(Statistics.ParamValue.SHARING_OPTIONS);
  }

  public void trackBookmarkListSharingOptions()
  {
    trackEvent(Statistics.EventName.BM_BOOKMARKS_LIST_ITEM_SETTINGS,
               new Statistics.ParameterBuilder().add(OPTION,
                                                     Statistics.ParamValue.SHARING_OPTIONS));
  }

  public void trackSettingsDrivingOptionsChangeEvent(@NonNull String componentDescent)
  {
    boolean hasToll = RoutingOptions.hasOption(RoadType.Toll);
    boolean hasFerry = RoutingOptions.hasOption(RoadType.Ferry);
    boolean hasMoto = RoutingOptions.hasOption(RoadType.Motorway);
    boolean hasDirty = RoutingOptions.hasOption(RoadType.Dirty);

    ParameterBuilder builder = new ParameterBuilder() ;
    ParameterBuilder parameterBuilder = builder.add(EventParam.TOLL, hasToll ? 1 : 0)
                                               .add(EventParam.FERRY, hasFerry ? 1 : 0)
                                               .add(EventParam.MOTORWAY, hasMoto ? 1 : 0)
                                               .add(EventParam.UNPAVED, hasDirty ? 1 : 0);
    parameterBuilder.add(EventParam.FROM, componentDescent);

    trackEvent(EventName.SETTINGS_DRIVING_OPTIONS_CHANGE, parameterBuilder);
  }

  @Retention(RetentionPolicy.SOURCE)
  @IntDef({PP_BANNER_STATE_PREVIEW, PP_BANNER_STATE_DETAILS})
  public @interface BannerState {}

  public static final int PP_BANNER_STATE_PREVIEW = 0;
  public static final int PP_BANNER_STATE_DETAILS = 1;

  @Retention(RetentionPolicy.SOURCE)
  @IntDef({ STATISTICS_CHANNEL_DEFAULT, STATISTICS_CHANNEL_REALTIME })
  public @interface StatisticsChannel {}

  public static final int STATISTICS_CHANNEL_DEFAULT = org.alohalytics.Statistics.ONLY_CHANNEL;
  private static final int REALTIME_CHANNEL_INDEX = 1;
  public static final int STATISTICS_CHANNEL_REALTIME =  STATISTICS_CHANNEL_DEFAULT | (1 << REALTIME_CHANNEL_INDEX);

  // Statistics counters
  private int mBookmarksCreated;
  private int mSharedTimes;

  public static class EventName
  {
    // Downloader
    public static final String DOWNLOADER_ERROR = "Downloader_Map_error";
    public static final String DOWNLOADER_ACTION = "Downloader_Map_action";
    public static final String DOWNLOADER_CANCEL = "Downloader_Cancel_downloading";
    public static final String DOWNLOADER_DIALOG_SHOW = "Downloader_OnStartScreen_show";
    public static final String DOWNLOADER_DIALOG_MANUAL_DOWNLOAD = "Downloader_OnStartScreen_manual_download";
    public static final String DOWNLOADER_DIALOG_DOWNLOAD = "Downloader_OnStartScreen_auto_download";
    public static final String DOWNLOADER_DIALOG_LATER = "Downloader_OnStartScreen_select_later";
    public static final String DOWNLOADER_DIALOG_HIDE = "Downloader_OnStartScreen_select_hide";
    public static final String DOWNLOADER_DIALOG_CANCEL = "Downloader_OnStartScreen_cancel_download";

    public static final String SETTINGS_TRACKING_DETAILS = "Settings_Tracking_details";
    public static final String SETTINGS_TRACKING_TOGGLE = "Settings_Tracking_toggle";
    public static final String PLACEPAGE_DESCRIPTION_MORE = "Placepage_Description_more";
    public static final String PLACEPAGE_DESCRIPTION_OUTBOUND_CLICK = "Placepage_Description_Outbound_click";
    public static final String SETTINGS_SPEED_CAMS = "Settings. Speed_cameras";
    public static final String SETTINGS_MOBILE_INTERNET_CHANGE = "Settings_MobileInternet_change";
    public static final String SETTINGS_RECENT_TRACK_CHANGE = "Settings_RecentTrack_change";
    public static final String MOBILE_INTERNET_ALERT = "MobileInternet_alert";

    public static final String DOWNLOADER_BANNER_SHOW = "Downloader_Banner_show";
    public static final String DOWNLOADER_BANNER_CLICK = "Downloader_Banner_click";
    static final String DOWNLOADER_DIALOG_ERROR = "Downloader_OnStartScreen_error";

    // bookmarks
    private static final String BM_SHARING_OPTIONS_UPLOAD_SUCCESS = "Bookmarks_SharingOptions_upload_success";
    public static final String BM_SHARING_OPTIONS_UPLOAD_ERROR = "Bookmarks_SharingOptions_upload_error";
    public static final String BM_SHARING_OPTIONS_ERROR = "Bookmarks_SharingOptions_error";
    public static final String BM_SHARING_OPTIONS_CLICK = "Bookmarks_SharingOptions_click";
    public static final String BM_EDIT_SETTINGS_CLICK = "Bookmarks_Bookmark_Settings_click";
    public static final String BM_EDIT_SETTINGS_CANCEL = "Bookmarks_Bookmark_Settings_cancel";
    public static final String BM_EDIT_SETTINGS_CONFIRM = "Bookmarks_Bookmark_Settings_confirm";
    public static final String BM_BOOKMARKS_LIST_SETTINGS_CLICK = "Bookmarks_BookmarksList_settings_click";
    public static final String BM_BOOKMARKS_LIST_ITEM_SETTINGS = "Bookmarks_BookmarksListItem_settings";
    public static final String BM_BOOKMARKS_LIST_SORT = "Bookmarks_BookmarksList_sort";
    public static final String BM_BOOKMARKS_SEARCH = "Bookmarks_Search";
    public static final String BM_BOOKMARKS_SEARCH_RESULT_SELECTED = "Bookmarks_Search_result_selected";
    public static final String BM_GROUP_CREATED = "Bookmark. Group created";
    public static final String BM_GROUP_CHANGED = "Bookmark. Group changed";
    public static final String BM_COLOR_CHANGED = "Bookmark. Color changed";
    public static final String BM_CREATED = "Bookmark. Bookmark created";
    public static final String BM_SYNC_PROPOSAL_SHOWN = "Bookmarks_SyncProposal_shown";
    public static final String BM_SYNC_PROPOSAL_APPROVED = "Bookmarks_SyncProposal_approved";
    public static final String BM_SYNC_PROPOSAL_ERROR = "Bookmarks_SyncProposal_error";
    public static final String BM_SYNC_PROPOSAL_ENABLED = "Bookmarks_SyncProposal_enabled";
    public static final String BM_SYNC_PROPOSAL_TOGGLE = "Settings_BookmarksSync_toggle";
    public static final String BM_SYNC_STARTED = "Bookmarks_sync_started";
    public static final String BM_SYNC_ERROR = "Bookmarks_sync_error";
    public static final String BM_SYNC_SUCCESS = "Bookmarks_sync_success";
    public static final String BM_EDIT_ON_WEB_CLICK = "Bookmarks_EditOnWeb_click";
    static final String BM_RESTORE_PROPOSAL_CLICK = "Bookmarks_RestoreProposal_click";
    public static final String BM_RESTORE_PROPOSAL_CANCEL = "Bookmarks_RestoreProposal_cancel";
    public static final String BM_RESTORE_PROPOSAL_SUCCESS = "Bookmarks_RestoreProposal_success";
    static final String BM_RESTORE_PROPOSAL_ERROR = "Bookmarks_RestoreProposal_error";
    static final String BM_TAB_CLICK = "Bookmarks_Tab_click";
    private static final String BM_DOWNLOADED_CATALOGUE_OPEN = "Bookmarks_Downloaded_Catalogue_open";
    private static final String BM_DOWNLOADED_CATALOGUE_ERROR = "Bookmarks_Downloaded_Catalogue_error";
    public static final String BM_GUIDEDOWNLOADTOAST_SHOWN = "Bookmarks_GuideDownloadToast_shown";
    public static final String BM_GUIDES_DOWNLOADDIALOGUE_CLICK = "Bookmarks_Guides_DownloadDialogue_click";
    public static final String SETTINGS_DRIVING_OPTIONS_CHANGE = "Settings_Navigation_DrivingOptions_change";
    public static final String PP_DRIVING_OPTIONS_ACTION = "Placepage_DrivingOptions_action";

    // search
    public static final String SEARCH_CAT_CLICKED = "Search. Category clicked";
    public static final String SEARCH_ITEM_CLICKED = "Search. Key clicked";
    public static final String SEARCH_ON_MAP_CLICKED = "Search. View on map clicked.";
    public static final String SEARCH_TAB_SELECTED = "Search_Tab_selected";
    public static final String SEARCH_SPONSOR_CATEGORY_SHOWN = "Search_SponsoredCategory_shown";
    public static final String SEARCH_SPONSOR_CATEGORY_SELECTED = "Search_SponsoredCategory_selected";
    public static final String SEARCH_FILTER_OPEN = "Search_Filter_Open";
    public static final String SEARCH_FILTER_CANCEL = "Search_Filter_Cancel";
    public static final String SEARCH_FILTER_RESET = "Search_Filter_Reset";
    public static final String SEARCH_FILTER_APPLY = "Search_Filter_Apply";
    public static final String SEARCH_FILTER_CLICK = "Search_Filter_Click";

    // place page
    public static final String PP_DETAILS_OPEN = "Placepage_Details_open";
    public static final String PP_SHARE = "PP. Share";
    public static final String PP_BOOKMARK = "PP. Bookmark";
    public static final String PP_ROUTE = "PP. Route";
    public static final String PP_SPONSORED_DETAILS = "Placepage_Hotel_details";
    public static final String PP_SPONSORED_BOOK = "Placepage_Hotel_book";
    public static final String PP_SPONSORED_OPENTABLE = "Placepage_Restaurant_book";
    public static final String PP_SPONSORED_OPEN = "Placepage_SponsoredGalleryPage_opened";
    public static final String PP_SPONSORED_SHOWN = "Placepage_SponsoredGallery_shown";
    public static final String PP_SPONSORED_ERROR = "Placepage_SponsoredGallery_error";
    public static final String PP_SPONSORED_ACTION = "Placepage_SponsoredActionButton_click";
    public static final String PP_SPONSOR_ITEM_SELECTED = "Placepage_SponsoredGallery_ProductItem_selected";
    public static final String PP_SPONSOR_MORE_SELECTED = "Placepage_SponsoredGallery_MoreItem_selected";
    public static final String PP_SPONSOR_LOGO_SELECTED = "Placepage_SponsoredGallery_LogoItem_selected";
    public static final String PP_DIRECTION_ARROW = "PP. DirectionArrow";
    public static final String PP_DIRECTION_ARROW_CLOSE = "PP. DirectionArrowClose";
    public static final String PP_METADATA_COPY = "PP. CopyMetadata";
    public static final String PP_BANNER_CLICK = "Placepage_Banner_click";
    public static final String PP_BANNER_SHOW = "Placepage_Banner_show";
    public static final String PP_BANNER_ERROR = "Placepage_Banner_error";
    public static final String PP_BANNER_BLANK = "Placepage_Banner_blank";
    public static final String PP_BANNER_CLOSE = "Placepage_Banner_close";
    public static final String PP_HOTEL_GALLERY_OPEN = "PlacePage_Hotel_Gallery_open";
    public static final String PP_HOTEL_REVIEWS_LAND = "PlacePage_Hotel_Reviews_land";
    public static final String PP_HOTEL_DESCRIPTION_LAND = "PlacePage_Hotel_Description_land";
    public static final String PP_HOTEL_FACILITIES = "PlacePage_Hotel_Facilities_open";
    public static final String PP_HOTEL_SEARCH_SIMILAR = "Placepage_Hotel_search_similar";
    static final String PP_OWNERSHIP_BUTTON_CLICK = "Placepage_OwnershipButton_click";

    // toolbar actions
    public static final String TOOLBAR_MY_POSITION = "Toolbar. MyPosition";
    static final String TOOLBAR_CLICK = "Toolbar_click";
    static final String TOOLBAR_MENU_CLICK = "Toolbar_Menu_click";

    // dialogs
    public static final String PLUS_DIALOG_LATER = "GPlus dialog cancelled.";
    public static final String RATE_DIALOG_LATER = "GPlay dialog cancelled.";
    public static final String FACEBOOK_INVITE_LATER = "Facebook invites dialog cancelled.";
    public static final String FACEBOOK_INVITE_INVITED = "Facebook invites dialog accepted.";
    public static final String RATE_DIALOG_RATED = "GPlay dialog. Rating set";

    // misc
    public static final String ZOOM_IN = "Zoom. In";
    public static final String ZOOM_OUT = "Zoom. Out";
    public static final String PLACE_SHARED = "Place Shared";
    public static final String API_CALLED = "API called";
    public static final String DOWNLOAD_COUNTRY_NOTIFICATION_SHOWN = "Download country notification shown";
    public static final String ACTIVE_CONNECTION = "Connection";
    public static final String STATISTICS_STATUS_CHANGED = "Statistics status changed";
    public static final String TTS_FAILURE_LOCATION = "TTS failure location";
    public static final String UGC_NOT_AUTH_NOTIFICATION_SHOWN = "UGC_UnsentNotification_shown";
    public static final String UGC_NOT_AUTH_NOTIFICATION_CLICKED = "UGC_UnsentNotification_clicked";
    public static final String UGC_REVIEW_NOTIFICATION_SHOWN = "UGC_ReviewNotification_shown";
    public static final String UGC_REVIEW_NOTIFICATION_CLICKED = "UGC_ReviewNotification_clicked";

    // routing
    public static final String ROUTING_BUILD = "Routing. Build";
    public static final String ROUTING_START_SUGGEST_REBUILD = "Routing. Suggest rebuild";
    public static final String ROUTING_ROUTE_START = "Routing_Route_start";
    public static final String ROUTING_ROUTE_FINISH = "Routing_Route_finish";
    public static final String ROUTING_CANCEL = "Routing. Cancel";
    public static final String ROUTING_VEHICLE_SET = "Routing. Set vehicle";
    public static final String ROUTING_PEDESTRIAN_SET = "Routing. Set pedestrian";
    public static final String ROUTING_BICYCLE_SET = "Routing. Set bicycle";
    public static final String ROUTING_TAXI_SET = "Routing. Set taxi";
    public static final String ROUTING_TRANSIT_SET = "Routing. Set transit";
    public static final String ROUTING_SWAP_POINTS = "Routing. Swap points";
    public static final String ROUTING_SETTINGS = "Routing. Settings";
    public static final String ROUTING_TAXI_ORDER = "Routing_Taxi_order";
    public static final String ROUTING_TAXI_INSTALL = "Routing_Taxi_install";
    public static final String ROUTING_TAXI_SHOW = "Placepage_Taxi_show";
    public static final String ROUTING_TAXI_CLICK_IN_PP = "Placepage_Taxi_click";
    public static final String ROUTING_TAXI_ROUTE_BUILT = "Routing_Build_Taxi";
    public static final String ROUTING_POINT_ADD = "Routing_Point_add";
    public static final String ROUTING_POINT_REMOVE = "Routing_Point_remove";
    public static final String ROUTING_SEARCH_CLICK = "Routing_Search_click";
    public static final String ROUTING_BOOKMARKS_CLICK = "Routing_Bookmarks_click";
    public static final String ROUTING_PLAN_TOOLTIP_CLICK = "Routing_PlanTooltip_click";

    // editor
    public static final String EDITOR_START_CREATE = "Editor_Add_start";
    public static final String EDITOR_ADD_CLICK = "Editor_Add_click";
    public static final String EDITOR_START_EDIT = "Editor_Edit_start";
    public static final String EDITOR_SUCCESS_CREATE = "Editor_Add_success";
    public static final String EDITOR_SUCCESS_EDIT = "Editor_Edit_success";
    public static final String EDITOR_ERROR_CREATE = "Editor_Add_error";
    public static final String EDITOR_ERROR_EDIT = "Editor_Edit_error";
    public static final String EDITOR_AUTH_DECLINED = "Editor_Auth_declined_by_user";
    public static final String EDITOR_AUTH_REQUEST = "Editor_Auth_request";
    public static final String EDITOR_AUTH_REQUEST_RESULT = "Editor_Auth_request_result";
    public static final String EDITOR_REG_REQUEST = "Editor_Reg_request";
    public static final String EDITOR_LOST_PASSWORD = "Editor_Lost_password";
    public static final String EDITOR_SHARE_SHOW = "Editor_SecondTimeShare_show";
    public static final String EDITOR_SHARE_CLICK = "Editor_SecondTimeShare_click";

    // Cold start
    public static final String APPLICATION_COLD_STARTUP_INFO = "Application_ColdStartup_info";

    // Ugc.
    public static final String UGC_REVIEW_START = "UGC_Review_start";
    public static final String UGC_REVIEW_CANCEL = "UGC_Review_cancel";
    public static final String UGC_REVIEW_SUCCESS = "UGC_Review_success";
    public static final String UGC_AUTH_SHOWN = "UGC_Auth_shown";
    public static final String UGC_AUTH_DECLINED = "UGC_Auth_declined";
    public static final String UGC_AUTH_EXTERNAL_REQUEST_SUCCESS = "UGC_Auth_external_request_success";
    public static final String UGC_AUTH_ERROR = "UGC_Auth_error";
    public static final String MAP_LAYERS_ACTIVATE = "Map_Layers_activate";

    // Purchases.
    static final String INAPP_PURCHASE_PREVIEW_SHOW = "InAppPurchase_Preview_show";
    static final String INAPP_PURCHASE_PREVIEW_SELECT = "InAppPurchase_Preview_select";
    public static final String INAPP_PURCHASE_PREVIEW_PAY = "InAppPurchase_Preview_pay";
    public static final String INAPP_PURCHASE_PREVIEW_CANCEL = "InAppPurchase_Preview_cancel";
    public static final String INAPP_PURCHASE_PREVIEW_RESTORE = "InAppPurchase_Preview_restore";

    public static final String INAPP_PURCHASE_STORE_SUCCESS  = "InAppPurchase_Store_success";
    static final String INAPP_PURCHASE_STORE_ERROR  = "InAppPurchase_Store_error";
    public static final String INAPP_PURCHASE_VALIDATION_SUCCESS  = "InAppPurchase_Validation_success";
    static final String INAPP_PURCHASE_VALIDATION_ERROR  = "InAppPurchase_Validation_error";
    static final String INAPP_PURCHASE_PRODUCT_DELIVERED  = "InAppPurchase_Product_delivered";

    public static final String ONBOARDING_DEEPLINK_SCREEN_SHOW = "OnboardingDeeplinkScreen_show";
    public static final String ONBOARDING_DEEPLINK_SCREEN_ACCEPT = "OnboardingDeeplinkScreen_accept";
    public static final String ONBOARDING_DEEPLINK_SCREEN_DECLINE = "OnboardingDeeplinkScreen_decline";

    public static final String TIPS_TRICKS_SHOW = "TipsTricks_show";
    public static final String TIPS_TRICKS_CLOSE = "TipsTricks_close";
    public static final String TIPS_TRICKS_CLICK = "TipsTricks_click";

    public static final String INAPP_SUGGESTION_SHOWN = "MapsMe_InAppSuggestion_shown";
    public static final String INAPP_SUGGESTION_CLICKED = "MapsMe_InAppSuggestion_clicked";
    public static final String INAPP_SUGGESTION_CLOSED = "MapsMe_InAppSuggestion_closed";

    public static final String GUIDES_SHOWN = "Bookmarks_Downloaded_Guides_list";
    public static final String GUIDES_OPEN = "Bookmarks_Downloaded_Guide_open";
    public static final String GUIDES_BOOKMARK_SELECT = "Bookmarks_BookmarksList_Bookmark_select";
    public static final String GUIDES_TRACK_SELECT = "Bookmarks_BookmarksList_Track_select";
    public static final String MAP_SPONSORED_BUTTON_CLICK = "Map_SponsoredButton_click";
    public static final String MAP_SPONSORED_BUTTON_SHOW = "Map_SponsoredButton_show";

    public static class Settings
    {
      public static final String WEB_SITE = "Setings. Go to website";
      public static final String FEEDBACK_GENERAL = "Send general feedback to android@maps.me";
      public static final String REPORT_BUG = "Settings. Bug reported";
      public static final String RATE = "Settings. Rate app called";
      public static final String TELL_FRIEND = "Settings. Tell to friend";
      public static final String FACEBOOK = "Settings. Go to FB.";
      public static final String TWITTER = "Settings. Go to twitter.";
      public static final String HELP = "Settings. Help.";
      public static final String ABOUT = "Settings. About.";
      public static final String OSM_PROFILE = "Settings. Profile.";
      public static final String COPYRIGHT = "Settings. Copyright.";
      public static final String UNITS = "Settings. Change units.";
      public static final String ZOOM = "Settings. Switch zoom.";
      public static final String MAP_STYLE = "Settings. Map style.";
      public static final String VOICE_ENABLED = "Settings. Switch voice.";
      public static final String VOICE_LANGUAGE = "Settings. Voice language.";
      public static final String ENERGY_SAVING = "Settings_EnergySaving_change";

      private Settings() {}
    }

    private EventName() {}
  }

  public static class EventParam
  {
    public static final String FROM = "from";
    public static final String TO = "to";
    public static final String OPTION = "option";
    public static final String TRACKS = "tracks";
    public static final String POINTS = "points";
    public static final String URL = "url";
    public static final String TOLL = "toll";
    public static final String UNPAVED = "unpaved";
    public static final String FERRY = "ferry";
    public static final String MOTORWAY = "motorway";
    public static final String SETTINGS = "settings";
    public static final String ROUTE = "route";
    public static final String SCENARIO = "scenario";
    static final String TARGET = "target";
    static final String CATEGORY = "category";
    public static final String TAB = "tab";
    static final String COUNT = "Count";
    static final String COUNT_LOWERCASE = "count";
    static final String CHANNEL = "Channel";
    static final String CALLER_ID = "Caller ID";
    public static final String ENABLED = "Enabled";
    public static final String RATING = "Rating";
    static final String CONNECTION_TYPE = "Connection name";
    static final String CONNECTION_FAST = "Connection fast";
    static final String CONNECTION_METERED = "Connection limit";
    static final String MY_POSITION = "my position";
    static final String POINT = "point";
    public static final String LANGUAGE = "language";
    public static final String NAME = "Name";
    public static final String ACTION = "action";
    public static final String TYPE = "type";
    static final String IS_AUTHENTICATED = "is_authenticated";
    static final String IS_ONLINE = "is_online";
    public static final String IS_SUCCESS = "is_success_message";
    static final String FEATURE_ID = "feature_id";
    static final String MWM_NAME = "mwm_name";
    static final String MWM_VERSION = "mwm_version";
    public static final String ERR_MSG = "error_message";
    public static final String OSM = "OSM";
    public static final String FACEBOOK = "Facebook";
    public static final String PROVIDER = "provider";
    public static final String HOTEL = "hotel";
    static final String HOTEL_LAT = "hotel_lat";
    static final String HOTEL_LON = "hotel_lon";
    static final String RESTAURANT = "restaurant";
    static final String RESTAURANT_LAT = "restaurant_lat";
    static final String RESTAURANT_LON = "restaurant_lon";
    static final String FROM_LAT = "from_lat";
    static final String FROM_LON = "from_lon";
    static final String TO_LAT = "to_lat";
    static final String TO_LON = "to_lon";
    static final String BANNER = "banner";
    static final String STATE = "state";
    static final String ERROR_CODE = "error_code";
    public static final String ERROR = "error";
    static final String ERROR_MESSAGE = "error_message";
    static final String MAP_DATA_SIZE = "map_data_size:";
    static final String BATTERY = "battery";
    static final String CHARGING = "charging";
    static final String NETWORK = "network";
    public static final String VALUE = "value";
    static final String METHOD = "method";
    static final String MODE = "mode";
    static final String OBJECT_LAT = "object_lat";
    static final String OBJECT_LON = "object_lon";
    static final String ITEM = "item";
    static final String DESTINATION = "destination";
    static final String PLACEMENT = "placement";
    public static final String PRICE_CATEGORY = "price_category";
    public static final String DATE = "date";
    static final String HAS_AUTH = "has_auth";
    public static final String STATUS = "status";
    static final String INTERRUPTED = "interrupted";
    static final String BUTTON = "button";
    static final String VENDOR = "vendor";
    static final String PRODUCT = "product";
    static final String PURCHASE = "purchase";
    static final String SERVER_ID = "server_id";
    static final String SERVER_IDS = "server_ids";
    public static final String SOURCE = "source";

    private EventParam() {}
  }

  public static class ParamValue
  {
    public static final String BOOKING_COM = "Booking.Com";
    public static final String OSM = "OSM";
    public static final String ON = "on";
    public static final String OFF = "off";
    public static final String CRASH_REPORTS = "crash_reports";
    public static final String PERSONAL_ADS = "personal_ads";
    public static final String SHARING_OPTIONS = "sharing_options";
    public static final String EDIT_ON_WEB = "edit_on_web";
    public static final String PUBLIC = "public";
    public static final String PRIVATE = "private";
    public static final String COPY_LINK = "copy_link";
    public static final String CANCEL = "Cancel";
    public static final String MEGAFON = "Megafon";
    public static final String MAP = "map";
    public static final String ALWAYS = "always";
    public static final String NEVER = "never";
    public static final String ASK = "ask";
    public static final String TODAY = "today";
    public static final String NOT_TODAY = "not_today";
    public static final String CARD = "card";
    public static final String SPONSORED_BUTTON = "sponsored_button";
    public static final String POPUP = "popup";
    public static final String WEBVIEW = "webview";
    static final String GUIDES_SUBSCRIPTION = "GuidesSubscription";
    static final String SEARCH_BOOKING_COM = "Search.Booking.Com";
    static final String OPENTABLE = "OpenTable";
    static final String LOCALS_EXPERTS = "Locals.Maps.Me";
    static final String SEARCH_RESTAURANTS = "Search.Restaurants";
    static final String SEARCH_ATTRACTIONS = "Search.Attractions";
    static final String HOLIDAY = "Holiday";
    public static final String NO_PRODUCTS = "no_products";
    static final String ADD = "add";
    public static final String EDIT = "edit";
    static final String AFTER_SAVE = "after_save";
    static final String PLACEPAGE_PREVIEW = "placepage_preview";
    static final String PLACEPAGE = "placepage";
    static final String NOTIFICATION = "notification";
    public static final String FACEBOOK = "facebook";
    public static final String CHECKIN = "check_in";
    public static final String CHECKOUT = "check_out";
    public static final String ANY = "any";
    public static final String GOOGLE = "google";
    public static final String MAPSME = "mapsme";
    public static final String PHONE = "phone";
    public static final String UNKNOWN = "unknown";
    static final String NETWORK = "network";
    static final String DISK = "disk";
    static final String AUTH = "auth";
    static final String USER_INTERRUPTED = "user_interrupted";
    static final String INVALID_CALL = "invalid_call";
    static final String NO_BACKUP = "no_backup";
    static final String DISK_NO_SPACE = "disk_no_space";
    static final String BACKUP = "backup";
    static final String RESTORE = "restore";
    public static final String NO_INTERNET = "no_internet";
    public static final String MY = "my";
    public static final String DOWNLOADED = "downloaded";
    static final String SUBWAY = "subway";
    static final String TRAFFIC = "traffic";
    public static final String SUCCESS = "success";
    public static final String UNAVAILABLE = "unavailable";
    static final String PEDESTRIAN = "pedestrian";
    static final String VEHICLE = "vehicle";
    static final String BICYCLE = "bicycle";
    static final String TAXI = "taxi";
    static final String TRANSIT = "transit";
    public final static String VIEW_ON_MAP = "view on map";
    public final static String NOT_NOW = "not now";
    public final static String CLICK_OUTSIDE = "click outside pop-up";
    public static final String ADD_DESC = "add_description";
    public static final String SEND_AS_FILE = "send_as_file";
    public static final String MAKE_INVISIBLE_ON_MAP = "make_invisible_on_map";
    public static final String LIST_SETTINGS = "list_settings";
    public static final String DELETE_GROUP = "delete_group";
    public static final String OFFSCREEEN = "Offscreen";
    public static final String MAPSME_GUIDES = "MapsMeGuides";
    public static final String BY_DEFAULT = "Default";
    public static final String BY_DATE = "Date";
    public static final String BY_DISTANCE = "Distance";
    public static final String BY_TYPE = "Type";
    public static final String BOOKMARKS_LIST = "BookmarksList";
    static final String PARTNER = "Partner";
    public static final String WIKIPEDIA = "wikipedia";
  }

  // Initialized once in constructor and does not change until the process restarts.
  // In this way we can correctly finish all statistics sessions and completely
  // avoid their initialization if user has disabled statistics collection.
  private final boolean mEnabled;

  Statistics()
  {
    mEnabled = SharedPropertiesUtils.isStatisticsEnabled();
    final Context context = MwmApplication.get();
    // At the moment we need special handling for Alohalytics to enable/disable logging of events in core C++ code.
    if (mEnabled)
      org.alohalytics.Statistics.enable(context);
    else
      org.alohalytics.Statistics.disable(context);
    configure(context);
  }

  @SuppressWarnings("NullableProblems")
  @NonNull
  private ExternalLibrariesMediator mMediator;

  public void setMediator(@NonNull ExternalLibrariesMediator mediator)
  {
    mMediator = mediator;
  }

  private void configure(Context context)
  {
    // At the moment, need to always initialize engine for correct JNI http part reusing.
    // Statistics is still enabled/disabled separately and never sent anywhere if turned off.
    // TODO (AlexZ): Remove this initialization dependency from JNI part.
    org.alohalytics.Statistics.setDebugMode(BuildConfig.DEBUG);
    org.alohalytics.Statistics.setup(new String[] { PrivateVariables.alohalyticsUrl(),
        PrivateVariables.alohalyticsRealtimeUrl()}, context);
  }

  public void trackEvent(@NonNull String name)
  {
    trackEvent(name, STATISTICS_CHANNEL_DEFAULT);
  }

  public void trackEvent(@NonNull String name, @StatisticsChannel int channel)
  {
    if (mEnabled)
      org.alohalytics.Statistics.logEvent(name, channel);
    mMediator.getEventLogger().logEvent(name, Collections.emptyMap());
  }

  public void trackEvent(@NonNull String name, @NonNull Map<String, String> params)
  {
    trackEvent(name, params, STATISTICS_CHANNEL_DEFAULT);
  }

  public void trackEvent(@NonNull String name, @NonNull Map<String, String> params,
                         @StatisticsChannel int channel)
  {
    if (mEnabled)
      org.alohalytics.Statistics.logEvent(name, params, channel);

    mMediator.getEventLogger().logEvent(name, params);
  }

  public void trackEvent(@NonNull String name, @Nullable Location location,
                         @NonNull Map<String, String> params)
  {
    trackEvent(name, location, params, STATISTICS_CHANNEL_DEFAULT);
  }

  public void trackEvent(@NonNull String name, @Nullable Location location,
                         @NonNull Map<String, String> params, @StatisticsChannel int channel)
  {
    List<String> eventDictionary = new ArrayList<String>();
    for (Map.Entry<String, String> entry : params.entrySet())
    {
      eventDictionary.add(entry.getKey());
      eventDictionary.add(entry.getValue());
    }
    params.put("lat", (location == null ? "N/A" : String.valueOf(location.getLatitude())));
    params.put("lon", (location == null ? "N/A" : String.valueOf(location.getLongitude())));

    if (mEnabled)
      org.alohalytics.Statistics.logEvent(name, eventDictionary.toArray(new String[0]), location, channel);

    mMediator.getEventLogger().logEvent(name, params);
  }

  public void trackEvent(@NonNull String name, @NonNull ParameterBuilder builder)
  {
    trackEvent(name, builder.get(), STATISTICS_CHANNEL_DEFAULT);
  }

  public void trackEvent(@NonNull String name, @NonNull ParameterBuilder builder,
                         @StatisticsChannel int channel)
  {
    trackEvent(name, builder.get(), channel);
  }

  public void startActivity(Activity activity)
  {
    if (mEnabled)
    {
      AppEventsLogger.activateApp(activity);
      org.alohalytics.Statistics.onStart(activity);
    }

    mMediator.getEventLogger().startActivity(activity);
  }

  public void stopActivity(Activity activity)
  {
    if (mEnabled)
    {
      AppEventsLogger.deactivateApp(activity);
      org.alohalytics.Statistics.onStop(activity);
    }
    mMediator.getEventLogger().stopActivity(activity);
  }

  public void setStatEnabled(boolean isEnabled)
  {
    SharedPropertiesUtils.setStatisticsEnabled(isEnabled);
    Config.setStatisticsEnabled(isEnabled);

    // We track if user turned on/off statistics to understand data better.
    trackEvent(EventName.STATISTICS_STATUS_CHANGED + " " + Counters.getInstallFlavor(),
               params().add(EventParam.ENABLED, String.valueOf(isEnabled)));
  }

  public void trackSearchTabSelected(@NonNull String tab)
  {
    trackEvent(EventName.SEARCH_TAB_SELECTED, params().add(EventParam.TAB, tab));
  }

  public void trackSearchCategoryClicked(String category)
  {
    trackEvent(EventName.SEARCH_CAT_CLICKED, params().add(EventParam.CATEGORY, category));
  }

  public void trackColorChanged(String from, String to)
  {
    trackEvent(EventName.BM_COLOR_CHANGED, params().add(EventParam.FROM, from)
                                                   .add(EventParam.TO, to));
  }

  public void trackBookmarkCreated()
  {
    trackEvent(EventName.BM_CREATED, params().add(EventParam.COUNT, String.valueOf(++mBookmarksCreated)));
  }

  public void trackPlaceShared(String channel)
  {
    trackEvent(EventName.PLACE_SHARED, params().add(EventParam.CHANNEL, channel).add(EventParam.COUNT, String.valueOf(++mSharedTimes)));
  }

  public void trackApiCall(@NonNull ParsedMwmRequest request)
  {
    trackEvent(EventName.API_CALLED, params().add(EventParam.CALLER_ID, request.getCallerInfo() == null ?
                                                                        "null" :
                                                                        request.getCallerInfo().packageName));
  }

  public void trackRatingDialog(float rating)
  {
    trackEvent(EventName.RATE_DIALOG_RATED, params().add(EventParam.RATING, String.valueOf(rating)));
  }

  public void trackConnectionState()
  {
    if (ConnectionState.isConnected())
    {
      final NetworkInfo info = ConnectionState.getActiveNetwork();
      boolean isConnectionMetered = false;
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
        isConnectionMetered = ((ConnectivityManager) MwmApplication.get().getSystemService(Context.CONNECTIVITY_SERVICE)).isActiveNetworkMetered();
      //noinspection ConstantConditions
      trackEvent(EventName.ACTIVE_CONNECTION,
                 params().add(EventParam.CONNECTION_TYPE, info.getTypeName() + ":" + info.getSubtypeName())
                         .add(EventParam.CONNECTION_FAST, String.valueOf(ConnectionState.isConnectionFast(info)))
                         .add(EventParam.CONNECTION_METERED, String.valueOf(isConnectionMetered)));
    }
    else
      trackEvent(EventName.ACTIVE_CONNECTION, params().add(EventParam.CONNECTION_TYPE, "Not connected."));
  }

  // FIXME Call to track map changes to MyTracker to correctly deal with preinstalls.
  public void trackMapChanged(String event)
  {
    if (mEnabled)
    {
      final ParameterBuilder params = params().add(EventParam.COUNT, String.valueOf(MapManager.nativeGetDownloadedCount()));
      trackEvent(event, params);
    }
  }

  public void trackRouteBuild(int routerType, MapObject from, MapObject to)
  {
    trackEvent(EventName.ROUTING_BUILD, params().add(EventParam.FROM, Statistics.getPointType(from))
        .add(EventParam.TO, Statistics.getPointType(to)));
  }

  public void trackEditorLaunch(boolean newObject)
  {
    trackEvent(newObject ? EventName.EDITOR_START_CREATE : EventName.EDITOR_START_EDIT,
               editorMwmParams().add(EventParam.IS_AUTHENTICATED, String.valueOf(OsmOAuth.isAuthorized()))
                                .add(EventParam.IS_ONLINE, String.valueOf(ConnectionState.isConnected())));

    if (newObject)
      PushwooshHelper.nativeSendEditorAddObjectTag();
    else
      PushwooshHelper.nativeSendEditorEditObjectTag();
  }

  public void trackSubwayEvent(@NonNull String status)
  {
    trackMapLayerEvent(ParamValue.SUBWAY, status);
  }

  public void trackTrafficEvent(@NonNull String status)
  {
    trackMapLayerEvent(ParamValue.TRAFFIC, status);
  }

  private void trackMapLayerEvent(@NonNull String eventName, @NonNull String status)
  {
    ParameterBuilder builder = params().add(EventParam.NAME, eventName)
                                       .add(EventParam.STATUS, status);
    trackEvent(EventName.MAP_LAYERS_ACTIVATE, builder);
  }

  public void trackEditorSuccess(boolean newObject)
  {
    trackEvent(newObject ? EventName.EDITOR_SUCCESS_CREATE : EventName.EDITOR_SUCCESS_EDIT,
               editorMwmParams().add(EventParam.IS_AUTHENTICATED, String.valueOf(OsmOAuth.isAuthorized()))
                                .add(EventParam.IS_ONLINE, String.valueOf(ConnectionState.isConnected())));
  }

  public void trackEditorError(boolean newObject)
  {
    trackEvent(newObject ? EventName.EDITOR_ERROR_CREATE : EventName.EDITOR_ERROR_EDIT,
               editorMwmParams().add(EventParam.IS_AUTHENTICATED, String.valueOf(OsmOAuth.isAuthorized()))
                                .add(EventParam.IS_ONLINE, String.valueOf(ConnectionState.isConnected())));
  }

  public void trackNetworkUsageAlert(@NonNull String event, @NonNull String param)
  {
    trackEvent(event, Statistics.params().add(VALUE, param));
  }

  public void trackAuthRequest(OsmOAuth.AuthType type)
  {
    trackEvent(EventName.EDITOR_AUTH_REQUEST, Statistics.params().add(Statistics.EventParam.TYPE, type.name));
  }

  public void trackTaxiInRoutePlanning(@Nullable MapObject from, @Nullable MapObject to,
                                       @Nullable Location location, @NonNull String providerName,
                                       boolean isAppInstalled)
  {
    Statistics.ParameterBuilder params = Statistics.params();
    params.add(Statistics.EventParam.PROVIDER, providerName);

    params.add(Statistics.EventParam.FROM_LAT, from != null ? String.valueOf(from.getLat()) : "N/A")
          .add(Statistics.EventParam.FROM_LON, from != null ? String.valueOf(from.getLon()) : "N/A");

    params.add(Statistics.EventParam.TO_LAT, to != null ? String.valueOf(to.getLat()) : "N/A")
          .add(Statistics.EventParam.TO_LON, to != null ? String.valueOf(to.getLon()) : "N/A");

    String event = isAppInstalled ? Statistics.EventName.ROUTING_TAXI_ORDER
                                   : Statistics.EventName.ROUTING_TAXI_INSTALL;
    trackEvent(event, location, params.get());
  }

  public void trackTaxiEvent(@NonNull String eventName, @NonNull String providerName)
  {
    Statistics.ParameterBuilder params = Statistics.params();
    params.add(Statistics.EventParam.PROVIDER, providerName);
    trackEvent(eventName, params);
  }

  public void trackTaxiError(@NonNull TaxiInfoError error)
  {
    Statistics.ParameterBuilder params = Statistics.params();
    params.add(Statistics.EventParam.PROVIDER, error.getProviderName());
    params.add(ERROR_CODE, error.getCode().name());
    trackEvent(EventName.ROUTING_TAXI_ROUTE_BUILT, params);
  }

  public void trackNoTaxiProvidersError()
  {
    Statistics.ParameterBuilder params = Statistics.params();
    params.add(ERROR_CODE, TaxiManager.ErrorCode.NoProviders.name());
    trackEvent(EventName.ROUTING_TAXI_ROUTE_BUILT, params);
  }

  public void trackRestaurantEvent(@NonNull String eventName, @NonNull Sponsored restaurant,
                                   @NonNull MapObject mapObject)
  {
    String provider = restaurant.getType() == Sponsored.TYPE_OPENTABLE ? OPENTABLE : "Unknown restaurant";
    trackEvent(eventName, LocationHelper.INSTANCE.getLastKnownLocation(),
        Statistics.params().add(PROVIDER, provider)
                           .add(RESTAURANT, restaurant.getId())
                           .add(RESTAURANT_LAT, mapObject.getLat())
                           .add(RESTAURANT_LON, mapObject.getLon()).get());
  }

  public void trackHotelEvent(@NonNull String eventName, @NonNull Sponsored hotel,
                              @NonNull MapObject mapObject)
  {
    String provider = hotel.getType() == Sponsored.TYPE_BOOKING ? BOOKING_COM : "Unknown hotel";
    trackEvent(eventName, LocationHelper.INSTANCE.getLastKnownLocation(),
        Statistics.params().add(PROVIDER, provider)
                           .add(HOTEL, hotel.getId())
                           .add(HOTEL_LAT, mapObject.getLat())
                           .add(HOTEL_LON, mapObject.getLon()).get());
  }

  public void trackBookHotelEvent(@NonNull Sponsored hotel, @NonNull MapObject mapObject)
  {
    trackHotelEvent(PP_SPONSORED_BOOK, hotel, mapObject);
  }

  public void trackBookmarksTabEvent(@NonNull String param)
  {
    ParameterBuilder params = params().add(EventParam.VALUE, param);
    trackEvent(EventName.BM_TAB_CLICK, params);
  }

  public void trackOpenCatalogScreen()
  {
    trackEvent(EventName.BM_DOWNLOADED_CATALOGUE_OPEN, Collections.emptyMap());
  }

  public void trackDownloadCatalogError(@NonNull String value)
  {
    ParameterBuilder params = params().add(EventParam.ERROR, value);
    trackEvent(EventName.BM_DOWNLOADED_CATALOGUE_ERROR, params);
  }

  public void trackPPBanner(@NonNull String eventName, @NonNull MwmNativeAd ad, @BannerState int state)
  {
    trackEvent(eventName, Statistics.params()
                                    .add(BANNER, ad.getBannerId())
                                    .add(PROVIDER, ad.getProvider())
                                    .add(STATE, String.valueOf(state)));

    if (!eventName.equals(PP_BANNER_SHOW) || state == PP_BANNER_STATE_PREVIEW)
      MyTracker.trackEvent(eventName);
  }

  public void trackPPBannerError(@NonNull String bannerId, @NonNull String provider,
                                 @Nullable NativeAdError error, int state)
  {
    boolean isAdBlank = error != null && error.getCode() == AdError.NO_FILL_ERROR_CODE;
    String eventName = isAdBlank ? PP_BANNER_BLANK : PP_BANNER_ERROR;
    Statistics.ParameterBuilder builder = Statistics.params();
    builder.add(BANNER, !TextUtils.isEmpty(bannerId) ? bannerId : "N/A")
           .add(ERROR_CODE, error != null ? String.valueOf(error.getCode()) : "N/A")
           .add(ERROR_MESSAGE, error != null ? error.getMessage() : "N/A")
           .add(PROVIDER, provider)
           .add(STATE, String.valueOf(state));
    trackEvent(eventName, builder.get());
    MyTracker.trackEvent(eventName);
  }

  public void trackBookingSearchEvent(@NonNull MapObject mapObject)
  {
    trackEvent(PP_SPONSORED_BOOK, LocationHelper.INSTANCE.getLastKnownLocation(),
               Statistics.params()
                         .add(PROVIDER, SEARCH_BOOKING_COM)
                         .add(HOTEL, "")
                         .add(HOTEL_LAT, mapObject.getLat())
                         .add(HOTEL_LON, mapObject.getLon())
                         .get());
  }

  public void trackDownloaderDialogEvent(@NonNull String eventName, long size)
  {
    trackEvent(eventName, Statistics.params()
                                    .add(MAP_DATA_SIZE, size));
  }

  public void trackDownloaderDialogError(long size, @NonNull String error)
  {
    trackEvent(DOWNLOADER_DIALOG_ERROR, Statistics.params()
                                                  .add(MAP_DATA_SIZE, size)
                                                  .add(TYPE, error));
  }

  public void trackPPOwnershipButtonClick(@NonNull MapObject mapObject)
  {
    trackEvent(PP_OWNERSHIP_BUTTON_CLICK, LocationHelper.INSTANCE.getLastKnownLocation(),
               params()
                   .add(MWM_NAME, mapObject.getFeatureId().getMwmName())
                   .add(MWM_VERSION, mapObject.getFeatureId().getMwmVersion())
                   .add(FEATURE_ID, mapObject.getFeatureId().getFeatureIndex())
                   .get());
  }

  public void trackColdStartupInfo()
  {
    BatteryState.State state =  BatteryState.getState();
    final String charging;
    switch (state.getChargingStatus())
    {
      case CHARGING_STATUS_UNKNOWN:
        charging = "unknown";
        break;
      case CHARGING_STATUS_PLUGGED:
        charging = ParamValue.ON;
        break;
      case CHARGING_STATUS_UNPLUGGED:
        charging = ParamValue.OFF;
        break;
      default:
        charging = "unknown";
        break;
    }

    final String network = getConnectionState();

    trackEvent(APPLICATION_COLD_STARTUP_INFO,
               params()
                   .add(BATTERY, state.getLevel())
                   .add(CHARGING, charging)
                   .add(NETWORK, network)
                   .get());
  }

  @NonNull
  private String getConnectionState()
  {
    final String network;
    if (ConnectionState.isWifiConnected())
    {
      network = "wifi";
    }
    else if (ConnectionState.isMobileConnected())
    {
      if (ConnectionState.isInRoaming())
        network = "roaming";
      else
        network = "mobile";
    }
    else
    {
      network = "off";
    }
    return network;
  }

  public void trackSponsoredOpenEvent(@NonNull Sponsored sponsored)
  {
    Statistics.ParameterBuilder builder = Statistics.params();
    builder.add(NETWORK, getConnectionState())
           .add(PROVIDER, convertToSponsor(sponsored));
    trackEvent(PP_SPONSORED_OPEN, builder.get());
  }

  public void trackGalleryShown(@NonNull GalleryType type, @NonNull GalleryState state,
                                @NonNull GalleryPlacement placement, int itemsCount)
  {
    trackEvent(PP_SPONSORED_SHOWN, Statistics.params()
                                             .add(PROVIDER, type.getProvider())
                                             .add(PLACEMENT, placement.toString())
                                             .add(STATE, state.toString())
                                             .add(COUNT_LOWERCASE, itemsCount));

    if (state == GalleryState.ONLINE)
      MyTracker.trackEvent(PP_SPONSORED_SHOWN + "_" + type.getProvider());
  }

  public void trackGalleryError(@NonNull GalleryType type,
                                @NonNull GalleryPlacement placement, @Nullable String code)
  {
    trackEvent(PP_SPONSORED_ERROR, Statistics.params()
                                             .add(PROVIDER, type.getProvider())
                                             .add(PLACEMENT, placement.toString())
                                             .add(ERROR, code).get());
  }

  public void trackGalleryProductItemSelected(@NonNull GalleryType type,
                                              @NonNull GalleryPlacement placement, int position,
                                              @NonNull Destination destination)
  {
    trackEvent(PP_SPONSOR_ITEM_SELECTED, Statistics.params()
                                                   .add(PROVIDER, type.getProvider())
                                                   .add(PLACEMENT, placement.toString())
                                                   .add(ITEM, position)
                                                   .add(DESTINATION, destination.toString()));
  }

  public void trackGalleryEvent(@NonNull String eventName, @NonNull GalleryType type,
                                  @NonNull GalleryPlacement placement)
  {
    trackEvent(eventName, Statistics.params()
                                    .add(PROVIDER, type.getProvider())
                                    .add(PLACEMENT,placement.toString())
                                    .get());
  }

  public void trackSearchPromoCategory(@NonNull String eventName, @NonNull String provider)
  {
    trackEvent(eventName, Statistics.params().add(PROVIDER, provider).get());
    MyTracker.trackEvent(eventName + "_" + provider);
  }

  public void trackSettingsToggle(boolean value)
  {
    trackEvent(EventName.SETTINGS_TRACKING_TOGGLE, Statistics.params()
                                                             .add(TYPE, ParamValue.CRASH_REPORTS)
                                                             .add(VALUE, value
                                                                        ? ParamValue.ON
                                                                        : ParamValue.OFF).get());
  }

  public void trackSettingsDetails()
  {
    trackEvent(EventName.SETTINGS_TRACKING_DETAILS,
               Statistics.params().add(TYPE, ParamValue.PERSONAL_ADS).get());
  }

  @NonNull
  private static String convertToSponsor(@NonNull Sponsored sponsored)
  {
    if (sponsored.getType() == Sponsored.TYPE_PARTNER)
      return sponsored.getPartnerName();

    return convertToSponsor(sponsored.getType());
  }

  @NonNull
  private static String convertToSponsor(@Sponsored.SponsoredType int type)
  {
    switch (type)
    {
      case Sponsored.TYPE_BOOKING:
        return BOOKING_COM;
      case Sponsored.TYPE_OPENTABLE:
        return OPENTABLE;
      case Sponsored.TYPE_HOLIDAY:
        return HOLIDAY;
      case Sponsored.TYPE_PARTNER:
        return PARTNER;
      case Sponsored.TYPE_PROMO_CATALOG_CITY:
        return MAPSME_GUIDES;
      case Sponsored.TYPE_PROMO_CATALOG_SIGHTSEEINGS:
        // TODO: Dummy, fix with correct value when documentation will be done.
        return MAPSME_GUIDES;
      case Sponsored.TYPE_NONE:
        return "N/A";
      default:
        throw new AssertionError("Unknown sponsor type: " + type);
    }
  }

  public void trackRoutingPoint(@NonNull String eventName, @RoutePointInfo.RouteMarkType int type,
                                boolean isPlanning, boolean isNavigating, boolean isMyPosition,
                                boolean isApi)
  {
    final String mode;
    if (isNavigating)
      mode = "onroute";
    else if (isPlanning)
      mode = "planning";
    else
      mode = null;

    final String method;
    if (isPlanning)
      method = "planning_pp";
    else if (isApi)
      method = "api";
    else
      method = "outside_pp";

    ParameterBuilder builder = params()
        .add(TYPE, convertRoutePointType(type))
        .add(VALUE, isMyPosition ? "gps" : "point")
        .add(METHOD, method);
    if (mode != null)
      builder.add(MODE, mode);
    trackEvent(eventName, builder.get());
  }

  public void trackRoutingEvent(@NonNull String eventName, boolean isPlanning)
  {
    trackEvent(eventName,
               params()
                   .add(MODE, isPlanning ? "planning" : "onroute")
                   .get());
  }

  public void trackRoutingStart(@Framework.RouterType int type,
                                boolean trafficEnabled)
  {
    trackEvent(ROUTING_ROUTE_START, prepareRouteParams(type, trafficEnabled));
  }

  public void trackRoutingFinish(boolean interrupted, @Framework.RouterType int type,
                                 boolean trafficEnabled)
  {
    ParameterBuilder params = prepareRouteParams(type, trafficEnabled);
    trackEvent(ROUTING_ROUTE_FINISH, params.add(INTERRUPTED, interrupted ? 1 : 0));
  }

  @NonNull
  private static ParameterBuilder prepareRouteParams(@Framework.RouterType int type,
                                                     boolean trafficEnabled)
  {
    return params().add(MODE, toRouterType(type)).add(TRAFFIC, trafficEnabled ? 1 : 0);
  }

  @NonNull
  private static String toRouterType(@Framework.RouterType int type)
  {
    switch (type)
    {
      case Framework.ROUTER_TYPE_VEHICLE:
        return VEHICLE;
      case Framework.ROUTER_TYPE_PEDESTRIAN:
        return PEDESTRIAN;
      case Framework.ROUTER_TYPE_BICYCLE:
        return BICYCLE;
      case Framework.ROUTER_TYPE_TAXI:
        return TAXI;
      case Framework.ROUTER_TYPE_TRANSIT:
        return TRANSIT;
      default:
        throw new AssertionError("Unsupported router type: " + type);
    }
  }

  public void trackRoutingTooltipEvent(@RoutePointInfo.RouteMarkType int type,
                                       boolean isPlanning)
  {
    trackEvent(ROUTING_PLAN_TOOLTIP_CLICK,
               params()
                   .add(TYPE, convertRoutePointType(type))
                   .add(MODE, isPlanning ? "planning" : "onroute")
                   .get());
  }

  public void trackSponsoredObjectEvent(@NonNull String eventName, @NonNull Sponsored sponsoredObj,
                                        @NonNull MapObject mapObject)
  {
    // Here we code category by means of rating.
    trackEvent(eventName, LocationHelper.INSTANCE.getLastKnownLocation(),
        Statistics.params().add(PROVIDER, convertToSponsor(sponsoredObj))
            .add(CATEGORY, sponsoredObj.getRating())
            .add(OBJECT_LAT, mapObject.getLat())
            .add(OBJECT_LON, mapObject.getLon()).get());
  }

  @NonNull
  private static String convertRoutePointType(@RoutePointInfo.RouteMarkType int type)
  {
    switch (type)
    {
      case RoutePointInfo.ROUTE_MARK_FINISH:
        return "finish";
      case RoutePointInfo.ROUTE_MARK_INTERMEDIATE:
        return "inter";
      case RoutePointInfo.ROUTE_MARK_START:
        return "start";
      default:
        throw new AssertionError("Wrong parameter 'type'");
    }
  }

  public void trackUGCStart(boolean isEdit, boolean isPPPreview, boolean isFromNotification)
  {
    trackEvent(UGC_REVIEW_START,
               params()
                   .add(EventParam.IS_AUTHENTICATED, Framework.nativeIsUserAuthenticated())
                   .add(EventParam.IS_ONLINE, ConnectionState.isConnected())
                   .add(EventParam.MODE, isEdit ? ParamValue.EDIT : ParamValue.ADD)
                   .add(EventParam.FROM, isPPPreview ? ParamValue.PLACEPAGE_PREVIEW :
                                         isFromNotification ? ParamValue.NOTIFICATION : ParamValue.PLACEPAGE)
                   .get());
  }

  public void trackUGCAuthDialogShown()
  {
    trackEvent(UGC_AUTH_SHOWN, params().add(EventParam.FROM, ParamValue.AFTER_SAVE).get());
  }

  public void trackUGCExternalAuthSucceed(@NonNull String provider)
  {
    trackEvent(UGC_AUTH_EXTERNAL_REQUEST_SUCCESS, params().add(EventParam.PROVIDER, provider));
  }

  public void trackUGCAuthFailed(@Framework.AuthTokenType int type, @Nullable String error)
  {
    trackEvent(UGC_AUTH_ERROR, params()
        .add(EventParam.PROVIDER, getAuthProvider(type))
        .add(EventParam.ERROR, error)
        .get());
  }

  @NonNull
  public static String getAuthProvider(@Framework.AuthTokenType int type)
  {
    switch (type)
    {
      case Framework.SOCIAL_TOKEN_FACEBOOK:
        return FACEBOOK;
      case Framework.SOCIAL_TOKEN_GOOGLE:
        return GOOGLE;
      case Framework.SOCIAL_TOKEN_PHONE:
        return PHONE;
      case Framework.TOKEN_MAPSME:
        return MAPSME;
      case Framework.SOCIAL_TOKEN_INVALID:
        return UNKNOWN;
      default:
        throw new AssertionError("Unknown social token type: " + type);
    }
  }

  @NonNull
  public static String getSynchronizationType(@BookmarkManager.SynchronizationType int type)
  {
    return type == 0 ? BACKUP : RESTORE;
  }

  public void trackFilterEvent(@NonNull String event, @NonNull String category)
  {
    trackEvent(event, params()
              .add(EventParam.CATEGORY, category)
              .get());
  }

  public void trackFilterClick(@NonNull String category, @NonNull Pair<String, String> params)
  {
    trackEvent(SEARCH_FILTER_CLICK, params()
              .add(EventParam.CATEGORY, category)
              .add(params.first, params.second)
              .get());
  }

  public void trackBmSyncProposalShown(boolean hasAuth)
  {
    trackEvent(BM_SYNC_PROPOSAL_SHOWN, params().add(HAS_AUTH, hasAuth ? 1 : 0).get());
  }

  public void trackBmSyncProposalApproved(boolean hasAuth)
  {
    trackEvent(BM_SYNC_PROPOSAL_APPROVED, params()
        .add(HAS_AUTH, hasAuth ? 1 : 0)
        .add(NETWORK, getConnectionState())
        .get());
  }

  public void trackBmRestoreProposalClick()
  {
    trackEvent(BM_RESTORE_PROPOSAL_CLICK, params()
        .add(NETWORK, getConnectionState())
        .get());
  }

  public void trackBmSyncProposalError(@Framework.AuthTokenType int type, @Nullable String message)
  {
    trackEvent(BM_SYNC_PROPOSAL_ERROR, params()
        .add(PROVIDER, getAuthProvider(type))
        .add(ERROR, message)
        .get());
  }

  public void trackBmSettingsToggle(boolean checked)
  {
    trackEvent(BM_SYNC_PROPOSAL_TOGGLE, params()
        .add(STATE, checked ? 1 : 0)
        .get());
  }

  public void trackBmSynchronizationFinish(@BookmarkManager.SynchronizationType int type,
                                           @BookmarkManager.SynchronizationResult int result,
                                           @NonNull String errorString)
  {
    if (result == BookmarkManager.CLOUD_SUCCESS)
    {
      if (type == BookmarkManager.CLOUD_BACKUP)
        trackEvent(BM_SYNC_SUCCESS);
      else
        trackEvent(BM_RESTORE_PROPOSAL_SUCCESS);
      return;
    }

    trackEvent(type == BookmarkManager.CLOUD_BACKUP ? BM_SYNC_ERROR : BM_RESTORE_PROPOSAL_ERROR,
               params().add(TYPE, getTypeForErrorSyncResult(result)).add(ERROR, errorString));
  }

  public void trackBmRestoringRequestResult(@BookmarkManager.RestoringRequestResult int result)
  {
    if (result == BookmarkManager.CLOUD_BACKUP_EXISTS)
      return;

    trackEvent(BM_RESTORE_PROPOSAL_ERROR, params()
        .add(TYPE, getTypeForRequestRestoringError(result)));
  }

  @NonNull
  private static String getTypeForErrorSyncResult(@BookmarkManager.SynchronizationResult int result)
  {
    switch (result)
    {
      case BookmarkManager.CLOUD_AUTH_ERROR:
        return ParamValue.AUTH;
      case BookmarkManager.CLOUD_NETWORK_ERROR:
        return ParamValue.NETWORK;
      case BookmarkManager.CLOUD_DISK_ERROR:
        return ParamValue.DISK;
      case BookmarkManager.CLOUD_USER_INTERRUPTED:
        return ParamValue.USER_INTERRUPTED;
      case BookmarkManager.CLOUD_INVALID_CALL:
        return ParamValue.INVALID_CALL;
      case BookmarkManager.CLOUD_SUCCESS:
        throw new AssertionError("It's not a error result!");
      default:
        throw new AssertionError("Unsupported error type: " + result);
    }
  }

  @NonNull
  private static String getTypeForRequestRestoringError(@BookmarkManager.RestoringRequestResult int result)
  {
    switch (result)
    {
      case BookmarkManager.CLOUD_BACKUP_EXISTS:
        throw new AssertionError("It's not a error result!");
      case BookmarkManager.CLOUD_NOT_ENOUGH_DISK_SPACE:
        return DISK_NO_SPACE;
      case BookmarkManager.CLOUD_NO_BACKUP:
        return NO_BACKUP;
      default:
        throw new AssertionError("Unsupported restoring request result: " + result);
    }
  }

  public void trackToolbarClick(@NonNull MainMenu.Item button)
  {
    trackEvent(TOOLBAR_CLICK, getToolbarParams(button));
  }

  public void trackToolbarMenu(@NonNull MainMenu.Item button)
  {
    trackEvent(TOOLBAR_MENU_CLICK, getToolbarParams(button));
  }

  public void trackDownloadBookmarkDialog(@NonNull String button)
  {
    trackEvent(BM_GUIDES_DOWNLOADDIALOGUE_CLICK, params().add(ACTION, button));
  }

  @NonNull
  private static ParameterBuilder getToolbarParams(@NonNull MainMenu.Item button)
  {
    return params().add(BUTTON, button.toStatisticValue());
  }

  public void trackPPBannerClose(@BannerState int state, boolean isCross)
  {
    trackEvent(PP_BANNER_CLOSE, params().add(BANNER, state)
                                        .add(BUTTON, isCross ? 0 : 1));
  }

  public void trackPurchasePreviewShow(@NonNull String purchaseId, @NonNull String vendor,
                                       @NonNull String productId, @Nullable String from)
  {
    ParameterBuilder params = params().add(VENDOR, vendor)
                                      .add(PRODUCT, productId)
                                      .add(PURCHASE, purchaseId);
    if (!TextUtils.isEmpty(from))
      params.add(FROM, from);

    trackEvent(INAPP_PURCHASE_PREVIEW_SHOW, params,
               STATISTICS_CHANNEL_REALTIME);
  }

  public void trackPurchasePreviewShow(@NonNull String purchaseId, @NonNull String vendor,
                                       @NonNull String productId)
  {
     trackPurchasePreviewShow(purchaseId, vendor, productId, null);
  }

  public void trackPurchaseEvent(@NonNull String event, @NonNull String purchaseId)
  {
    trackPurchaseEvent(event, purchaseId, STATISTICS_CHANNEL_DEFAULT);
  }

  public void trackPurchaseEvent(@NonNull String event, @NonNull String purchaseId,
                                 @StatisticsChannel int channel)
  {
    trackEvent(event, params().add(PURCHASE, purchaseId), channel);
  }

  public void trackPurchasePreviewSelect(@NonNull String purchaseId, @NonNull String productId)
  {
    trackEvent(INAPP_PURCHASE_PREVIEW_SELECT, params().add(PRODUCT, productId)
                                                      .add(PURCHASE, purchaseId));
  }

  public void trackPurchaseStoreError(@NonNull String purchaseId,
                                      @BillingClient.BillingResponse int error)
  {
    trackEvent(INAPP_PURCHASE_STORE_ERROR, params().add(ERROR, "Billing error: " + error)
                                                   .add(PURCHASE, purchaseId));
  }

  public void trackPurchaseValidationError(@NonNull String purchaseId, @NonNull ValidationStatus status)
  {
    if (status == ValidationStatus.VERIFIED)
      return;

    int errorCode;
    switch (status)
    {
      case NOT_VERIFIED:
        errorCode = 0;
        break;
      case AUTH_ERROR:
        errorCode = 1;
        break;
      case SERVER_ERROR:
        errorCode = 2;
        break;
      default:
        throw new UnsupportedOperationException("Unsupported status: " + status);
    }

    trackEvent(INAPP_PURCHASE_VALIDATION_ERROR, params().add(ERROR_CODE, errorCode)
                                                        .add(PURCHASE, purchaseId));
  }

  public void trackPowerManagmentSchemeChanged(@PowerManagment.SchemeType int scheme)
  {
    String statisticValue = "";
    switch (scheme)
    {
      case PowerManagment.NONE:
      case PowerManagment.MEDIUM:
        throw new AssertionError("Incorrect scheme type");
      case PowerManagment.NORMAL: statisticValue = "never"; break;
      case PowerManagment.AUTO: statisticValue = "auto"; break;
      case PowerManagment.HIGH: statisticValue = "max"; break;
    }

    trackEvent(EventName.Settings.ENERGY_SAVING, params().add(EventParam.VALUE, statisticValue));
  }

  public void trackPurchaseProductDelivered(@NonNull String purchaseId, @NonNull String vendor)
  {
    trackEvent(INAPP_PURCHASE_PRODUCT_DELIVERED, params().add(VENDOR, vendor)
                                                         .add(PURCHASE, purchaseId),
               STATISTICS_CHANNEL_REALTIME);
  }

  public void trackTipsEvent(@NonNull String eventName, int type)
  {
    trackEvent(eventName, params().add(TYPE, type));
  }

  public void trackTipsClose(int type)
  {
    trackEvent(TIPS_TRICKS_CLOSE, params().add(TYPE, type).add(OPTION, OFFSCREEEN));
  }

  public void trackGuidesShown(@NonNull String serverIds)
  {
    if (!serverIds.isEmpty())
      trackEvent(GUIDES_SHOWN, params().add(SERVER_IDS, serverIds), STATISTICS_CHANNEL_REALTIME);
  }

  public void trackGuideOpen(@NonNull String serverId)
  {
    trackEvent(GUIDES_OPEN, params().add(SERVER_ID, serverId), STATISTICS_CHANNEL_REALTIME);
  }

  public void trackGuideBookmarkSelect(@NonNull String serverId)
  {
    trackEvent(GUIDES_BOOKMARK_SELECT, params().add(SERVER_ID, serverId), STATISTICS_CHANNEL_REALTIME);
  }

  public void trackGuideTrackSelect(@NonNull String serverId)
  {
    trackEvent(GUIDES_TRACK_SELECT, params().add(SERVER_ID, serverId), STATISTICS_CHANNEL_REALTIME);
  }

  public static ParameterBuilder params()
  {
    return new ParameterBuilder();
  }

  public static ParameterBuilder editorMwmParams()
  {
    return params().add(MWM_NAME, Editor.nativeGetMwmName())
                   .add(MWM_VERSION, Editor.nativeGetMwmVersion());
  }

  public static class ParameterBuilder
  {
    private final Map<String, String> mParams = new HashMap<>();

    @NonNull
    public static ParameterBuilder from(@NonNull String key, @NonNull Analytics analytics)
    {
      return new ParameterBuilder().add(key, analytics.getName());
    }

    public ParameterBuilder add(String key, String value)
    {
      mParams.put(key, value);
      return this;
    }

    public ParameterBuilder add(String key, boolean value)
    {
      mParams.put(key, String.valueOf(value));
      return this;
    }

    public ParameterBuilder add(String key, int value)
    {
      mParams.put(key, String.valueOf(value));
      return this;
    }

    public ParameterBuilder add(String key, float value)
    {
      mParams.put(key, String.valueOf(value));
      return this;
    }

    public ParameterBuilder add(String key, double value)
    {
      mParams.put(key, String.valueOf(value));
      return this;
    }

    public Map<String, String> get()
    {
      return mParams;
    }
  }

  public static String getPointType(MapObject point)
  {
    return MapObject.isOfType(MapObject.MY_POSITION, point) ? Statistics.EventParam.MY_POSITION
                                                            : Statistics.EventParam.POINT;
  }
  
  public enum NetworkErrorType 
  {
    NO_NETWORK,
    AUTH_FAILED;
  }
}