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
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
|
/*!
* Piwik - free/libre analytics platform
*
* JavaScript tracking client
*
* @link http://piwik.org
* @source https://github.com/piwik/piwik/blob/master/js/piwik.js
* @license http://piwik.org/free-software/bsd/ BSD-3 Clause (also in js/LICENSE.txt)
* @license magnet:?xt=urn:btih:c80d50af7d3db9be66a4d0a86db0286e4fd33292&dn=bsd-3-clause.txt BSD-3-Clause
*/
// Refer to README.md for build instructions when minifying this file for distribution.
/*
* Browser [In]Compatibility
* - minimum required ECMAScript: ECMA-262, edition 3
*
* Incompatible with these (and earlier) versions of:
* - IE4 - try..catch and for..in introduced in IE5
* - IE5 - named anonymous functions, array.push, encodeURIComponent, decodeURIComponent, and getElementsByTagName introduced in IE5.5
* - Firefox 1.0 and Netscape 8.x - FF1.5 adds array.indexOf, among other things
* - Mozilla 1.7 and Netscape 6.x-7.x
* - Netscape 4.8
* - Opera 6 - Error object (and Presto) introduced in Opera 7
* - Opera 7
*/
/************************************************************
* JSON - public domain reference implementation by Douglas Crockford
* @version 2012-10-08
* @link http://www.JSON.org/js.html
************************************************************/
/*jslint evil: true, regexp: false, bitwise: true, white: true */
/*global JSON2:true */
/*members "", "\b", "\t", "\n", "\f", "\r", "\"", "\\", apply,
call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
lastIndex, length, parse, prototype, push, replace, sort, slice, stringify,
test, toJSON, toString, valueOf,
objectToJSON
*/
// Create a JSON object only if one does not already exist. We create the
// methods in a closure to avoid creating global variables.
if (typeof JSON2 !== 'object') {
JSON2 = {};
}
(function () {
'use strict';
function f(n) {
// Format integers to have at least two digits.
return n < 10 ? '0' + n : n;
}
function objectToJSON(value, key) {
var objectType = Object.prototype.toString.apply(value);
if (objectType === '[object Date]') {
return isFinite(value.valueOf())
? value.getUTCFullYear() + '-' +
f(value.getUTCMonth() + 1) + '-' +
f(value.getUTCDate()) + 'T' +
f(value.getUTCHours()) + ':' +
f(value.getUTCMinutes()) + ':' +
f(value.getUTCSeconds()) + 'Z'
: null;
}
if (objectType === '[object String]' ||
objectType === '[object Number]' ||
objectType === '[object Boolean]') {
return value.valueOf();
}
if (objectType !== '[object Array]' &&
typeof value.toJSON === 'function') {
return value.toJSON(key);
}
return value;
}
var cx = new RegExp('[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]', 'g'),
// hack: workaround Snort false positive (sid 8443)
pattern = '\\\\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]',
escapable = new RegExp('[' + pattern, 'g'),
gap,
indent,
meta = { // table of character substitutions
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
'\r': '\\r',
'"' : '\\"',
'\\': '\\\\'
},
rep;
function quote(string) {
// If the string contains no control characters, no quote characters, and no
// backslash characters, then we can safely slap some quotes around it.
// Otherwise we must also replace the offending characters with safe escape
// sequences.
escapable.lastIndex = 0;
return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
var c = meta[a];
return typeof c === 'string'
? c
: '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
}) + '"' : '"' + string + '"';
}
function str(key, holder) {
// Produce a string from holder[key].
var i, // The loop counter.
k, // The member key.
v, // The member value.
length,
mind = gap,
partial,
value = holder[key];
// If the value has a toJSON method, call it to obtain a replacement value.
if (value && typeof value === 'object') {
value = objectToJSON(value, key);
}
// If we were called with a replacer function, then call the replacer to
// obtain a replacement value.
if (typeof rep === 'function') {
value = rep.call(holder, key, value);
}
// What happens next depends on the value's type.
switch (typeof value) {
case 'string':
return quote(value);
case 'number':
// JSON numbers must be finite. Encode non-finite numbers as null.
return isFinite(value) ? String(value) : 'null';
case 'boolean':
case 'null':
// If the value is a boolean or null, convert it to a string. Note:
// typeof null does not produce 'null'. The case is included here in
// the remote chance that this gets fixed someday.
return String(value);
// If the type is 'object', we might be dealing with an object or an array or
// null.
case 'object':
// Due to a specification blunder in ECMAScript, typeof null is 'object',
// so watch out for that case.
if (!value) {
return 'null';
}
// Make an array to hold the partial results of stringifying this object value.
gap += indent;
partial = [];
// Is the value an array?
if (Object.prototype.toString.apply(value) === '[object Array]') {
// The value is an array. Stringify every element. Use null as a placeholder
// for non-JSON values.
length = value.length;
for (i = 0; i < length; i += 1) {
partial[i] = str(i, value) || 'null';
}
// Join all of the elements together, separated with commas, and wrap them in
// brackets.
v = partial.length === 0
? '[]'
: gap
? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']'
: '[' + partial.join(',') + ']';
gap = mind;
return v;
}
// If the replacer is an array, use it to select the members to be stringified.
if (rep && typeof rep === 'object') {
length = rep.length;
for (i = 0; i < length; i += 1) {
if (typeof rep[i] === 'string') {
k = rep[i];
v = str(k, value);
if (v) {
partial.push(quote(k) + (gap ? ': ' : ':') + v);
}
}
}
} else {
// Otherwise, iterate through all of the keys in the object.
for (k in value) {
if (Object.prototype.hasOwnProperty.call(value, k)) {
v = str(k, value);
if (v) {
partial.push(quote(k) + (gap ? ': ' : ':') + v);
}
}
}
}
// Join all of the member texts together, separated with commas,
// and wrap them in braces.
v = partial.length === 0
? '{}'
: gap
? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}'
: '{' + partial.join(',') + '}';
gap = mind;
return v;
}
}
// If the JSON object does not yet have a stringify method, give it one.
if (typeof JSON2.stringify !== 'function') {
JSON2.stringify = function (value, replacer, space) {
// The stringify method takes a value and an optional replacer, and an optional
// space parameter, and returns a JSON text. The replacer can be a function
// that can replace values, or an array of strings that will select the keys.
// A default replacer method can be provided. Use of the space parameter can
// produce text that is more easily readable.
var i;
gap = '';
indent = '';
// If the space parameter is a number, make an indent string containing that
// many spaces.
if (typeof space === 'number') {
for (i = 0; i < space; i += 1) {
indent += ' ';
}
// If the space parameter is a string, it will be used as the indent string.
} else if (typeof space === 'string') {
indent = space;
}
// If there is a replacer, it must be a function or an array.
// Otherwise, throw an error.
rep = replacer;
if (replacer && typeof replacer !== 'function' &&
(typeof replacer !== 'object' ||
typeof replacer.length !== 'number')) {
throw new Error('JSON2.stringify');
}
// Make a fake root object containing our value under the key of ''.
// Return the result of stringifying the value.
return str('', {'': value});
};
}
// If the JSON object does not yet have a parse method, give it one.
if (typeof JSON2.parse !== 'function') {
JSON2.parse = function (text, reviver) {
// The parse method takes a text and an optional reviver function, and returns
// a JavaScript value if the text is a valid JSON text.
var j;
function walk(holder, key) {
// The walk method is used to recursively walk the resulting structure so
// that modifications can be made.
var k, v, value = holder[key];
if (value && typeof value === 'object') {
for (k in value) {
if (Object.prototype.hasOwnProperty.call(value, k)) {
v = walk(value, k);
if (v !== undefined) {
value[k] = v;
} else {
delete value[k];
}
}
}
}
return reviver.call(holder, key, value);
}
// Parsing happens in four stages. In the first stage, we replace certain
// Unicode characters with escape sequences. JavaScript handles many characters
// incorrectly, either silently deleting them, or treating them as line endings.
text = String(text);
cx.lastIndex = 0;
if (cx.test(text)) {
text = text.replace(cx, function (a) {
return '\\u' +
('0000' + a.charCodeAt(0).toString(16)).slice(-4);
});
}
// In the second stage, we run the text against regular expressions that look
// for non-JSON patterns. We are especially concerned with '()' and 'new'
// because they can cause invocation, and '=' because it can cause mutation.
// But just to be safe, we want to reject all unexpected forms.
// We split the second stage into 4 regexp operations in order to work around
// crippling inefficiencies in IE's and Safari's regexp engines. First we
// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
// replace all simple value tokens with ']' characters. Third, we delete all
// open brackets that follow a colon or comma or that begin the text. Finally,
// we look to see that the remaining characters are only whitespace or ']' or
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
if ((new RegExp('^[\\],:{}\\s]*$'))
.test(text.replace(new RegExp('\\\\(?:["\\\\/bfnrt]|u[0-9a-fA-F]{4})', 'g'), '@')
.replace(new RegExp('"[^"\\\\\n\r]*"|true|false|null|-?\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d+)?', 'g'), ']')
.replace(new RegExp('(?:^|:|,)(?:\\s*\\[)+', 'g'), ''))) {
// In the third stage we use the eval function to compile the text into a
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
// in JavaScript: it can begin a block or an object literal. We wrap the text
// in parens to eliminate the ambiguity.
j = eval('(' + text + ')');
// In the optional fourth stage, we recursively walk the new structure, passing
// each name/value pair to a reviver function for possible transformation.
return typeof reviver === 'function'
? walk({'': j}, '')
: j;
}
// If the text is not JSON parseable, then a SyntaxError is thrown.
throw new SyntaxError('JSON2.parse');
};
}
}());
/************************************************************
* end JSON
************************************************************/
/*jslint browser:true, plusplus:true, vars:true, nomen:true, evil:true */
/*global window */
/*global unescape */
/*global ActiveXObject */
/*members encodeURIComponent, decodeURIComponent, getElementsByTagName,
shift, unshift, piwikAsyncInit,
createElement, appendChild, characterSet, charset,
addEventListener, attachEvent, removeEventListener, detachEvent, disableCookies,
cookie, domain, readyState, documentElement, doScroll, title, text,
location, top, onerror, document, referrer, parent, links, href, protocol, name, GearsFactory,
performance, mozPerformance, msPerformance, webkitPerformance, timing, requestStart,
responseEnd, event, which, button, srcElement, type, target,
parentNode, tagName, hostname, className,
userAgent, cookieEnabled, platform, mimeTypes, enabledPlugin, javaEnabled,
XMLHttpRequest, ActiveXObject, open, setRequestHeader, onreadystatechange, send, readyState, status,
getTime, getTimeAlias, setTime, toGMTString, getHours, getMinutes, getSeconds,
toLowerCase, toUpperCase, charAt, indexOf, lastIndexOf, split, slice,
onload, src,
round, random,
exec,
res, width, height, devicePixelRatio,
pdf, qt, realp, wma, dir, fla, java, gears, ag,
hook, getHook, getVisitorId, getVisitorInfo, setUserId, getUserId, setSiteId, setTrackerUrl, appendToTrackingUrl, getRequest, addPlugin,
getAttributionInfo, getAttributionCampaignName, getAttributionCampaignKeyword,
getAttributionReferrerTimestamp, getAttributionReferrerUrl,
setCustomData, getCustomData,
setCustomRequestProcessing,
setCustomVariable, getCustomVariable, deleteCustomVariable, storeCustomVariablesInCookie,
setDownloadExtensions, addDownloadExtensions,
setDomains, setIgnoreClasses, setRequestMethod, setRequestContentType,
setReferrerUrl, setCustomUrl, setAPIUrl, setDocumentTitle,
setDownloadClasses, setLinkClasses,
setCampaignNameKey, setCampaignKeywordKey,
discardHashTag,
setCookieNamePrefix, setCookieDomain, setCookiePath, setVisitorIdCookie,
setVisitorCookieTimeout, setSessionCookieTimeout, setReferralCookieTimeout,
setConversionAttributionFirstReferrer,
disablePerformanceTracking, setGenerationTimeMs,
doNotTrack, setDoNotTrack, msDoNotTrack,
addListener, enableLinkTracking, enableJSErrorTracking, setLinkTrackingTimer,
setHeartBeatTimer, killFrame, redirectFile, setCountPreRendered,
trackGoal, trackLink, trackPageView, trackSiteSearch, trackEvent,
setEcommerceView, addEcommerceItem, trackEcommerceOrder, trackEcommerceCartUpdate,
deleteCookies, offsetTop, offsetLeft, offsetHeight, offsetWidth, nodeType, defaultView,
innerHTML, scrollLeft, scrollTop, currentStyle, getComputedStyle, querySelectorAll, splice,
getAttribute, hasAttribute, attributes, nodeName, findContentNodes, findContentNodes, findContentNodesWithinNode,
findPieceNode, findTargetNodeNoDefault, findTargetNode, findContentPiece, children, hasNodeCssClass,
getAttributeValueFromNode, hasNodeAttributeWithValue, hasNodeAttribute, findNodesByTagName, findMultiple,
makeNodesUnique, concat, find, htmlCollectionToArray, offsetParent, value, nodeValue, findNodesHavingAttribute,
findFirstNodeHavingAttribute, findFirstNodeHavingAttributeWithValue, getElementsByClassName,
findNodesHavingCssClass, findFirstNodeHavingClass, isLinkElement, findParentContentNode, removeDomainIfIsInLink,
findContentName, findMediaUrlInNode, toAbsoluteUrl, findContentTarget, getLocation, origin, host, isSameDomain,
search, trim, getBoundingClientRect, bottom, right, left, innerWidth, innerHeight, clientWidth, clientHeight,
isOrWasNodeInViewport, isNodeVisible, buildInteractionRequestParams, buildImpressionRequestParams,
shouldIgnoreInteraction, setHrefAttribute, setAttribute, buildContentBlock, collectContent, setLocation,
CONTENT_ATTR, CONTENT_CLASS, CONTENT_NAME_ATTR, CONTENT_PIECE_ATTR, CONTENT_PIECE_CLASS,
CONTENT_TARGET_ATTR, CONTENT_TARGET_CLASS, CONTENT_IGNOREINTERACTION_ATTR, CONTENT_IGNOREINTERACTION_CLASS,
trackCallbackOnLoad, trackCallbackOnReady, buildContentImpressionsRequests, wasContentImpressionAlreadyTracked,
getQuery, getContent, getContentImpressionsRequestsFromNodes, buildContentInteractionTrackingRedirectUrl,
buildContentInteractionRequestNode, buildContentInteractionRequest, buildContentImpressionRequest,
appendContentInteractionToRequestIfPossible, setupInteractionsTracking, trackContentImpressionClickInteraction,
internalIsNodeVisible, clearTrackedContentImpressions, getTrackerUrl, trackAllContentImpressions,
getTrackedContentImpressions, getCurrentlyVisibleContentImpressionsRequestsIfNotTrackedYet,
contentInteractionTrackingSetupDone, contains, match, pathname, piece, trackContentInteractionNode,
trackContentInteractionNode, trackContentImpressionsWithinNode, trackContentImpression,
enableTrackOnlyVisibleContent, trackContentInteraction, clearEnableTrackOnlyVisibleContent,
trackVisibleContentImpressions, isTrackOnlyVisibleContentEnabled, port, isUrlToCurrentDomain,
isNodeAuthorizedToTriggerInteraction, replaceHrefIfInternalLink, getConfigDownloadExtensions, disableLinkTracking,
substr, setAnyAttribute, wasContentTargetAttrReplaced, max, abs, childNodes, compareDocumentPosition, body,
getConfigVisitorCookieTimeout, getRemainingVisitorCookieTimeout
*/
/*global _paq:true */
/*members push */
/*global Piwik:true */
/*members addPlugin, getTracker, getAsyncTracker */
/*global Piwik_Overlay_Client */
/*global AnalyticsTracker:true */
/*members initialize */
/*global define */
/*members amd */
/*global console:true */
/*members error */
// asynchronous tracker (or proxy)
if (typeof _paq !== 'object') {
_paq = [];
}
// Piwik singleton and namespace
if (typeof Piwik !== 'object') {
Piwik = (function () {
'use strict';
/************************************************************
* Private data
************************************************************/
var expireDateTime,
/* plugins */
plugins = {},
/* alias frequently used globals for added minification */
documentAlias = document,
navigatorAlias = navigator,
screenAlias = screen,
windowAlias = window,
/* performance timing */
performanceAlias = windowAlias.performance || windowAlias.mozPerformance || windowAlias.msPerformance || windowAlias.webkitPerformance,
/* DOM Ready */
hasLoaded = false,
registeredOnLoadHandlers = [],
/* encode */
encodeWrapper = windowAlias.encodeURIComponent,
/* decode */
decodeWrapper = windowAlias.decodeURIComponent,
/* urldecode */
urldecode = unescape,
/* asynchronous tracker */
asyncTracker,
/* iterator */
iterator,
/* local Piwik */
Piwik;
/************************************************************
* Private methods
************************************************************/
/*
* Is property defined?
*/
function isDefined(property) {
// workaround https://github.com/douglascrockford/JSLint/commit/24f63ada2f9d7ad65afc90e6d949f631935c2480
var propertyType = typeof property;
return propertyType !== 'undefined';
}
/*
* Is property a function?
*/
function isFunction(property) {
return typeof property === 'function';
}
/*
* Is property an object?
*
* @return bool Returns true if property is null, an Object, or subclass of Object (i.e., an instanceof String, Date, etc.)
*/
function isObject(property) {
return typeof property === 'object';
}
/*
* Is property a string?
*/
function isString(property) {
return typeof property === 'string' || property instanceof String;
}
/*
* apply wrapper
*
* @param array parameterArray An array comprising either:
* [ 'methodName', optional_parameters ]
* or:
* [ functionObject, optional_parameters ]
*/
function apply() {
var i, f, parameterArray;
for (i = 0; i < arguments.length; i += 1) {
parameterArray = arguments[i];
f = parameterArray.shift();
if (isString(f)) {
asyncTracker[f].apply(asyncTracker, parameterArray);
} else {
f.apply(asyncTracker, parameterArray);
}
}
}
/*
* Cross-browser helper function to add event handler
*/
function addEventListener(element, eventType, eventHandler, useCapture) {
if (element.addEventListener) {
element.addEventListener(eventType, eventHandler, useCapture);
return true;
}
if (element.attachEvent) {
return element.attachEvent('on' + eventType, eventHandler);
}
element['on' + eventType] = eventHandler;
}
/*
* Call plugin hook methods
*/
function executePluginMethod(methodName, callback) {
var result = '',
i,
pluginMethod;
for (i in plugins) {
if (Object.prototype.hasOwnProperty.call(plugins, i)) {
pluginMethod = plugins[i][methodName];
if (isFunction(pluginMethod)) {
result += pluginMethod(callback);
}
}
}
return result;
}
/*
* Handle beforeunload event
*
* Subject to Safari's "Runaway JavaScript Timer" and
* Chrome V8 extension that terminates JS that exhibits
* "slow unload", i.e., calling getTime() > 1000 times
*/
function beforeUnloadHandler() {
var now;
executePluginMethod('unload');
/*
* Delay/pause (blocks UI)
*/
if (expireDateTime) {
// the things we do for backwards compatibility...
// in ECMA-262 5th ed., we could simply use:
// while (Date.now() < expireDateTime) { }
do {
now = new Date();
} while (now.getTimeAlias() < expireDateTime);
}
}
/*
* Handler for onload event
*/
function loadHandler() {
var i;
if (!hasLoaded) {
hasLoaded = true;
executePluginMethod('load');
for (i = 0; i < registeredOnLoadHandlers.length; i++) {
registeredOnLoadHandlers[i]();
}
}
return true;
}
/*
* Add onload or DOM ready handler
*/
function addReadyListener() {
var _timer;
if (documentAlias.addEventListener) {
addEventListener(documentAlias, 'DOMContentLoaded', function ready() {
documentAlias.removeEventListener('DOMContentLoaded', ready, false);
loadHandler();
});
} else if (documentAlias.attachEvent) {
documentAlias.attachEvent('onreadystatechange', function ready() {
if (documentAlias.readyState === 'complete') {
documentAlias.detachEvent('onreadystatechange', ready);
loadHandler();
}
});
if (documentAlias.documentElement.doScroll && windowAlias === windowAlias.top) {
(function ready() {
if (!hasLoaded) {
try {
documentAlias.documentElement.doScroll('left');
} catch (error) {
setTimeout(ready, 0);
return;
}
loadHandler();
}
}());
}
}
// sniff for older WebKit versions
if ((new RegExp('WebKit')).test(navigatorAlias.userAgent)) {
_timer = setInterval(function () {
if (hasLoaded || /loaded|complete/.test(documentAlias.readyState)) {
clearInterval(_timer);
loadHandler();
}
}, 10);
}
// fallback
addEventListener(windowAlias, 'load', loadHandler, false);
}
/*
* Load JavaScript file (asynchronously)
*/
function loadScript(src, onLoad) {
var script = documentAlias.createElement('script');
script.type = 'text/javascript';
script.src = src;
if (script.readyState) {
script.onreadystatechange = function () {
var state = this.readyState;
if (state === 'loaded' || state === 'complete') {
script.onreadystatechange = null;
onLoad();
}
};
} else {
script.onload = onLoad;
}
documentAlias.getElementsByTagName('head')[0].appendChild(script);
}
/*
* Get page referrer
*/
function getReferrer() {
var referrer = '';
try {
referrer = windowAlias.top.document.referrer;
} catch (e) {
if (windowAlias.parent) {
try {
referrer = windowAlias.parent.document.referrer;
} catch (e2) {
referrer = '';
}
}
}
if (referrer === '') {
referrer = documentAlias.referrer;
}
return referrer;
}
/*
* Extract scheme/protocol from URL
*/
function getProtocolScheme(url) {
var e = new RegExp('^([a-z]+):'),
matches = e.exec(url);
return matches ? matches[1] : null;
}
/*
* Extract hostname from URL
*/
function getHostName(url) {
// scheme : // [username [: password] @] hostame [: port] [/ [path] [? query] [# fragment]]
var e = new RegExp('^(?:(?:https?|ftp):)/*(?:[^@]+@)?([^:/#]+)'),
matches = e.exec(url);
return matches ? matches[1] : url;
}
/*
* Extract parameter from URL
*/
function getParameter(url, name) {
var regexSearch = "[\\?&#]" + name + "=([^&#]*)";
var regex = new RegExp(regexSearch);
var results = regex.exec(url);
return results ? decodeWrapper(results[1]) : '';
}
/*
* UTF-8 encoding
*/
function utf8_encode(argString) {
return urldecode(encodeWrapper(argString));
}
/************************************************************
* sha1
* - based on sha1 from http://phpjs.org/functions/sha1:512 (MIT / GPL v2)
************************************************************/
function sha1(str) {
// + original by: Webtoolkit.info (http://www.webtoolkit.info/)
// + namespaced by: Michael White (http://getsprink.com)
// + input by: Brett Zamir (http://brett-zamir.me)
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + jslinted by: Anthon Pang (http://piwik.org)
var
rotate_left = function (n, s) {
return (n << s) | (n >>> (32 - s));
},
cvt_hex = function (val) {
var strout = '',
i,
v;
for (i = 7; i >= 0; i--) {
v = (val >>> (i * 4)) & 0x0f;
strout += v.toString(16);
}
return strout;
},
blockstart,
i,
j,
W = [],
H0 = 0x67452301,
H1 = 0xEFCDAB89,
H2 = 0x98BADCFE,
H3 = 0x10325476,
H4 = 0xC3D2E1F0,
A,
B,
C,
D,
E,
temp,
str_len,
word_array = [];
str = utf8_encode(str);
str_len = str.length;
for (i = 0; i < str_len - 3; i += 4) {
j = str.charCodeAt(i) << 24 | str.charCodeAt(i + 1) << 16 |
str.charCodeAt(i + 2) << 8 | str.charCodeAt(i + 3);
word_array.push(j);
}
switch (str_len & 3) {
case 0:
i = 0x080000000;
break;
case 1:
i = str.charCodeAt(str_len - 1) << 24 | 0x0800000;
break;
case 2:
i = str.charCodeAt(str_len - 2) << 24 | str.charCodeAt(str_len - 1) << 16 | 0x08000;
break;
case 3:
i = str.charCodeAt(str_len - 3) << 24 | str.charCodeAt(str_len - 2) << 16 | str.charCodeAt(str_len - 1) << 8 | 0x80;
break;
}
word_array.push(i);
while ((word_array.length & 15) !== 14) {
word_array.push(0);
}
word_array.push(str_len >>> 29);
word_array.push((str_len << 3) & 0x0ffffffff);
for (blockstart = 0; blockstart < word_array.length; blockstart += 16) {
for (i = 0; i < 16; i++) {
W[i] = word_array[blockstart + i];
}
for (i = 16; i <= 79; i++) {
W[i] = rotate_left(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1);
}
A = H0;
B = H1;
C = H2;
D = H3;
E = H4;
for (i = 0; i <= 19; i++) {
temp = (rotate_left(A, 5) + ((B & C) | (~B & D)) + E + W[i] + 0x5A827999) & 0x0ffffffff;
E = D;
D = C;
C = rotate_left(B, 30);
B = A;
A = temp;
}
for (i = 20; i <= 39; i++) {
temp = (rotate_left(A, 5) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1) & 0x0ffffffff;
E = D;
D = C;
C = rotate_left(B, 30);
B = A;
A = temp;
}
for (i = 40; i <= 59; i++) {
temp = (rotate_left(A, 5) + ((B & C) | (B & D) | (C & D)) + E + W[i] + 0x8F1BBCDC) & 0x0ffffffff;
E = D;
D = C;
C = rotate_left(B, 30);
B = A;
A = temp;
}
for (i = 60; i <= 79; i++) {
temp = (rotate_left(A, 5) + (B ^ C ^ D) + E + W[i] + 0xCA62C1D6) & 0x0ffffffff;
E = D;
D = C;
C = rotate_left(B, 30);
B = A;
A = temp;
}
H0 = (H0 + A) & 0x0ffffffff;
H1 = (H1 + B) & 0x0ffffffff;
H2 = (H2 + C) & 0x0ffffffff;
H3 = (H3 + D) & 0x0ffffffff;
H4 = (H4 + E) & 0x0ffffffff;
}
temp = cvt_hex(H0) + cvt_hex(H1) + cvt_hex(H2) + cvt_hex(H3) + cvt_hex(H4);
return temp.toLowerCase();
}
/************************************************************
* end sha1
************************************************************/
/*
* Fix-up URL when page rendered from search engine cache or translated page
*/
function urlFixup(hostName, href, referrer) {
if (hostName === 'translate.googleusercontent.com') { // Google
if (referrer === '') {
referrer = href;
}
href = getParameter(href, 'u');
hostName = getHostName(href);
} else if (hostName === 'cc.bingj.com' || // Bing
hostName === 'webcache.googleusercontent.com' || // Google
hostName.slice(0, 5) === '74.6.') { // Yahoo (via Inktomi 74.6.0.0/16)
href = documentAlias.links[0].href;
hostName = getHostName(href);
}
return [hostName, href, referrer];
}
/*
* Fix-up domain
*/
function domainFixup(domain) {
var dl = domain.length;
// remove trailing '.'
if (domain.charAt(--dl) === '.') {
domain = domain.slice(0, dl);
}
// remove leading '*'
if (domain.slice(0, 2) === '*.') {
domain = domain.slice(1);
}
return domain;
}
/*
* Title fixup
*/
function titleFixup(title) {
title = title && title.text ? title.text : title;
if (!isString(title)) {
var tmp = documentAlias.getElementsByTagName('title');
if (tmp && isDefined(tmp[0])) {
title = tmp[0].text;
}
}
return title;
}
function getChildrenFromNode(node)
{
if (!node) {
return [];
}
if (!isDefined(node.children) && isDefined(node.childNodes)) {
return node.children;
}
if (isDefined(node.children)) {
return node.children;
}
return [];
}
function containsNodeElement(node, containedNode)
{
if (!node || !containedNode) {
return false;
}
if (node.contains) {
return node.contains(containedNode);
}
if (node === containedNode) {
return true;
}
if (node.compareDocumentPosition) {
return !!(node.compareDocumentPosition(containedNode) & 16);
}
return false;
}
// Polyfill for IndexOf for IE6-IE8
function indexOfArray(theArray, searchElement)
{
if (theArray && theArray.indexOf) {
return theArray.indexOf(searchElement);
}
// 1. Let O be the result of calling ToObject passing
// the this value as the argument.
if (!isDefined(theArray) || theArray === null) {
return -1;
}
if (!theArray.length) {
return -1;
}
var len = theArray.length;
if (len === 0) {
return -1;
}
var k = 0;
// 9. Repeat, while k < len
while (k < len) {
// a. Let Pk be ToString(k).
// This is implicit for LHS operands of the in operator
// b. Let kPresent be the result of calling the
// HasProperty internal method of O with argument Pk.
// This step can be combined with c
// c. If kPresent is true, then
// i. Let elementK be the result of calling the Get
// internal method of O with the argument ToString(k).
// ii. Let same be the result of applying the
// Strict Equality Comparison Algorithm to
// searchElement and elementK.
// iii. If same is true, return k.
if (theArray[k] === searchElement) {
return k;
}
k++;
}
return -1;
}
/************************************************************
* Element Visiblility
************************************************************/
/**
* Author: Jason Farrell
* Author URI: http://useallfive.com/
*
* Description: Checks if a DOM element is truly visible.
* Package URL: https://github.com/UseAllFive/true-visibility
* License: MIT (https://github.com/UseAllFive/true-visibility/blob/master/LICENSE.txt)
*/
function isVisible(node) {
if (!node) {
return false;
}
//-- Cross browser method to get style properties:
function _getStyle(el, property) {
if (windowAlias.getComputedStyle) {
return documentAlias.defaultView.getComputedStyle(el,null)[property];
}
if (el.currentStyle) {
return el.currentStyle[property];
}
}
function _elementInDocument(element) {
element = element.parentNode;
while (element) {
if (element === documentAlias) {
return true;
}
element = element.parentNode;
}
return false;
}
/**
* Checks if a DOM element is visible. Takes into
* consideration its parents and overflow.
*
* @param (el) the DOM element to check if is visible
*
* These params are optional that are sent in recursively,
* you typically won't use these:
*
* @param (t) Top corner position number
* @param (r) Right corner position number
* @param (b) Bottom corner position number
* @param (l) Left corner position number
* @param (w) Element width number
* @param (h) Element height number
*/
function _isVisible(el, t, r, b, l, w, h) {
var p = el.parentNode,
VISIBLE_PADDING = 1; // has to be visible at least one px of the element
if (!_elementInDocument(el)) {
return false;
}
//-- Return true for document node
if (9 === p.nodeType) {
return true;
}
//-- Return false if our element is invisible
if (
'0' === _getStyle(el, 'opacity') ||
'none' === _getStyle(el, 'display') ||
'hidden' === _getStyle(el, 'visibility')
) {
return false;
}
if (!isDefined(t) ||
!isDefined(r) ||
!isDefined(b) ||
!isDefined(l) ||
!isDefined(w) ||
!isDefined(h)) {
t = el.offsetTop;
l = el.offsetLeft;
b = t + el.offsetHeight;
r = l + el.offsetWidth;
w = el.offsetWidth;
h = el.offsetHeight;
}
if (node === el && (0 === h || 0 === w) && 'hidden' === _getStyle(el, 'overflow')) {
return false;
}
//-- If we have a parent, let's continue:
if (p) {
//-- Check if the parent can hide its children.
if (('hidden' === _getStyle(p, 'overflow') || 'scroll' === _getStyle(p, 'overflow'))) {
//-- Only check if the offset is different for the parent
if (
//-- If the target element is to the right of the parent elm
l + VISIBLE_PADDING > p.offsetWidth + p.scrollLeft ||
//-- If the target element is to the left of the parent elm
l + w - VISIBLE_PADDING < p.scrollLeft ||
//-- If the target element is under the parent elm
t + VISIBLE_PADDING > p.offsetHeight + p.scrollTop ||
//-- If the target element is above the parent elm
t + h - VISIBLE_PADDING < p.scrollTop
) {
//-- Our target element is out of bounds:
return false;
}
}
//-- Add the offset parent's left/top coords to our element's offset:
if (el.offsetParent === p) {
l += p.offsetLeft;
t += p.offsetTop;
}
//-- Let's recursively check upwards:
return _isVisible(p, t, r, b, l, w, h);
}
return true;
}
return _isVisible(node);
}
/************************************************************
* Query
************************************************************/
var query = {
htmlCollectionToArray: function (foundNodes)
{
var nodes = [], index;
if (!foundNodes || !foundNodes.length) {
return nodes;
}
for (index = 0; index < foundNodes.length; index++) {
nodes.push(foundNodes[index]);
}
return nodes;
},
find: function (selector)
{
// we use querySelectorAll only on document, not on nodes because of its unexpected behavior. See for
// instance http://stackoverflow.com/questions/11503534/jquery-vs-document-queryselectorall and
// http://jsfiddle.net/QdMc5/ and http://ejohn.org/blog/thoughts-on-queryselectorall
if (!document.querySelectorAll || !selector) {
return []; // we do not support all browsers
}
var foundNodes = document.querySelectorAll(selector);
return this.htmlCollectionToArray(foundNodes);
},
findMultiple: function (selectors)
{
if (!selectors || !selectors.length) {
return [];
}
var index, foundNodes;
var nodes = [];
for (index = 0; index < selectors.length; index++) {
foundNodes = this.find(selectors[index]);
nodes = nodes.concat(foundNodes);
}
nodes = this.makeNodesUnique(nodes);
return nodes;
},
findNodesByTagName: function (node, tagName)
{
if (!node || !tagName || !node.getElementsByTagName) {
return [];
}
var foundNodes = node.getElementsByTagName(tagName);
return this.htmlCollectionToArray(foundNodes);
},
makeNodesUnique: function (nodes)
{
var copy = [].concat(nodes);
nodes.sort(function(n1, n2){
if (n1 === n2) {
return 0;
}
var index1 = indexOfArray(copy, n1);
var index2 = indexOfArray(copy, n2);
if (index1 === index2) {
return 0;
}
return index1 > index2 ? -1 : 1;
});
if (nodes.length <= 1) {
return nodes;
}
var index = 0;
var numDuplicates = 0;
var duplicates = [];
var node;
node = nodes[index++];
while (node) {
if (node === nodes[index]) {
numDuplicates = duplicates.push(index);
}
node = nodes[index++] || null;
}
while (numDuplicates--) {
nodes.splice(duplicates[numDuplicates], 1);
}
return nodes;
},
getAttributeValueFromNode: function (node, attributeName)
{
if (!this.hasNodeAttribute(node, attributeName)) {
return;
}
if (node && node.getAttribute) {
return node.getAttribute(attributeName);
}
if (!node || !node.attributes) {
return;
}
var typeOfAttr = (typeof node.attributes[attributeName]);
if ('undefined' === typeOfAttr) {
return;
}
if (node.attributes[attributeName].value) {
return node.attributes[attributeName].value; // nodeValue is deprecated ie Chrome
}
if (node.attributes[attributeName].nodeValue) {
return node.attributes[attributeName].nodeValue;
}
var index;
var attrs = node.attributes;
if (!attrs) {
return;
}
for (index = 0; index < attrs.length; index++) {
if (attrs[index].nodeName === attributeName) {
return attrs[index].nodeValue;
}
}
return null;
},
hasNodeAttributeWithValue: function (node, attributeName)
{
var value = this.getAttributeValueFromNode(node, attributeName);
return !!value;
},
hasNodeAttribute: function (node, attributeName)
{
if (node && node.hasAttribute) {
return node.hasAttribute(attributeName);
}
if (node && node.attributes) {
var typeOfAttr = (typeof node.attributes[attributeName]);
return 'undefined' !== typeOfAttr;
}
return false;
},
hasNodeCssClass: function (node, className)
{
if (node && className && node.className) {
var classes = node.className.split(' ');
if (-1 !== indexOfArray(classes, className)) {
return true;
}
}
return false;
},
findNodesHavingAttribute: function (nodeToSearch, attributeName, nodes)
{
if (!nodes) {
nodes = [];
}
if (!nodeToSearch || !attributeName) {
return nodes;
}
var children = getChildrenFromNode(nodeToSearch);
if (!children || !children.length) {
return nodes;
}
var index, child;
for (index = 0; index < children.length; index++) {
child = children[index];
if (this.hasNodeAttribute(child, attributeName)) {
nodes.push(child);
}
nodes = this.findNodesHavingAttribute(child, attributeName, nodes);
}
return nodes;
},
findFirstNodeHavingAttribute: function (node, attributeName)
{
if (!node || !attributeName) {
return;
}
if (this.hasNodeAttribute(node, attributeName)) {
return node;
}
var nodes = this.findNodesHavingAttribute(node, attributeName);
if (nodes && nodes.length) {
return nodes[0];
}
},
findFirstNodeHavingAttributeWithValue: function (node, attributeName)
{
if (!node || !attributeName) {
return;
}
if (this.hasNodeAttributeWithValue(node, attributeName)) {
return node;
}
var nodes = this.findNodesHavingAttribute(node, attributeName);
if (!nodes || !nodes.length) {
return;
}
var index;
for (index = 0; index < nodes.length; index++) {
if (this.getAttributeValueFromNode(nodes[index], attributeName)) {
return nodes[index];
}
}
},
findNodesHavingCssClass: function (nodeToSearch, className, nodes)
{
if (!nodes) {
nodes = [];
}
if (!nodeToSearch || !className) {
return nodes;
}
if (nodeToSearch.getElementsByClassName) {
var foundNodes = nodeToSearch.getElementsByClassName(className);
return this.htmlCollectionToArray(foundNodes);
}
var children = getChildrenFromNode(nodeToSearch);
if (!children || !children.length) {
return [];
}
var index, child;
for (index = 0; index < children.length; index++) {
child = children[index];
if (this.hasNodeCssClass(child, className)) {
nodes.push(child);
}
nodes = this.findNodesHavingCssClass(child, className, nodes);
}
return nodes;
},
findFirstNodeHavingClass: function (node, className)
{
if (!node || !className) {
return;
}
if (this.hasNodeCssClass(node, className)) {
return node;
}
var nodes = this.findNodesHavingCssClass(node, className);
if (nodes && nodes.length) {
return nodes[0];
}
},
isLinkElement: function (node)
{
if (!node) {
return false;
}
var elementName = String(node.nodeName).toLowerCase();
var linkElementNames = ['a', 'area'];
var pos = indexOfArray(linkElementNames, elementName);
return pos !== -1;
},
setAnyAttribute: function (node, attrName, attrValue)
{
if (!node || !attrName) {
return;
}
if (node.setAttribute) {
node.setAttribute(attrName, attrValue);
} else {
node[attrName] = attrValue;
}
}
};
/************************************************************
* Content Tracking
************************************************************/
var content = {
CONTENT_ATTR: 'data-track-content',
CONTENT_CLASS: 'piwikTrackContent',
CONTENT_NAME_ATTR: 'data-content-name',
CONTENT_PIECE_ATTR: 'data-content-piece',
CONTENT_PIECE_CLASS: 'piwikContentPiece',
CONTENT_TARGET_ATTR: 'data-content-target',
CONTENT_TARGET_CLASS: 'piwikContentTarget',
CONTENT_IGNOREINTERACTION_ATTR: 'data-content-ignoreinteraction',
CONTENT_IGNOREINTERACTION_CLASS: 'piwikContentIgnoreInteraction',
location: undefined,
findContentNodes: function ()
{
var cssSelector = '.' + this.CONTENT_CLASS;
var attrSelector = '[' + this.CONTENT_ATTR + ']';
var contentNodes = query.findMultiple([cssSelector, attrSelector]);
return contentNodes;
},
findContentNodesWithinNode: function (node)
{
if (!node) {
return [];
}
// NOTE: we do not use query.findMultiple here as querySelectorAll would most likely not deliver the result we want
var nodes1 = query.findNodesHavingCssClass(node, this.CONTENT_CLASS);
var nodes2 = query.findNodesHavingAttribute(node, this.CONTENT_ATTR);
if (nodes2 && nodes2.length) {
var index;
for (index = 0; index < nodes2.length; index++) {
nodes1.push(nodes2[index]);
}
}
if (query.hasNodeAttribute(node, this.CONTENT_ATTR)) {
nodes1.push(node);
} else if (query.hasNodeCssClass(node, this.CONTENT_CLASS)) {
nodes1.push(node);
}
nodes1 = query.makeNodesUnique(nodes1);
return nodes1;
},
findParentContentNode: function (anyNode)
{
if (!anyNode) {
return;
}
var node = anyNode;
var counter = 0;
while (node && node !== documentAlias && node.parentNode) {
if (query.hasNodeAttribute(node, this.CONTENT_ATTR)) {
return node;
}
if (query.hasNodeCssClass(node, this.CONTENT_CLASS)) {
return node;
}
node = node.parentNode;
if (counter > 1000) {
break; // prevent loop, should not happen anyway but better we do this
}
counter++;
}
},
findPieceNode: function (node)
{
var contentPiece;
contentPiece = query.findFirstNodeHavingAttribute(node, this.CONTENT_PIECE_ATTR);
if (!contentPiece) {
contentPiece = query.findFirstNodeHavingClass(node, this.CONTENT_PIECE_CLASS);
}
if (contentPiece) {
return contentPiece;
}
return node;
},
findTargetNodeNoDefault: function (node)
{
if (!node) {
return;
}
var target = query.findFirstNodeHavingAttributeWithValue(node, this.CONTENT_TARGET_ATTR);
if (target) {
return target;
}
target = query.findFirstNodeHavingAttribute(node, this.CONTENT_TARGET_ATTR);
if (target) {
return target;
}
target = query.findFirstNodeHavingClass(node, this.CONTENT_TARGET_CLASS);
if (target) {
return target;
}
},
findTargetNode: function (node)
{
var target = this.findTargetNodeNoDefault(node);
if (target) {
return target;
}
return node;
},
findContentName: function (node)
{
if (!node) {
return;
}
var nameNode = query.findFirstNodeHavingAttributeWithValue(node, this.CONTENT_NAME_ATTR);
if (nameNode) {
return query.getAttributeValueFromNode(nameNode, this.CONTENT_NAME_ATTR);
}
var contentPiece = this.findContentPiece(node);
if (contentPiece) {
return this.removeDomainIfIsInLink(contentPiece);
}
if (query.hasNodeAttributeWithValue(node, 'title')) {
return query.getAttributeValueFromNode(node, 'title');
}
var clickUrlNode = this.findPieceNode(node);
if (query.hasNodeAttributeWithValue(clickUrlNode, 'title')) {
return query.getAttributeValueFromNode(clickUrlNode, 'title');
}
var targetNode = this.findTargetNode(node);
if (query.hasNodeAttributeWithValue(targetNode, 'title')) {
return query.getAttributeValueFromNode(targetNode, 'title');
}
},
findContentPiece: function (node)
{
if (!node) {
return;
}
var nameNode = query.findFirstNodeHavingAttributeWithValue(node, this.CONTENT_PIECE_ATTR);
if (nameNode) {
return query.getAttributeValueFromNode(nameNode, this.CONTENT_PIECE_ATTR);
}
var contentNode = this.findPieceNode(node);
var media = this.findMediaUrlInNode(contentNode);
if (media) {
return this.toAbsoluteUrl(media);
}
},
findContentTarget: function (node)
{
if (!node) {
return;
}
var targetNode = this.findTargetNode(node);
if (query.hasNodeAttributeWithValue(targetNode, this.CONTENT_TARGET_ATTR)) {
return query.getAttributeValueFromNode(targetNode, this.CONTENT_TARGET_ATTR);
}
var href;
if (query.hasNodeAttributeWithValue(targetNode, 'href')) {
href = query.getAttributeValueFromNode(targetNode, 'href');
return this.toAbsoluteUrl(href);
}
var contentNode = this.findPieceNode(node);
if (query.hasNodeAttributeWithValue(contentNode, 'href')) {
href = query.getAttributeValueFromNode(contentNode, 'href');
return this.toAbsoluteUrl(href);
}
},
isSameDomain: function (url)
{
if (!url || !url.indexOf) {
return false;
}
if (0 === url.indexOf(this.getLocation().origin)) {
return true;
}
var posHost = url.indexOf(this.getLocation().host);
if (8 >= posHost && 0 <= posHost) {
return true;
}
return false;
},
removeDomainIfIsInLink: function (text)
{
// we will only remove if domain === location.origin meaning is not an outlink
var regexContainsProtocol = '^https?:\/\/[^\/]+';
var regexReplaceDomain = '^.*\/\/[^\/]+';
if (text &&
text.search &&
-1 !== text.search(new RegExp(regexContainsProtocol))
&& this.isSameDomain(text)) {
text = text.replace(new RegExp(regexReplaceDomain), '');
if (!text) {
text = '/';
}
}
return text;
},
findMediaUrlInNode: function (node)
{
if (!node) {
return;
}
var mediaElements = ['img', 'embed', 'video', 'audio'];
var elementName = node.nodeName.toLowerCase();
if (-1 !== indexOfArray(mediaElements, elementName) &&
query.findFirstNodeHavingAttributeWithValue(node, 'src')) {
var sourceNode = query.findFirstNodeHavingAttributeWithValue(node, 'src');
return query.getAttributeValueFromNode(sourceNode, 'src');
}
if (elementName === 'object' &&
query.hasNodeAttributeWithValue(node, 'data')) {
return query.getAttributeValueFromNode(node, 'data');
}
if (elementName === 'object') {
var params = query.findNodesByTagName(node, 'param');
if (params && params.length) {
var index;
for (index = 0; index < params.length; index++) {
if ('movie' === query.getAttributeValueFromNode(params[index], 'name') &&
query.hasNodeAttributeWithValue(params[index], 'value')) {
return query.getAttributeValueFromNode(params[index], 'value');
}
}
}
var embed = query.findNodesByTagName(node, 'embed');
if (embed && embed.length) {
return this.findMediaUrlInNode(embed[0]);
}
}
},
trim: function (text)
{
if (text && String(text) === text) {
return text.replace(/^\s+|\s+$/g, '');
}
return text;
},
isOrWasNodeInViewport: function (node)
{
if (!node || !node.getBoundingClientRect || node.nodeType !== 1) {
return true;
}
var rect = node.getBoundingClientRect();
var html = documentAlias.documentElement || {};
var wasVisible = rect.top < 0;
if (wasVisible && node.offsetTop) {
wasVisible = (node.offsetTop + rect.height) > 0;
}
var docWidth = html.clientWidth; // The clientWidth attribute returns the viewport width excluding the size of a rendered scroll bar
if (windowAlias.innerWidth && docWidth > windowAlias.innerWidth) {
docWidth = windowAlias.innerWidth; // The innerWidth attribute must return the viewport width including the size of a rendered scroll bar
}
var docHeight = html.clientHeight; // The clientWidth attribute returns the viewport width excluding the size of a rendered scroll bar
if (windowAlias.innerHeight && docHeight > windowAlias.innerHeight) {
docHeight = windowAlias.innerHeight; // The innerWidth attribute must return the viewport width including the size of a rendered scroll bar
}
return (
(rect.bottom > 0 || wasVisible) &&
rect.right > 0 &&
rect.left < docWidth &&
((rect.top < docHeight) || wasVisible) // rect.top < 0 we assume user has seen all the ones that are above the current viewport
);
},
isNodeVisible: function (node)
{
var isItVisible = isVisible(node);
var isInViewport = this.isOrWasNodeInViewport(node);
return isItVisible && isInViewport;
},
buildInteractionRequestParams: function (interaction, name, piece, target)
{
var params = '';
if (interaction) {
params += 'c_i='+ encodeWrapper(interaction);
}
if (name) {
if (params) {
params += '&';
}
params += 'c_n='+ encodeWrapper(name);
}
if (piece) {
if (params) {
params += '&';
}
params += 'c_p='+ encodeWrapper(piece);
}
if (target) {
if (params) {
params += '&';
}
params += 'c_t='+ encodeWrapper(target);
}
return params;
},
buildImpressionRequestParams: function (name, piece, target)
{
var params = 'c_n=' + encodeWrapper(name) +
'&c_p=' + encodeWrapper(piece);
if (target) {
params += '&c_t=' + encodeWrapper(target);
}
return params;
},
buildContentBlock: function (node)
{
if (!node) {
return;
}
var name = this.findContentName(node);
var piece = this.findContentPiece(node);
var target = this.findContentTarget(node);
name = this.trim(name);
piece = this.trim(piece);
target = this.trim(target);
return {
name: name || 'Unknown',
piece: piece || 'Unknown',
target: target || ''
};
},
collectContent: function (contentNodes)
{
if (!contentNodes || !contentNodes.length) {
return [];
}
var contents = [];
var index, contentBlock;
for (index = 0; index < contentNodes.length; index++) {
contentBlock = this.buildContentBlock(contentNodes[index]);
if (isDefined(contentBlock)) {
contents.push(contentBlock);
}
}
return contents;
},
setLocation: function (location)
{
this.location = location;
},
getLocation: function ()
{
var locationAlias = this.location || windowAlias.location;
if (!locationAlias.origin) {
locationAlias.origin = locationAlias.protocol + "//" + locationAlias.hostname + (locationAlias.port ? ':' + locationAlias.port: '');
}
return locationAlias;
},
toAbsoluteUrl: function (url)
{
if ((!url || String(url) !== url) && url !== '') {
// we only handle strings
return url;
}
if ('' === url) {
return this.getLocation().href;
}
// Eg //example.com/test.jpg
if (url.search(/^\/\//) !== -1) {
return this.getLocation().protocol + url;
}
// Eg http://example.com/test.jpg
if (url.search(/:\/\//) !== -1) {
return url;
}
// Eg #test.jpg
if (0 === url.indexOf('#')) {
return this.getLocation().origin + this.getLocation().pathname + url;
}
// Eg ?x=5
if (0 === url.indexOf('?')) {
return this.getLocation().origin + this.getLocation().pathname + url;
}
// Eg mailto:x@y.z tel:012345, ... market:... sms:..., javasript:... ecmascript: ... and many more
if (0 === url.search('^[a-zA-Z]{2,11}:')) {
return url;
}
// Eg /test.jpg
if (url.search(/^\//) !== -1) {
return this.getLocation().origin + url;
}
// Eg test.jpg
var regexMatchDir = '(.*\/)';
var base = this.getLocation().origin + this.getLocation().pathname.match(new RegExp(regexMatchDir))[0];
return base + url;
},
isUrlToCurrentDomain: function (url) {
var absoluteUrl = this.toAbsoluteUrl(url);
if (!absoluteUrl) {
return false;
}
var origin = this.getLocation().origin;
if (origin === absoluteUrl) {
return true;
}
if (0 === String(absoluteUrl).indexOf(origin)) {
if (':' === String(absoluteUrl).substr(origin.length, 1)) {
return false; // url has port whereas origin has not => different URL
}
return true;
}
return false;
},
setHrefAttribute: function (node, url)
{
if (!node || !url) {
return;
}
query.setAnyAttribute(node, 'href', url);
},
shouldIgnoreInteraction: function (targetNode)
{
var hasAttr = query.hasNodeAttribute(targetNode, this.CONTENT_IGNOREINTERACTION_ATTR);
var hasClass = query.hasNodeCssClass(targetNode, this.CONTENT_IGNOREINTERACTION_CLASS);
return hasAttr || hasClass;
}
};
/************************************************************
* Page Overlay
************************************************************/
function getPiwikUrlForOverlay(trackerUrl, apiUrl) {
if (apiUrl) {
return apiUrl;
}
if (trackerUrl.slice(-9) === 'piwik.php') {
trackerUrl = trackerUrl.slice(0, trackerUrl.length - 9);
}
return trackerUrl;
}
/*
* Check whether this is a page overlay session
*
* @return boolean
*
* {@internal side-effect: modifies window.name }}
*/
function isOverlaySession(configTrackerSiteId) {
var windowName = 'Piwik_Overlay';
// check whether we were redirected from the piwik overlay plugin
var referrerRegExp = new RegExp('index\\.php\\?module=Overlay&action=startOverlaySession'
+ '&idSite=([0-9]+)&period=([^&]+)&date=([^&]+)$');
var match = referrerRegExp.exec(documentAlias.referrer);
if (match) {
// check idsite
var idsite = match[1];
if (idsite !== String(configTrackerSiteId)) {
return false;
}
// store overlay session info in window name
var period = match[2],
date = match[3];
windowAlias.name = windowName + '###' + period + '###' + date;
}
// retrieve and check data from window name
var windowNameParts = windowAlias.name.split('###');
return windowNameParts.length === 3 && windowNameParts[0] === windowName;
}
/*
* Inject the script needed for page overlay
*/
function injectOverlayScripts(configTrackerUrl, configApiUrl, configTrackerSiteId) {
var windowNameParts = windowAlias.name.split('###'),
period = windowNameParts[1],
date = windowNameParts[2],
piwikUrl = getPiwikUrlForOverlay(configTrackerUrl, configApiUrl);
loadScript(
piwikUrl + 'plugins/Overlay/client/client.js?v=1',
function () {
Piwik_Overlay_Client.initialize(piwikUrl, configTrackerSiteId, period, date);
}
);
}
/************************************************************
* End Page Overlay
************************************************************/
/*
* Piwik Tracker class
*
* trackerUrl and trackerSiteId are optional arguments to the constructor
*
* See: Tracker.setTrackerUrl() and Tracker.setSiteId()
*/
function Tracker(trackerUrl, siteId, uuid) {
/************************************************************
* Private members
************************************************************/
var
/*<DEBUG>*/
/*
* registered test hooks
*/
registeredHooks = {},
/*</DEBUG>*/
// Current URL and Referrer URL
locationArray = urlFixup(documentAlias.domain, windowAlias.location.href, getReferrer()),
domainAlias = domainFixup(locationArray[0]),
locationHrefAlias = locationArray[1],
configReferrerUrl = locationArray[2],
enableJSErrorTracking = false,
defaultRequestMethod = 'GET',
// Request method (GET or POST)
configRequestMethod = defaultRequestMethod,
defaultRequestContentType = 'application/x-www-form-urlencoded; charset=UTF-8',
// Request Content-Type header value; applicable when POST request method is used for submitting tracking events
configRequestContentType = defaultRequestContentType,
// Tracker URL
configTrackerUrl = trackerUrl || '',
// API URL (only set if it differs from the Tracker URL)
configApiUrl = '',
// This string is appended to the Tracker URL Request (eg. to send data that is not handled by the existing setters/getters)
configAppendToTrackingUrl = '',
// Site ID
configTrackerSiteId = siteId || '',
// User ID
configUserId = '',
// Document URL
configCustomUrl,
// Document title
configTitle = documentAlias.title,
// Extensions to be treated as download links
configDownloadExtensions = '7z|aac|apk|ar[cj]|as[fx]|avi|azw3|bin|csv|deb|dmg|docx?|epub|exe|flv|gif|gz|gzip|hqx|jar|jpe?g|js|mobi|mp(2|3|4|e?g)|mov(ie)?|ms[ip]|od[bfgpst]|og[gv]|pdf|phps|png|pptx?|qtm?|ra[mr]?|rpm|sea|sit|tar|t?bz2?|tgz|torrent|txt|wav|wm[av]|wpd||xlsx?|xml|z|zip',
// Hosts or alias(es) to not treat as outlinks
configHostsAlias = [domainAlias],
// HTML anchor element classes to not track
configIgnoreClasses = [],
// HTML anchor element classes to treat as downloads
configDownloadClasses = [],
// HTML anchor element classes to treat at outlinks
configLinkClasses = [],
// Maximum delay to wait for web bug image to be fetched (in milliseconds)
configTrackerPause = 500,
// Minimum visit time after initial page view (in milliseconds)
configMinimumVisitTime,
// Recurring heart beat after initial ping (in milliseconds)
configHeartBeatTimer,
// Disallow hash tags in URL
configDiscardHashTag,
// Custom data
configCustomData,
// Campaign names
configCampaignNameParameters = [ 'pk_campaign', 'piwik_campaign', 'utm_campaign', 'utm_source', 'utm_medium' ],
// Campaign keywords
configCampaignKeywordParameters = [ 'pk_kwd', 'piwik_kwd', 'utm_term' ],
// First-party cookie name prefix
configCookieNamePrefix = '_pk_',
// First-party cookie domain
// User agent defaults to origin hostname
configCookieDomain,
// First-party cookie path
// Default is user agent defined.
configCookiePath,
// Cookies are disabled
configCookiesDisabled = false,
// Do Not Track
configDoNotTrack,
// Count sites which are pre-rendered
configCountPreRendered,
// Do we attribute the conversion to the first referrer or the most recent referrer?
configConversionAttributionFirstReferrer,
// Life of the visitor cookie (in milliseconds)
configVisitorCookieTimeout = 33955200000, // 13 months (365 days + 28days)
// Life of the session cookie (in milliseconds)
configSessionCookieTimeout = 1800000, // 30 minutes
// Life of the referral cookie (in milliseconds)
configReferralCookieTimeout = 15768000000, // 6 months
// Is performance tracking enabled
configPerformanceTrackingEnabled = true,
// Generation time set from the server
configPerformanceGenerationTime = 0,
// Whether Custom Variables scope "visit" should be stored in a cookie during the time of the visit
configStoreCustomVariablesInCookie = false,
// Custom Variables read from cookie, scope "visit"
customVariables = false,
configCustomRequestContentProcessing,
// Custom Variables, scope "page"
customVariablesPage = {},
// Custom Variables, scope "event"
customVariablesEvent = {},
// Custom Variables names and values are each truncated before being sent in the request or recorded in the cookie
customVariableMaximumLength = 200,
// Ecommerce items
ecommerceItems = {},
// Browser features via client-side data collection
browserFeatures = {},
// Keeps track of previously tracked content impressions
trackedContentImpressions = [],
isTrackOnlyVisibleContentEnabled = false,
// Guard to prevent empty visits see #6415. If there is a new visitor and the first 2 (or 3 or 4)
// tracking requests are at nearly same time (eg trackPageView and trackContentImpression) 2 or more
// visits will be created
timeNextTrackingRequestCanBeExecutedImmediately = false,
// Guard against installing the link tracker more than once per Tracker instance
linkTrackingInstalled = false,
linkTrackingEnabled = false,
// Guard against installing the activity tracker more than once per Tracker instance
activityTrackingInstalled = false,
// Last activity timestamp
lastActivityTime,
// Internal state of the pseudo click handler
lastButton,
lastTarget,
// Hash function
hash = sha1,
// Domain hash value
domainHash,
// Visitor UUID
visitorUUID = uuid;
/*
* Set cookie value
*/
function setCookie(cookieName, value, msToExpire, path, domain, secure) {
if (configCookiesDisabled) {
return;
}
var expiryDate;
// relative time to expire in milliseconds
if (msToExpire) {
expiryDate = new Date();
expiryDate.setTime(expiryDate.getTime() + msToExpire);
}
documentAlias.cookie = cookieName + '=' + encodeWrapper(value) +
(msToExpire ? ';expires=' + expiryDate.toGMTString() : '') +
';path=' + (path || '/') +
(domain ? ';domain=' + domain : '') +
(secure ? ';secure' : '');
}
/*
* Get cookie value
*/
function getCookie(cookieName) {
if (configCookiesDisabled) {
return 0;
}
var cookiePattern = new RegExp('(^|;)[ ]*' + cookieName + '=([^;]*)'),
cookieMatch = cookiePattern.exec(documentAlias.cookie);
return cookieMatch ? decodeWrapper(cookieMatch[2]) : 0;
}
/*
* Removes hash tag from the URL
*
* URLs are purified before being recorded in the cookie,
* or before being sent as GET parameters
*/
function purify(url) {
var targetPattern;
if (configDiscardHashTag) {
targetPattern = new RegExp('#.*');
return url.replace(targetPattern, '');
}
return url;
}
/*
* Resolve relative reference
*
* Note: not as described in rfc3986 section 5.2
*/
function resolveRelativeReference(baseUrl, url) {
var protocol = getProtocolScheme(url),
i;
if (protocol) {
return url;
}
if (url.slice(0, 1) === '/') {
return getProtocolScheme(baseUrl) + '://' + getHostName(baseUrl) + url;
}
baseUrl = purify(baseUrl);
i = baseUrl.indexOf('?');
if (i >= 0) {
baseUrl = baseUrl.slice(0, i);
}
i = baseUrl.lastIndexOf('/');
if (i !== baseUrl.length - 1) {
baseUrl = baseUrl.slice(0, i + 1);
}
return baseUrl + url;
}
/*
* Is the host local? (i.e., not an outlink)
*/
function isSiteHostName(hostName) {
var i,
alias,
offset;
for (i = 0; i < configHostsAlias.length; i++) {
alias = domainFixup(configHostsAlias[i].toLowerCase());
if (hostName === alias) {
return true;
}
if (alias.slice(0, 1) === '.') {
if (hostName === alias.slice(1)) {
return true;
}
offset = hostName.length - alias.length;
if ((offset > 0) && (hostName.slice(offset) === alias)) {
return true;
}
}
}
return false;
}
/*
* Send image request to Piwik server using GET.
* The infamous web bug (or beacon) is a transparent, single pixel (1x1) image
*/
function getImage(request, callback) {
var image = new Image(1, 1);
image.onload = function () {
iterator = 0; // To avoid JSLint warning of empty block
if (typeof callback === 'function') { callback(); }
};
image.src = configTrackerUrl + (configTrackerUrl.indexOf('?') < 0 ? '?' : '&') + request;
}
/*
* POST request to Piwik server using XMLHttpRequest.
*/
function sendXmlHttpRequest(request, callback, fallbackToGet) {
if (!isDefined(fallbackToGet) || null === fallbackToGet) {
fallbackToGet = true;
}
try {
// we use the progid Microsoft.XMLHTTP because
// IE5.5 included MSXML 2.5; the progid MSXML2.XMLHTTP
// is pinned to MSXML2.XMLHTTP.3.0
var xhr = windowAlias.XMLHttpRequest
? new windowAlias.XMLHttpRequest()
: windowAlias.ActiveXObject
? new ActiveXObject('Microsoft.XMLHTTP')
: null;
xhr.open('POST', configTrackerUrl, true);
// fallback on error
xhr.onreadystatechange = function () {
if (this.readyState === 4 && !(this.status >= 200 && this.status < 300) && fallbackToGet) {
getImage(request, callback);
} else {
if (typeof callback === 'function') { callback(); }
}
};
xhr.setRequestHeader('Content-Type', configRequestContentType);
xhr.send(request);
} catch (e) {
if (fallbackToGet) {
// fallback
getImage(request, callback);
}
}
}
function setExpireDateTime(delay) {
var now = new Date();
var time = now.getTime() + delay;
if (!expireDateTime || time > expireDateTime) {
expireDateTime = time;
}
}
function makeSureThereIsAGapAfterFirstTrackingRequestToPreventMultipleVisitorCreation(callback)
{
var now = new Date();
var timeNow = now.getTime();
if (timeNextTrackingRequestCanBeExecutedImmediately && timeNow < timeNextTrackingRequestCanBeExecutedImmediately) {
// we are in the time frame shortly after the first request. we have to delay this request a bit to make sure
// a visitor has been created meanwhile.
var timeToWait = timeNextTrackingRequestCanBeExecutedImmediately - timeNow;
setTimeout(callback, timeToWait);
setExpireDateTime(timeToWait + 50); // set timeout is not necessarily executed at timeToWait so delay a bit more
timeNextTrackingRequestCanBeExecutedImmediately += 50; // delay next tracking request by further 50ms to next execute them at same time
return;
}
if (timeNextTrackingRequestCanBeExecutedImmediately === false) {
// it is the first request, we want to execute this one directly and delay all the next one(s) within a delay.
// All requests after this delay can be executed as usual again
var delayInMs = 800;
timeNextTrackingRequestCanBeExecutedImmediately = timeNow + delayInMs;
}
callback();
}
/*
* Send request
*/
function sendRequest(request, delay, callback) {
if (!configDoNotTrack && request) {
makeSureThereIsAGapAfterFirstTrackingRequestToPreventMultipleVisitorCreation(function () {
if (configRequestMethod === 'POST') {
sendXmlHttpRequest(request, callback);
} else {
getImage(request, callback);
}
setExpireDateTime(delay);
});
}
}
function canSendBulkRequest(requests)
{
if (configDoNotTrack) {
return false;
}
return (requests && requests.length);
}
/*
* Send requests using bulk
*/
function sendBulkRequest(requests, delay)
{
if (!canSendBulkRequest(requests)) {
return;
}
var bulk = '{"requests":["?' + requests.join('","?') + '"]}';
makeSureThereIsAGapAfterFirstTrackingRequestToPreventMultipleVisitorCreation(function () {
sendXmlHttpRequest(bulk, null, false);
setExpireDateTime(delay);
});
}
/*
* Get cookie name with prefix and domain hash
*/
function getCookieName(baseName) {
// NOTE: If the cookie name is changed, we must also update the PiwikTracker.php which
// will attempt to discover first party cookies. eg. See the PHP Client method getVisitorId()
return configCookieNamePrefix + baseName + '.' + configTrackerSiteId + '.' + domainHash;
}
/*
* Does browser have cookies enabled (for this site)?
*/
function hasCookies() {
if (configCookiesDisabled) {
return '0';
}
if (!isDefined(navigatorAlias.cookieEnabled)) {
var testCookieName = getCookieName('testcookie');
setCookie(testCookieName, '1');
return getCookie(testCookieName) === '1' ? '1' : '0';
}
return navigatorAlias.cookieEnabled ? '1' : '0';
}
/*
* Update domain hash
*/
function updateDomainHash() {
domainHash = hash((configCookieDomain || domainAlias) + (configCookiePath || '/')).slice(0, 4); // 4 hexits = 16 bits
}
/*
* Inits the custom variables object
*/
function getCustomVariablesFromCookie() {
var cookieName = getCookieName('cvar'),
cookie = getCookie(cookieName);
if (cookie.length) {
cookie = JSON2.parse(cookie);
if (isObject(cookie)) {
return cookie;
}
}
return {};
}
/*
* Lazy loads the custom variables from the cookie, only once during this page view
*/
function loadCustomVariables() {
if (customVariables === false) {
customVariables = getCustomVariablesFromCookie();
}
}
/*
* Process all "activity" events.
* For performance, this function must have low overhead.
*/
function activityHandler() {
var now = new Date();
lastActivityTime = now.getTime();
}
/*
* Load visitor ID cookie
*/
function loadVisitorIdCookie() {
var now = new Date(),
nowTs = Math.round(now.getTime() / 1000),
id = getCookie(getCookieName('id')),
tmpContainer;
if (id) {
tmpContainer = id.split('.');
// returning visitor flag
tmpContainer.unshift('0');
} else {
// uuid - generate a pseudo-unique ID to fingerprint this user;
// note: this isn't a RFC4122-compliant UUID
if (!visitorUUID) {
visitorUUID = hash(
(navigatorAlias.userAgent || '') +
(navigatorAlias.platform || '') +
JSON2.stringify(browserFeatures) +
now.getTime() +
Math.random()
).slice(0, 16); // 16 hexits = 64 bits
}
tmpContainer = [
// new visitor
'1',
// uuid
visitorUUID,
// creation timestamp - seconds since Unix epoch
nowTs,
// visitCount - 0 = no previous visit
0,
// current visit timestamp
nowTs,
// last visit timestamp - blank = no previous visit
'',
// last ecommerce order timestamp
''
];
}
return tmpContainer;
}
function getRemainingVisitorCookieTimeout() {
var now = new Date(),
nowTs = now.getTime(),
visitorInfo = loadVisitorIdCookie();
var createTs = parseInt(visitorInfo[2], 10);
var originalTimeout = (createTs * 1000) + configVisitorCookieTimeout - nowTs;
return originalTimeout;
}
/*
* Sets the Visitor ID cookie: either the first time loadVisitorIdCookie is called
* or when there is a new visit or a new page view
*/
function setVisitorIdCookie(uuid, createTs, visitCount, nowTs, lastVisitTs, lastEcommerceOrderTs) {
var timeout = getRemainingVisitorCookieTimeout();
setCookie(getCookieName('id'), uuid + '.' + createTs + '.' + visitCount + '.' + nowTs + '.' + lastVisitTs + '.' + lastEcommerceOrderTs, timeout, configCookiePath, configCookieDomain);
}
/*
* Loads the referrer attribution information
*
* @returns array
* 0: campaign name
* 1: campaign keyword
* 2: timestamp
* 3: raw URL
*/
function loadReferrerAttributionCookie() {
// NOTE: if the format of the cookie changes,
// we must also update JS tests, PHP tracker, System tests,
// and notify other tracking clients (eg. Java) of the changes
var cookie = getCookie(getCookieName('ref'));
if (cookie.length) {
try {
cookie = JSON2.parse(cookie);
if (isObject(cookie)) {
return cookie;
}
} catch (ignore) {
// Pre 1.3, this cookie was not JSON encoded
}
}
return [
'',
'',
0,
''
];
}
function deleteCookies() {
var savedConfigCookiesDisabled = configCookiesDisabled;
// Temporarily allow cookies just to delete the existing ones
configCookiesDisabled = false;
setCookie(getCookieName('id'), '', -86400, configCookiePath, configCookieDomain);
setCookie(getCookieName('ses'), '', -86400, configCookiePath, configCookieDomain);
setCookie(getCookieName('cvar'), '', -86400, configCookiePath, configCookieDomain);
setCookie(getCookieName('ref'), '', -86400, configCookiePath, configCookieDomain);
configCookiesDisabled = savedConfigCookiesDisabled;
}
function sortObjectByKeys(value) {
if (!value || !isObject(value)) {
return;
}
// Object.keys(value) is not supported by all browsers, we get the keys manually
var keys = [];
var key;
for (key in value) {
if (Object.prototype.hasOwnProperty.call(value, key)) {
keys.push(key);
}
}
var normalized = {};
keys.sort();
var len = keys.length;
var i;
for (i = 0; i < len; i++) {
normalized[keys[i]] = value[keys[i]];
}
return normalized;
}
/**
* Returns the URL to call piwik.php,
* with the standard parameters (plugins, resolution, url, referrer, etc.).
* Sends the pageview and browser settings with every request in case of race conditions.
*/
function getRequest(request, customData, pluginMethod, currentEcommerceOrderTs) {
var i,
now = new Date(),
nowTs = Math.round(now.getTime() / 1000),
newVisitor,
uuid,
visitCount,
createTs,
currentVisitTs,
lastVisitTs,
lastEcommerceOrderTs,
referralTs,
referralUrl,
referralUrlMaxLength = 1024,
currentReferrerHostName,
originalReferrerHostName,
customVariablesCopy = customVariables,
sesname = getCookieName('ses'),
refname = getCookieName('ref'),
cvarname = getCookieName('cvar'),
id = loadVisitorIdCookie(),
ses = getCookie(sesname),
attributionCookie = loadReferrerAttributionCookie(),
currentUrl = configCustomUrl || locationHrefAlias,
campaignNameDetected,
campaignKeywordDetected;
if (configCookiesDisabled) {
deleteCookies();
}
if (configDoNotTrack) {
return '';
}
newVisitor = id[0];
uuid = id[1];
createTs = id[2];
visitCount = id[3];
currentVisitTs = id[4];
lastVisitTs = id[5];
// case migrating from pre-1.5 cookies
if (!isDefined(id[6])) {
id[6] = "";
}
lastEcommerceOrderTs = id[6];
if (!isDefined(currentEcommerceOrderTs)) {
currentEcommerceOrderTs = "";
}
// send charset if document charset is not utf-8. sometimes encoding
// of urls will be the same as this and not utf-8, which will cause problems
// do not send charset if it is utf8 since it's assumed by default in Piwik
var charSet = documentAlias.characterSet || documentAlias.charset;
if (!charSet || charSet.toLowerCase() === 'utf-8') {
charSet = null;
}
campaignNameDetected = attributionCookie[0];
campaignKeywordDetected = attributionCookie[1];
referralTs = attributionCookie[2];
referralUrl = attributionCookie[3];
if (!ses) {
// cookie 'ses' was not found: we consider this the start of a 'session'
// here we make sure that if 'ses' cookie is deleted few times within the visit
// and so this code path is triggered many times for one visit,
// we only increase visitCount once per Visit window (default 30min)
var visitDuration = configSessionCookieTimeout / 1000;
if (!lastVisitTs
|| (nowTs - lastVisitTs) > visitDuration) {
visitCount++;
lastVisitTs = currentVisitTs;
}
// Detect the campaign information from the current URL
// Only if campaign wasn't previously set
// Or if it was set but we must attribute to the most recent one
// Note: we are working on the currentUrl before purify() since we can parse the campaign parameters in the hash tag
if (!configConversionAttributionFirstReferrer
|| !campaignNameDetected.length) {
for (i in configCampaignNameParameters) {
if (Object.prototype.hasOwnProperty.call(configCampaignNameParameters, i)) {
campaignNameDetected = getParameter(currentUrl, configCampaignNameParameters[i]);
if (campaignNameDetected.length) {
break;
}
}
}
for (i in configCampaignKeywordParameters) {
if (Object.prototype.hasOwnProperty.call(configCampaignKeywordParameters, i)) {
campaignKeywordDetected = getParameter(currentUrl, configCampaignKeywordParameters[i]);
if (campaignKeywordDetected.length) {
break;
}
}
}
}
// Store the referrer URL and time in the cookie;
// referral URL depends on the first or last referrer attribution
currentReferrerHostName = getHostName(configReferrerUrl);
originalReferrerHostName = referralUrl.length ? getHostName(referralUrl) : '';
if (currentReferrerHostName.length && // there is a referrer
!isSiteHostName(currentReferrerHostName) && // domain is not the current domain
(!configConversionAttributionFirstReferrer || // attribute to last known referrer
!originalReferrerHostName.length || // previously empty
isSiteHostName(originalReferrerHostName))) { // previously set but in current domain
referralUrl = configReferrerUrl;
}
// Set the referral cookie if we have either a Referrer URL, or detected a Campaign (or both)
if (referralUrl.length
|| campaignNameDetected.length) {
referralTs = nowTs;
attributionCookie = [
campaignNameDetected,
campaignKeywordDetected,
referralTs,
purify(referralUrl.slice(0, referralUrlMaxLength))
];
setCookie(refname, JSON2.stringify(attributionCookie), configReferralCookieTimeout, configCookiePath, configCookieDomain);
}
}
// build out the rest of the request
request += '&idsite=' + configTrackerSiteId +
'&rec=1' +
'&r=' + String(Math.random()).slice(2, 8) + // keep the string to a minimum
'&h=' + now.getHours() + '&m=' + now.getMinutes() + '&s=' + now.getSeconds() +
'&url=' + encodeWrapper(purify(currentUrl)) +
(configReferrerUrl.length ? '&urlref=' + encodeWrapper(purify(configReferrerUrl)) : '') +
(configUserId.length ? '&uid=' + encodeWrapper(configUserId) : '') +
'&_id=' + uuid + '&_idts=' + createTs + '&_idvc=' + visitCount +
'&_idn=' + newVisitor + // currently unused
(campaignNameDetected.length ? '&_rcn=' + encodeWrapper(campaignNameDetected) : '') +
(campaignKeywordDetected.length ? '&_rck=' + encodeWrapper(campaignKeywordDetected) : '') +
'&_refts=' + referralTs +
'&_viewts=' + lastVisitTs +
(String(lastEcommerceOrderTs).length ? '&_ects=' + lastEcommerceOrderTs : '') +
(String(referralUrl).length ? '&_ref=' + encodeWrapper(purify(referralUrl.slice(0, referralUrlMaxLength))) : '') +
(charSet ? '&cs=' + encodeWrapper(charSet) : '');
// browser features
for (i in browserFeatures) {
if (Object.prototype.hasOwnProperty.call(browserFeatures, i)) {
request += '&' + i + '=' + browserFeatures[i];
}
}
// custom data
if (customData) {
request += '&data=' + encodeWrapper(JSON2.stringify(customData));
} else if (configCustomData) {
request += '&data=' + encodeWrapper(JSON2.stringify(configCustomData));
}
// Custom Variables, scope "page"
function appendCustomVariablesToRequest(customVariables, parameterName) {
var customVariablesStringified = JSON2.stringify(customVariables);
if (customVariablesStringified.length > 2) {
return '&' + parameterName + '=' + encodeWrapper(customVariablesStringified);
}
return '';
}
var sortedCustomVarPage = sortObjectByKeys(customVariablesPage);
var sortedCustomVarEvent = sortObjectByKeys(customVariablesEvent);
request += appendCustomVariablesToRequest(sortedCustomVarPage, 'cvar');
request += appendCustomVariablesToRequest(sortedCustomVarEvent, 'e_cvar');
// Custom Variables, scope "visit"
if (customVariables) {
request += appendCustomVariablesToRequest(customVariables, '_cvar');
// Don't save deleted custom variables in the cookie
for (i in customVariablesCopy) {
if (Object.prototype.hasOwnProperty.call(customVariablesCopy, i)) {
if (customVariables[i][0] === '' || customVariables[i][1] === '') {
delete customVariables[i];
}
}
}
if (configStoreCustomVariablesInCookie) {
setCookie(cvarname, JSON2.stringify(customVariables), configSessionCookieTimeout, configCookiePath, configCookieDomain);
}
}
// performance tracking
if (configPerformanceTrackingEnabled) {
if (configPerformanceGenerationTime) {
request += '>_ms=' + configPerformanceGenerationTime;
} else if (performanceAlias && performanceAlias.timing
&& performanceAlias.timing.requestStart && performanceAlias.timing.responseEnd) {
request += '>_ms=' + (performanceAlias.timing.responseEnd - performanceAlias.timing.requestStart);
}
}
// update cookies
setVisitorIdCookie(uuid, createTs, visitCount, nowTs, lastVisitTs, isDefined(currentEcommerceOrderTs) && String(currentEcommerceOrderTs).length ? currentEcommerceOrderTs : lastEcommerceOrderTs);
setCookie(sesname, '*', configSessionCookieTimeout, configCookiePath, configCookieDomain);
// tracker plugin hook
request += executePluginMethod(pluginMethod);
if (configAppendToTrackingUrl.length) {
request += '&' + configAppendToTrackingUrl;
}
if (isFunction(configCustomRequestContentProcessing)) {
request = configCustomRequestContentProcessing(request);
}
return request;
}
function logEcommerce(orderId, grandTotal, subTotal, tax, shipping, discount) {
var request = 'idgoal=0',
lastEcommerceOrderTs,
now = new Date(),
items = [],
sku;
if (String(orderId).length) {
request += '&ec_id=' + encodeWrapper(orderId);
// Record date of order in the visitor cookie
lastEcommerceOrderTs = Math.round(now.getTime() / 1000);
}
request += '&revenue=' + grandTotal;
if (String(subTotal).length) {
request += '&ec_st=' + subTotal;
}
if (String(tax).length) {
request += '&ec_tx=' + tax;
}
if (String(shipping).length) {
request += '&ec_sh=' + shipping;
}
if (String(discount).length) {
request += '&ec_dt=' + discount;
}
if (ecommerceItems) {
// Removing the SKU index in the array before JSON encoding
for (sku in ecommerceItems) {
if (Object.prototype.hasOwnProperty.call(ecommerceItems, sku)) {
// Ensure name and category default to healthy value
if (!isDefined(ecommerceItems[sku][1])) {
ecommerceItems[sku][1] = "";
}
if (!isDefined(ecommerceItems[sku][2])) {
ecommerceItems[sku][2] = "";
}
// Set price to zero
if (!isDefined(ecommerceItems[sku][3])
|| String(ecommerceItems[sku][3]).length === 0) {
ecommerceItems[sku][3] = 0;
}
// Set quantity to 1
if (!isDefined(ecommerceItems[sku][4])
|| String(ecommerceItems[sku][4]).length === 0) {
ecommerceItems[sku][4] = 1;
}
items.push(ecommerceItems[sku]);
}
}
request += '&ec_items=' + encodeWrapper(JSON2.stringify(items));
}
request = getRequest(request, configCustomData, 'ecommerce', lastEcommerceOrderTs);
sendRequest(request, configTrackerPause);
}
function logEcommerceOrder(orderId, grandTotal, subTotal, tax, shipping, discount) {
if (String(orderId).length
&& isDefined(grandTotal)) {
logEcommerce(orderId, grandTotal, subTotal, tax, shipping, discount);
}
}
function logEcommerceCartUpdate(grandTotal) {
if (isDefined(grandTotal)) {
logEcommerce("", grandTotal, "", "", "", "");
}
}
/*
* Log the page view / visit
*/
function logPageView(customTitle, customData) {
var now = new Date(),
request = getRequest('action_name=' + encodeWrapper(titleFixup(customTitle || configTitle)), customData, 'log');
sendRequest(request, configTrackerPause);
// send ping
if (configMinimumVisitTime && configHeartBeatTimer && !activityTrackingInstalled) {
activityTrackingInstalled = true;
// add event handlers; cross-browser compatibility here varies significantly
// @see http://quirksmode.org/dom/events
addEventListener(documentAlias, 'click', activityHandler);
addEventListener(documentAlias, 'mouseup', activityHandler);
addEventListener(documentAlias, 'mousedown', activityHandler);
addEventListener(documentAlias, 'mousemove', activityHandler);
addEventListener(documentAlias, 'mousewheel', activityHandler);
addEventListener(windowAlias, 'DOMMouseScroll', activityHandler);
addEventListener(windowAlias, 'scroll', activityHandler);
addEventListener(documentAlias, 'keypress', activityHandler);
addEventListener(documentAlias, 'keydown', activityHandler);
addEventListener(documentAlias, 'keyup', activityHandler);
addEventListener(windowAlias, 'resize', activityHandler);
addEventListener(windowAlias, 'focus', activityHandler);
addEventListener(windowAlias, 'blur', activityHandler);
// periodic check for activity
lastActivityTime = now.getTime();
setTimeout(function heartBeat() {
var requestPing;
now = new Date();
// there was activity during the heart beat period;
// on average, this is going to overstate the visitDuration by configHeartBeatTimer/2
if ((lastActivityTime + configHeartBeatTimer) > now.getTime()) {
// send ping if minimum visit time has elapsed
if (configMinimumVisitTime < now.getTime()) {
requestPing = getRequest('ping=1', customData, 'ping');
sendRequest(requestPing, configTrackerPause);
}
// resume heart beat
setTimeout(heartBeat, configHeartBeatTimer);
}
// else heart beat cancelled due to inactivity
}, configHeartBeatTimer);
}
}
/*
* Construct regular expression of classes
*/
function getClassesRegExp(configClasses, defaultClass) {
var i,
classesRegExp = '(^| )(piwik[_-]' + defaultClass;
if (configClasses) {
for (i = 0; i < configClasses.length; i++) {
classesRegExp += '|' + configClasses[i];
}
}
classesRegExp += ')( |$)';
return new RegExp(classesRegExp);
}
function startsUrlWithTrackerUrl(url) {
return (configTrackerUrl && url && 0 === String(url).indexOf(configTrackerUrl));
}
/*
* Link or Download?
*/
function getLinkType(className, href, isInLink) {
if (startsUrlWithTrackerUrl(href)) {
return 0;
}
// does class indicate whether it is an (explicit/forced) outlink or a download?
var downloadPattern = getClassesRegExp(configDownloadClasses, 'download'),
linkPattern = getClassesRegExp(configLinkClasses, 'link'),
// does file extension indicate that it is a download?
downloadExtensionsPattern = new RegExp('\\.(' + configDownloadExtensions + ')([?&#]|$)', 'i');
if (linkPattern.test(className)) {
return 'link';
}
if (downloadPattern.test(className) || downloadExtensionsPattern.test(href)) {
return 'download';
}
if (isInLink) {
return 0;
}
return 'link';
}
function getSourceElement(sourceElement)
{
var parentElement;
parentElement = sourceElement.parentNode;
while (parentElement !== null &&
/* buggy IE5.5 */
isDefined(parentElement)) {
if (query.isLinkElement(sourceElement)) {
break;
}
sourceElement = parentElement;
parentElement = sourceElement.parentNode;
}
return sourceElement;
}
function getLinkIfShouldBeProcessed(sourceElement)
{
sourceElement = getSourceElement(sourceElement);
if (!query.hasNodeAttribute(sourceElement, 'href')) {
return;
}
if (!isDefined(sourceElement.href)) {
return;
}
var href = query.getAttributeValueFromNode(sourceElement, 'href');
if (startsUrlWithTrackerUrl(href)) {
return;
}
// browsers, such as Safari, don't downcase hostname and href
var originalSourceHostName = sourceElement.hostname || getHostName(sourceElement.href);
var sourceHostName = originalSourceHostName.toLowerCase();
var sourceHref = sourceElement.href.replace(originalSourceHostName, sourceHostName);
// browsers, such as Safari, don't downcase hostname and href
var scriptProtocol = new RegExp('^(javascript|vbscript|jscript|mocha|livescript|ecmascript|mailto):', 'i');
if (!scriptProtocol.test(sourceHref)) {
// track outlinks and all downloads
var linkType = getLinkType(sourceElement.className, sourceHref, isSiteHostName(sourceHostName));
if (linkType) {
return {
type: linkType,
href: sourceHref
};
}
}
}
function buildContentInteractionRequest(interaction, name, piece, target)
{
var params = content.buildInteractionRequestParams(interaction, name, piece, target);
if (!params) {
return;
}
return getRequest(params, null, 'contentInteraction');
}
function buildContentInteractionTrackingRedirectUrl(url, contentInteraction, contentName, contentPiece, contentTarget)
{
if (!isDefined(url)) {
return;
}
if (startsUrlWithTrackerUrl(url)) {
return url;
}
var redirectUrl = content.toAbsoluteUrl(url);
var request = 'redirecturl=' + encodeWrapper(redirectUrl) + '&';
request += buildContentInteractionRequest(contentInteraction, contentName, contentPiece, (contentTarget || url));
var separator = '&';
if (configTrackerUrl.indexOf('?') < 0) {
separator = '?';
}
return configTrackerUrl + separator + request;
}
function isNodeAuthorizedToTriggerInteraction(contentNode, interactedNode)
{
if (!contentNode || !interactedNode) {
return false;
}
var targetNode = content.findTargetNode(contentNode);
if (content.shouldIgnoreInteraction(targetNode)) {
// interaction should be ignored
return false;
}
targetNode = content.findTargetNodeNoDefault(contentNode);
if (targetNode && !containsNodeElement(targetNode, interactedNode)) {
/**
* There is a target node defined but the clicked element is not within the target node. example:
* <div data-track-content><a href="Y" data-content-target>Y</a><img src=""/><a href="Z">Z</a></div>
*
* The user clicked in this case on link Z and not on target Y
*/
return false;
}
return true;
}
function getContentInteractionToRequestIfPossible (anyNode, interaction, fallbackTarget)
{
if (!anyNode) {
return;
}
var contentNode = content.findParentContentNode(anyNode);
if (!contentNode) {
// we are not within a content block
return;
}
if (!isNodeAuthorizedToTriggerInteraction(contentNode, anyNode)) {
return;
}
var contentBlock = content.buildContentBlock(contentNode);
if (!contentBlock) {
return;
}
if (!contentBlock.target && fallbackTarget) {
contentBlock.target = fallbackTarget;
}
return content.buildInteractionRequestParams(interaction, contentBlock.name, contentBlock.piece, contentBlock.target);
}
function wasContentImpressionAlreadyTracked(contentBlock)
{
if (!trackedContentImpressions || !trackedContentImpressions.length) {
return false;
}
var index, trackedContent;
for (index = 0; index < trackedContentImpressions.length; index++) {
trackedContent = trackedContentImpressions[index];
if (trackedContent &&
trackedContent.name === contentBlock.name &&
trackedContent.piece === contentBlock.piece &&
trackedContent.target === contentBlock.target) {
return true;
}
}
return false;
}
function replaceHrefIfInternalLink(contentBlock)
{
if (!contentBlock) {
return false;
}
var targetNode = content.findTargetNode(contentBlock);
if (!targetNode || content.shouldIgnoreInteraction(targetNode)) {
return false;
}
var link = getLinkIfShouldBeProcessed(targetNode);
if (linkTrackingEnabled && link && link.type) {
return false; // will be handled via outlink or download.
}
if (query.isLinkElement(targetNode) &&
query.hasNodeAttributeWithValue(targetNode, 'href')) {
var url = String(query.getAttributeValueFromNode(targetNode, 'href'));
if (0 === url.indexOf('#')) {
return false;
}
if (startsUrlWithTrackerUrl(url)) {
return true;
}
if (!content.isUrlToCurrentDomain(url)) {
return false;
}
var block = content.buildContentBlock(contentBlock);
if (!block) {
return;
}
var contentName = block.name;
var contentPiece = block.piece;
var contentTarget = block.target;
if (!query.hasNodeAttributeWithValue(targetNode, content.CONTENT_TARGET_ATTR) || targetNode.wasContentTargetAttrReplaced) {
// make sure we still track the correct content target when an interaction is happening
targetNode.wasContentTargetAttrReplaced = true;
contentTarget = content.toAbsoluteUrl(url);
query.setAnyAttribute(targetNode, content.CONTENT_TARGET_ATTR, contentTarget);
}
var targetUrl = buildContentInteractionTrackingRedirectUrl(url, 'click', contentName, contentPiece, contentTarget);
// location.href does not respect target=_blank so we prefer to use this
content.setHrefAttribute(targetNode, targetUrl);
return true;
}
return false;
}
function replaceHrefsIfInternalLink(contentNodes)
{
if (!contentNodes || !contentNodes.length) {
return;
}
var index;
for (index = 0; index < contentNodes.length; index++) {
replaceHrefIfInternalLink(contentNodes[index]);
}
}
function trackContentImpressionClickInteraction (targetNode)
{
return function (event) {
if (!targetNode) {
return;
}
var contentBlock = content.findParentContentNode(targetNode);
var interactedElement;
if (event) {
interactedElement = event.target || event.srcElement;
}
if (!interactedElement) {
interactedElement = targetNode;
}
if (!isNodeAuthorizedToTriggerInteraction(contentBlock, interactedElement)) {
return;
}
setExpireDateTime(configTrackerPause);
if (query.isLinkElement(targetNode) &&
query.hasNodeAttributeWithValue(targetNode, 'href') &&
query.hasNodeAttributeWithValue(targetNode, content.CONTENT_TARGET_ATTR)) {
// there is a href attribute, the link was replaced with piwik.php but later the href was changed again by the application.
var href = query.getAttributeValueFromNode(targetNode, 'href');
if (!startsUrlWithTrackerUrl(href) && targetNode.wasContentTargetAttrReplaced) {
query.setAnyAttribute(targetNode, content.CONTENT_TARGET_ATTR, '');
}
}
var link = getLinkIfShouldBeProcessed(targetNode);
if (linkTrackingInstalled && link && link.type) {
// click ignore, will be tracked via processClick, we do not want to track it twice
return link.type;
}
if (replaceHrefIfInternalLink(contentBlock)) {
return 'href';
}
var block = content.buildContentBlock(contentBlock);
if (!block) {
return;
}
var contentName = block.name;
var contentPiece = block.piece;
var contentTarget = block.target;
// click on any non link element, or on a link element that has not an href attribute or on an anchor
var request = buildContentInteractionRequest('click', contentName, contentPiece, contentTarget);
sendRequest(request, configTrackerPause);
return request;
};
}
function setupInteractionsTracking(contentNodes)
{
if (!contentNodes || !contentNodes.length) {
return;
}
var index, targetNode;
for (index = 0; index < contentNodes.length; index++) {
targetNode = content.findTargetNode(contentNodes[index]);
if (targetNode && !targetNode.contentInteractionTrackingSetupDone) {
targetNode.contentInteractionTrackingSetupDone = true;
addEventListener(targetNode, 'click', trackContentImpressionClickInteraction(targetNode));
}
}
}
/*
* Log all content pieces
*/
function buildContentImpressionsRequests(contents, contentNodes)
{
if (!contents || !contents.length) {
return [];
}
var index, request;
for (index = 0; index < contents.length; index++) {
if (wasContentImpressionAlreadyTracked(contents[index])) {
contents.splice(index, 1);
index--;
} else {
trackedContentImpressions.push(contents[index]);
}
}
if (!contents || !contents.length) {
return [];
}
replaceHrefsIfInternalLink(contentNodes);
setupInteractionsTracking(contentNodes);
var requests = [];
for (index = 0; index < contents.length; index++) {
request = getRequest(
content.buildImpressionRequestParams(contents[index].name, contents[index].piece, contents[index].target),
undefined,
'contentImpressions'
);
requests.push(request);
}
return requests;
}
/*
* Log all content pieces
*/
function getContentImpressionsRequestsFromNodes(contentNodes)
{
var contents = content.collectContent(contentNodes);
return buildContentImpressionsRequests(contents, contentNodes);
}
/*
* Log currently visible content pieces
*/
function getCurrentlyVisibleContentImpressionsRequestsIfNotTrackedYet(contentNodes)
{
if (!contentNodes || !contentNodes.length) {
return [];
}
var index;
for (index = 0; index < contentNodes.length; index++) {
if (!content.isNodeVisible(contentNodes[index])) {
contentNodes.splice(index, 1);
index--;
}
}
if (!contentNodes || !contentNodes.length) {
return [];
}
return getContentImpressionsRequestsFromNodes(contentNodes);
}
function buildContentImpressionRequest(contentName, contentPiece, contentTarget)
{
var params = content.buildImpressionRequestParams(contentName, contentPiece, contentTarget);
return getRequest(params, null, 'contentImpression');
}
function buildContentInteractionRequestNode(node, contentInteraction)
{
if (!node) {
return;
}
var contentNode = content.findParentContentNode(node);
var contentBlock = content.buildContentBlock(contentNode);
if (!contentBlock) {
return;
}
if (!contentInteraction) {
contentInteraction = 'Unknown';
}
return buildContentInteractionRequest(contentInteraction, contentBlock.name, contentBlock.piece, contentBlock.target);
}
function buildEventRequest(category, action, name, value)
{
return 'e_c=' + encodeWrapper(category)
+ '&e_a=' + encodeWrapper(action)
+ (isDefined(name) ? '&e_n=' + encodeWrapper(name) : '')
+ (isDefined(value) ? '&e_v=' + encodeWrapper(value) : '');
}
/*
* Log the event
*/
function logEvent(category, action, name, value, customData)
{
// Category and Action are required parameters
if (String(category).length === 0 || String(action).length === 0) {
return false;
}
var request = getRequest(
buildEventRequest(category, action, name, value),
customData,
'event'
);
sendRequest(request, configTrackerPause);
}
/*
* Log the site search request
*/
function logSiteSearch(keyword, category, resultsCount, customData) {
var request = getRequest('search=' + encodeWrapper(keyword)
+ (category ? '&search_cat=' + encodeWrapper(category) : '')
+ (isDefined(resultsCount) ? '&search_count=' + resultsCount : ''), customData, 'sitesearch');
sendRequest(request, configTrackerPause);
}
/*
* Log the goal with the server
*/
function logGoal(idGoal, customRevenue, customData) {
var request = getRequest('idgoal=' + idGoal + (customRevenue ? '&revenue=' + customRevenue : ''), customData, 'goal');
sendRequest(request, configTrackerPause);
}
/*
* Log the link or click with the server
*/
function logLink(url, linkType, customData, callback, sourceElement) {
var linkParams = linkType + '=' + encodeWrapper(purify(url));
var interaction = getContentInteractionToRequestIfPossible(sourceElement, 'click', url);
if (interaction) {
linkParams += '&' + interaction;
}
var request = getRequest(linkParams, customData, 'link');
sendRequest(request, (callback ? 0 : configTrackerPause), callback);
}
/*
* Browser prefix
*/
function prefixPropertyName(prefix, propertyName) {
if (prefix !== '') {
return prefix + propertyName.charAt(0).toUpperCase() + propertyName.slice(1);
}
return propertyName;
}
/*
* Check for pre-rendered web pages, and log the page view/link/goal
* according to the configuration and/or visibility
*
* @see http://dvcs.w3.org/hg/webperf/raw-file/tip/specs/PageVisibility/Overview.html
*/
function trackCallback(callback) {
var isPreRendered,
i,
// Chrome 13, IE10, FF10
prefixes = ['', 'webkit', 'ms', 'moz'],
prefix;
if (!configCountPreRendered) {
for (i = 0; i < prefixes.length; i++) {
prefix = prefixes[i];
// does this browser support the page visibility API?
if (Object.prototype.hasOwnProperty.call(documentAlias, prefixPropertyName(prefix, 'hidden'))) {
// if pre-rendered, then defer callback until page visibility changes
if (documentAlias[prefixPropertyName(prefix, 'visibilityState')] === 'prerender') {
isPreRendered = true;
}
break;
}
}
}
if (isPreRendered) {
// note: the event name doesn't follow the same naming convention as vendor properties
addEventListener(documentAlias, prefix + 'visibilitychange', function ready() {
documentAlias.removeEventListener(prefix + 'visibilitychange', ready, false);
callback();
});
return;
}
// configCountPreRendered === true || isPreRendered === false
callback();
}
function trackCallbackOnLoad(callback)
{
if (documentAlias.readyState === 'complete') {
callback();
} else if (windowAlias.addEventListener) {
windowAlias.addEventListener('load', callback);
} else if (windowAlias.attachEvent) {
windowAlias.attachEvent('onLoad', callback);
}
}
function trackCallbackOnReady(callback)
{
var loaded = false;
if (documentAlias.attachEvent) {
loaded = documentAlias.readyState === "complete";
} else {
loaded = documentAlias.readyState !== "loading";
}
if (loaded) {
callback();
} else if (documentAlias.addEventListener) {
documentAlias.addEventListener('DOMContentLoaded', callback);
} else if (documentAlias.attachEvent) {
documentAlias.attachEvent('onreadystatechange', callback);
}
}
/*
* Process clicks
*/
function processClick(sourceElement) {
var link = getLinkIfShouldBeProcessed(sourceElement);
if (link && link.type) {
// urldecode %xx
link.href = urldecode(link.href);
logLink(link.href, link.type, undefined, null, sourceElement);
}
}
/*
* Handle click event
*/
function clickHandler(evt) {
var button,
target;
evt = evt || windowAlias.event;
button = evt.which || evt.button;
target = evt.target || evt.srcElement;
// Using evt.type (added in IE4), we avoid defining separate handlers for mouseup and mousedown.
if (evt.type === 'click') {
if (target) {
processClick(target);
}
} else if (evt.type === 'mousedown') {
if ((button === 1 || button === 2) && target) {
lastButton = button;
lastTarget = target;
} else {
lastButton = lastTarget = null;
}
} else if (evt.type === 'mouseup') {
if (button === lastButton && target === lastTarget) {
processClick(target);
}
lastButton = lastTarget = null;
}
}
/*
* Add click listener to a DOM element
*/
function addClickListener(element, enable) {
if (enable) {
// for simplicity and performance, we ignore drag events
addEventListener(element, 'mouseup', clickHandler, false);
addEventListener(element, 'mousedown', clickHandler, false);
} else {
addEventListener(element, 'click', clickHandler, false);
}
}
/*
* Add click handlers to anchor and AREA elements, except those to be ignored
*/
function addClickListeners(enable) {
if (!linkTrackingInstalled) {
linkTrackingInstalled = true;
// iterate through anchor elements with href and AREA elements
var i,
ignorePattern = getClassesRegExp(configIgnoreClasses, 'ignore'),
linkElements = documentAlias.links;
if (linkElements) {
for (i = 0; i < linkElements.length; i++) {
if (!ignorePattern.test(linkElements[i].className)) {
addClickListener(linkElements[i], enable);
}
}
}
}
}
function enableTrackOnlyVisibleContent (checkOnSroll, timeIntervalInMs, tracker) {
if (isTrackOnlyVisibleContentEnabled) {
// already enabled, do not register intervals again
return true;
}
isTrackOnlyVisibleContentEnabled = true;
var didScroll = false;
var events, index;
function setDidScroll() { didScroll = true; }
trackCallbackOnLoad(function () {
function checkContent(intervalInMs) {
setTimeout(function () {
if (!isTrackOnlyVisibleContentEnabled) {
return; // the tests stopped tracking only visible content
}
didScroll = false;
tracker.trackVisibleContentImpressions();
checkContent(intervalInMs);
}, intervalInMs);
}
function checkContentIfDidScroll(intervalInMs) {
setTimeout(function () {
if (!isTrackOnlyVisibleContentEnabled) {
return; // the tests stopped tracking only visible content
}
if (didScroll) {
didScroll = false;
tracker.trackVisibleContentImpressions();
}
checkContentIfDidScroll(intervalInMs);
}, intervalInMs);
}
if (checkOnSroll) {
// scroll event is executed after each pixel, so we make sure not to
// execute event too often. otherwise FPS goes down a lot!
events = ['scroll', 'resize'];
for (index = 0; index < events.length; index++) {
if (documentAlias.addEventListener) {
documentAlias.addEventListener(events[index], setDidScroll);
} else {
windowAlias.attachEvent('on' + events[index], setDidScroll);
}
}
checkContentIfDidScroll(100);
}
if (timeIntervalInMs && timeIntervalInMs > 0) {
timeIntervalInMs = parseInt(timeIntervalInMs, 10);
checkContent(timeIntervalInMs);
}
});
}
/*
* Browser features (plugins, resolution, cookies)
*/
function detectBrowserFeatures() {
var i,
mimeType,
pluginMap = {
// document types
pdf: 'application/pdf',
// media players
qt: 'video/quicktime',
realp: 'audio/x-pn-realaudio-plugin',
wma: 'application/x-mplayer2',
// interactive multimedia
dir: 'application/x-director',
fla: 'application/x-shockwave-flash',
// RIA
java: 'application/x-java-vm',
gears: 'application/x-googlegears',
ag: 'application/x-silverlight'
},
devicePixelRatio = (new RegExp('Mac OS X.*Safari/')).test(navigatorAlias.userAgent) ? windowAlias.devicePixelRatio || 1 : 1;
if (!((new RegExp('MSIE')).test(navigatorAlias.userAgent))) {
// general plugin detection
if (navigatorAlias.mimeTypes && navigatorAlias.mimeTypes.length) {
for (i in pluginMap) {
if (Object.prototype.hasOwnProperty.call(pluginMap, i)) {
mimeType = navigatorAlias.mimeTypes[pluginMap[i]];
browserFeatures[i] = (mimeType && mimeType.enabledPlugin) ? '1' : '0';
}
}
}
// Safari and Opera
// IE6/IE7 navigator.javaEnabled can't be aliased, so test directly
if (typeof navigator.javaEnabled !== 'unknown' &&
isDefined(navigatorAlias.javaEnabled) &&
navigatorAlias.javaEnabled()) {
browserFeatures.java = '1';
}
// Firefox
if (isFunction(windowAlias.GearsFactory)) {
browserFeatures.gears = '1';
}
// other browser features
browserFeatures.cookie = hasCookies();
}
// screen resolution
// - only Apple reports screen.* in device-independent-pixels (dips)
// - devicePixelRatio is always 2 on MacOSX+Retina regardless of resolution set in Display Preferences
browserFeatures.res = screenAlias.width * devicePixelRatio + 'x' + screenAlias.height * devicePixelRatio;
}
/*<DEBUG>*/
/*
* Register a test hook. Using eval() permits access to otherwise
* privileged members.
*/
function registerHook(hookName, userHook) {
var hookObj = null;
if (isString(hookName) && !isDefined(registeredHooks[hookName]) && userHook) {
if (isObject(userHook)) {
hookObj = userHook;
} else if (isString(userHook)) {
try {
eval('hookObj =' + userHook);
} catch (ignore) { }
}
registeredHooks[hookName] = hookObj;
}
return hookObj;
}
/*</DEBUG>*/
/************************************************************
* Constructor
************************************************************/
/*
* initialize tracker
*/
detectBrowserFeatures();
updateDomainHash();
/*<DEBUG>*/
/*
* initialize test plugin
*/
executePluginMethod('run', registerHook);
/*</DEBUG>*/
/************************************************************
* Public data and methods
************************************************************/
return {
/*<DEBUG>*/
/*
* Test hook accessors
*/
hook: registeredHooks,
getHook: function (hookName) {
return registeredHooks[hookName];
},
getQuery: function () {
return query;
},
getContent: function () {
return content;
},
buildContentImpressionRequest: buildContentImpressionRequest,
buildContentInteractionRequest: buildContentInteractionRequest,
buildContentInteractionRequestNode: buildContentInteractionRequestNode,
buildContentInteractionTrackingRedirectUrl: buildContentInteractionTrackingRedirectUrl,
getContentImpressionsRequestsFromNodes: getContentImpressionsRequestsFromNodes,
getCurrentlyVisibleContentImpressionsRequestsIfNotTrackedYet: getCurrentlyVisibleContentImpressionsRequestsIfNotTrackedYet,
trackCallbackOnLoad: trackCallbackOnLoad,
trackCallbackOnReady: trackCallbackOnReady,
buildContentImpressionsRequests: buildContentImpressionsRequests,
wasContentImpressionAlreadyTracked: wasContentImpressionAlreadyTracked,
appendContentInteractionToRequestIfPossible: getContentInteractionToRequestIfPossible,
setupInteractionsTracking: setupInteractionsTracking,
trackContentImpressionClickInteraction: trackContentImpressionClickInteraction,
internalIsNodeVisible: isVisible,
isNodeAuthorizedToTriggerInteraction: isNodeAuthorizedToTriggerInteraction,
replaceHrefIfInternalLink: replaceHrefIfInternalLink,
getConfigDownloadExtensions: function () {
return configDownloadExtensions;
},
enableTrackOnlyVisibleContent: function (checkOnScroll, timeIntervalInMs) {
return enableTrackOnlyVisibleContent(checkOnScroll, timeIntervalInMs, this);
},
clearTrackedContentImpressions: function () {
trackedContentImpressions = [];
},
getTrackedContentImpressions: function () {
return trackedContentImpressions;
},
getTrackerUrl: function () {
return configTrackerUrl;
},
clearEnableTrackOnlyVisibleContent: function () {
isTrackOnlyVisibleContentEnabled = false;
},
disableLinkTracking: function () {
linkTrackingInstalled = false;
linkTrackingEnabled = false;
},
getConfigVisitorCookieTimeout: function () {
return configVisitorCookieTimeout;
},
getRemainingVisitorCookieTimeout: getRemainingVisitorCookieTimeout,
/*</DEBUG>*/
/**
* Get visitor ID (from first party cookie)
*
* @return string Visitor ID in hexits (or null, if not yet known)
*/
getVisitorId: function () {
return (loadVisitorIdCookie())[1];
},
/**
* Get the visitor information (from first party cookie)
*
* @return array
*/
getVisitorInfo: function () {
return loadVisitorIdCookie();
},
/**
* Get the Attribution information, which is an array that contains
* the Referrer used to reach the site as well as the campaign name and keyword
* It is useful only when used in conjunction with Tracker API function setAttributionInfo()
* To access specific data point, you should use the other functions getAttributionReferrer* and getAttributionCampaign*
*
* @return array Attribution array, Example use:
* 1) Call JSON2.stringify(piwikTracker.getAttributionInfo())
* 2) Pass this json encoded string to the Tracking API (php or java client): setAttributionInfo()
*/
getAttributionInfo: function () {
return loadReferrerAttributionCookie();
},
/**
* Get the Campaign name that was parsed from the landing page URL when the visitor
* landed on the site originally
*
* @return string
*/
getAttributionCampaignName: function () {
return loadReferrerAttributionCookie()[0];
},
/**
* Get the Campaign keyword that was parsed from the landing page URL when the visitor
* landed on the site originally
*
* @return string
*/
getAttributionCampaignKeyword: function () {
return loadReferrerAttributionCookie()[1];
},
/**
* Get the time at which the referrer (used for Goal Attribution) was detected
*
* @return int Timestamp or 0 if no referrer currently set
*/
getAttributionReferrerTimestamp: function () {
return loadReferrerAttributionCookie()[2];
},
/**
* Get the full referrer URL that will be used for Goal Attribution
*
* @return string Raw URL, or empty string '' if no referrer currently set
*/
getAttributionReferrerUrl: function () {
return loadReferrerAttributionCookie()[3];
},
/**
* Specify the Piwik server URL
*
* @param string trackerUrl
*/
setTrackerUrl: function (trackerUrl) {
configTrackerUrl = trackerUrl;
},
/**
* Specify the site ID
*
* @param int|string siteId
*/
setSiteId: function (siteId) {
configTrackerSiteId = siteId;
},
/**
* Sets a User ID to this user (such as an email address or a username)
*
* @param string User ID
*/
setUserId: function (userId) {
configUserId = userId;
},
/**
* Gets the User ID if set.
*
* @returns string User ID
*/
getUserId: function() {
return configUserId;
},
/**
* Pass custom data to the server
*
* Examples:
* tracker.setCustomData(object);
* tracker.setCustomData(key, value);
*
* @param mixed key_or_obj
* @param mixed opt_value
*/
setCustomData: function (key_or_obj, opt_value) {
if (isObject(key_or_obj)) {
configCustomData = key_or_obj;
} else {
if (!configCustomData) {
configCustomData = {};
}
configCustomData[key_or_obj] = opt_value;
}
},
/**
* Get custom data
*
* @return mixed
*/
getCustomData: function () {
return configCustomData;
},
/**
* Configure function with custom request content processing logic.
* It gets called after request content in form of query parameters string has been prepared and before request content gets sent.
*
* Examples:
* tracker.setCustomRequestProcessing(function(request){
* var pairs = request.split('&');
* var result = {};
* pairs.forEach(function(pair) {
* pair = pair.split('=');
* result[pair[0]] = decodeURIComponent(pair[1] || '');
* });
* return JSON.stringify(result);
* });
*
* @param function customRequestContentProcessingLogic
*/
setCustomRequestProcessing: function (customRequestContentProcessingLogic) {
configCustomRequestContentProcessing = customRequestContentProcessingLogic;
},
/**
* Appends the specified query string to the piwik.php?... Tracking API URL
*
* @param string queryString eg. 'lat=140&long=100'
*/
appendToTrackingUrl: function (queryString) {
configAppendToTrackingUrl = queryString;
},
/**
* Returns the query string for the current HTTP Tracking API request.
* Piwik would prepend the hostname and path to Piwik: http://example.org/piwik/piwik.php?
* prior to sending the request.
*
* @param request eg. "param=value¶m2=value2"
*/
getRequest: function (request) {
return getRequest(request);
},
/**
* Add plugin defined by a name and a callback function.
* The callback function will be called whenever a tracking request is sent.
* This can be used to append data to the tracking request, or execute other custom logic.
*
* @param string pluginName
* @param Object pluginObj
*/
addPlugin: function (pluginName, pluginObj) {
plugins[pluginName] = pluginObj;
},
/**
* Set custom variable within this visit
*
* @param int index
* @param string name
* @param string value
* @param string scope Scope of Custom Variable:
* - "visit" will store the name/value in the visit and will persist it in the cookie for the duration of the visit,
* - "page" will store the name/value in the next page view tracked.
* - "event" will store the name/value in the next event tracked.
*/
setCustomVariable: function (index, name, value, scope) {
var toRecord;
if (!isDefined(scope)) {
scope = 'visit';
}
if (!isDefined(name)) {
return;
}
if (!isDefined(value)) {
value = "";
}
if (index > 0) {
name = !isString(name) ? String(name) : name;
value = !isString(value) ? String(value) : value;
toRecord = [name.slice(0, customVariableMaximumLength), value.slice(0, customVariableMaximumLength)];
// numeric scope is there for GA compatibility
if (scope === 'visit' || scope === 2) {
loadCustomVariables();
customVariables[index] = toRecord;
} else if (scope === 'page' || scope === 3) {
customVariablesPage[index] = toRecord;
} else if (scope === 'event') { /* GA does not have 'event' scope but we do */
customVariablesEvent[index] = toRecord;
}
}
},
/**
* Get custom variable
*
* @param int index
* @param string scope Scope of Custom Variable: "visit" or "page" or "event"
*/
getCustomVariable: function (index, scope) {
var cvar;
if (!isDefined(scope)) {
scope = "visit";
}
if (scope === "page" || scope === 3) {
cvar = customVariablesPage[index];
} else if (scope === "event") {
cvar = customVariablesEvent[index];
} else if (scope === "visit" || scope === 2) {
loadCustomVariables();
cvar = customVariables[index];
}
if (!isDefined(cvar)
|| (cvar && cvar[0] === '')) {
return false;
}
return cvar;
},
/**
* Delete custom variable
*
* @param int index
*/
deleteCustomVariable: function (index, scope) {
// Only delete if it was there already
if (this.getCustomVariable(index, scope)) {
this.setCustomVariable(index, '', '', scope);
}
},
/**
* When called then the Custom Variables of scope "visit" will be stored (persisted) in a first party cookie
* for the duration of the visit. This is useful if you want to call getCustomVariable later in the visit.
*
* By default, Custom Variables of scope "visit" are not stored on the visitor's computer.
*/
storeCustomVariablesInCookie: function () {
configStoreCustomVariablesInCookie = true;
},
/**
* Set delay for link tracking (in milliseconds)
*
* @param int delay
*/
setLinkTrackingTimer: function (delay) {
configTrackerPause = delay;
},
/**
* Set list of file extensions to be recognized as downloads
*
* @param string extensions
*/
setDownloadExtensions: function (extensions) {
configDownloadExtensions = extensions;
},
/**
* Specify additional file extensions to be recognized as downloads
*
* @param string extensions
*/
addDownloadExtensions: function (extensions) {
configDownloadExtensions += '|' + extensions;
},
/**
* Set array of domains to be treated as local
*
* @param string|array hostsAlias
*/
setDomains: function (hostsAlias) {
configHostsAlias = isString(hostsAlias) ? [hostsAlias] : hostsAlias;
configHostsAlias.push(domainAlias);
},
/**
* Set array of classes to be ignored if present in link
*
* @param string|array ignoreClasses
*/
setIgnoreClasses: function (ignoreClasses) {
configIgnoreClasses = isString(ignoreClasses) ? [ignoreClasses] : ignoreClasses;
},
/**
* Set request method
*
* @param string method GET or POST; default is GET
*/
setRequestMethod: function (method) {
configRequestMethod = method || defaultRequestMethod;
},
/**
* Set request Content-Type header value, applicable when POST request method is used for submitting tracking events.
* See XMLHttpRequest Level 2 spec, section 4.7.2 for invalid headers
* @link http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html
*
* @param string requestContentType; default is 'application/x-www-form-urlencoded; charset=UTF-8'
*/
setRequestContentType: function (requestContentType) {
configRequestContentType = requestContentType || defaultRequestContentType;
},
/**
* Override referrer
*
* @param string url
*/
setReferrerUrl: function (url) {
configReferrerUrl = url;
},
/**
* Override url
*
* @param string url
*/
setCustomUrl: function (url) {
configCustomUrl = resolveRelativeReference(locationHrefAlias, url);
},
/**
* Override document.title
*
* @param string title
*/
setDocumentTitle: function (title) {
configTitle = title;
},
/**
* Set the URL of the Piwik API. It is used for Page Overlay.
* This method should only be called when the API URL differs from the tracker URL.
*
* @param string apiUrl
*/
setAPIUrl: function (apiUrl) {
configApiUrl = apiUrl;
},
/**
* Set array of classes to be treated as downloads
*
* @param string|array downloadClasses
*/
setDownloadClasses: function (downloadClasses) {
configDownloadClasses = isString(downloadClasses) ? [downloadClasses] : downloadClasses;
},
/**
* Set array of classes to be treated as outlinks
*
* @param string|array linkClasses
*/
setLinkClasses: function (linkClasses) {
configLinkClasses = isString(linkClasses) ? [linkClasses] : linkClasses;
},
/**
* Set array of campaign name parameters
*
* @see http://piwik.org/faq/how-to/#faq_120
* @param string|array campaignNames
*/
setCampaignNameKey: function (campaignNames) {
configCampaignNameParameters = isString(campaignNames) ? [campaignNames] : campaignNames;
},
/**
* Set array of campaign keyword parameters
*
* @see http://piwik.org/faq/how-to/#faq_120
* @param string|array campaignKeywords
*/
setCampaignKeywordKey: function (campaignKeywords) {
configCampaignKeywordParameters = isString(campaignKeywords) ? [campaignKeywords] : campaignKeywords;
},
/**
* Strip hash tag (or anchor) from URL
* Note: this can be done in the Piwik>Settings>Websites on a per-website basis
*
* @deprecated
* @param bool enableFilter
*/
discardHashTag: function (enableFilter) {
configDiscardHashTag = enableFilter;
},
/**
* Set first-party cookie name prefix
*
* @param string cookieNamePrefix
*/
setCookieNamePrefix: function (cookieNamePrefix) {
configCookieNamePrefix = cookieNamePrefix;
// Re-init the Custom Variables cookie
customVariables = getCustomVariablesFromCookie();
},
/**
* Set first-party cookie domain
*
* @param string domain
*/
setCookieDomain: function (domain) {
configCookieDomain = domainFixup(domain);
updateDomainHash();
},
/**
* Set first-party cookie path
*
* @param string domain
*/
setCookiePath: function (path) {
configCookiePath = path;
updateDomainHash();
},
/**
* Set visitor cookie timeout (in seconds)
* Defaults to 13 months (timeout=33955200)
*
* @param int timeout
*/
setVisitorCookieTimeout: function (timeout) {
configVisitorCookieTimeout = timeout * 1000;
},
/**
* Set session cookie timeout (in seconds).
* Defaults to 30 minutes (timeout=1800000)
*
* @param int timeout
*/
setSessionCookieTimeout: function (timeout) {
configSessionCookieTimeout = timeout * 1000;
},
/**
* Set referral cookie timeout (in seconds).
* Defaults to 6 months (15768000000)
*
* @param int timeout
*/
setReferralCookieTimeout: function (timeout) {
configReferralCookieTimeout = timeout * 1000;
},
/**
* Set conversion attribution to first referrer and campaign
*
* @param bool if true, use first referrer (and first campaign)
* if false, use the last referrer (or campaign)
*/
setConversionAttributionFirstReferrer: function (enable) {
configConversionAttributionFirstReferrer = enable;
},
/**
* Disables all cookies from being set
*
* Existing cookies will be deleted on the next call to track
*/
disableCookies: function () {
configCookiesDisabled = true;
browserFeatures.cookie = '0';
},
/**
* One off cookies clearing. Useful to call this when you know for sure a new visitor is using the same browser,
* it maybe helps to "reset" tracking cookies to prevent data reuse for different users.
*/
deleteCookies: function () {
deleteCookies();
},
/**
* Handle do-not-track requests
*
* @param bool enable If true, don't track if user agent sends 'do-not-track' header
*/
setDoNotTrack: function (enable) {
var dnt = navigatorAlias.doNotTrack || navigatorAlias.msDoNotTrack;
configDoNotTrack = enable && (dnt === 'yes' || dnt === '1');
// do not track also disables cookies and deletes existing cookies
if (configDoNotTrack) {
this.disableCookies();
}
},
/**
* Add click listener to a specific link element.
* When clicked, Piwik will log the click automatically.
*
* @param DOMElement element
* @param bool enable If true, use pseudo click-handler (mousedown+mouseup)
*/
addListener: function (element, enable) {
addClickListener(element, enable);
},
/**
* Install link tracker
*
* The default behaviour is to use actual click events. However, some browsers
* (e.g., Firefox, Opera, and Konqueror) don't generate click events for the middle mouse button.
*
* To capture more "clicks", the pseudo click-handler uses mousedown + mouseup events.
* This is not industry standard and is vulnerable to false positives (e.g., drag events).
*
* There is a Safari/Chrome/Webkit bug that prevents tracking requests from being sent
* by either click handler. The workaround is to set a target attribute (which can't
* be "_self", "_top", or "_parent").
*
* @see https://bugs.webkit.org/show_bug.cgi?id=54783
*
* @param bool enable If true, use pseudo click-handler (mousedown+mouseup)
*/
enableLinkTracking: function (enable) {
linkTrackingEnabled = true;
if (hasLoaded) {
// the load event has already fired, add the click listeners now
addClickListeners(enable);
} else {
// defer until page has loaded
registeredOnLoadHandlers.push(function () {
addClickListeners(enable);
});
}
},
/**
* Enable tracking of uncatched JavaScript errors
*
* If enabled, uncaught JavaScript Errors will be tracked as an event by defining a
* window.onerror handler. If a window.onerror handler is already defined we will make
* sure to call this previously registered error handler after tracking the error.
*
* By default we return false in the window.onerror handler to make sure the error still
* appears in the browser's console etc. Note: Some older browsers might behave differently
* so it could happen that an actual JavaScript error will be suppressed.
* If a window.onerror handler was registered we will return the result of this handler.
*
* Make sure not to overwrite the window.onerror handler after enabling the JS error
* tracking as the error tracking won't work otherwise. To capture all JS errors we
* recommend to include the Piwik JavaScript tracker in the HTML as early as possible.
* If possible directly in <head></head> before loading any other JavaScript.
*/
enableJSErrorTracking: function () {
if (enableJSErrorTracking) {
return;
}
enableJSErrorTracking = true;
var onError = windowAlias.onerror;
windowAlias.onerror = function (message, url, linenumber, column, error) {
trackCallback(function () {
var category = 'JavaScript Errors';
var action = url + ':' + linenumber;
if (column) {
action += ':' + column;
}
logEvent(category, action, message);
});
if (onError) {
return onError(message, url, linenumber, column, error);
}
return false;
};
},
/**
* Disable automatic performance tracking
*/
disablePerformanceTracking: function () {
configPerformanceTrackingEnabled = false;
},
/**
* Set the server generation time.
* If set, the browser's performance.timing API in not used anymore to determine the time.
*
* @param int generationTime
*/
setGenerationTimeMs: function (generationTime) {
configPerformanceGenerationTime = parseInt(generationTime, 10);
},
/**
* Set heartbeat (in seconds)
*
* @param int minimumVisitLength
* @param int heartBeatDelay
*/
setHeartBeatTimer: function (minimumVisitLength, heartBeatDelay) {
var now = new Date();
configMinimumVisitTime = now.getTime() + minimumVisitLength * 1000;
configHeartBeatTimer = heartBeatDelay * 1000;
},
/**
* Frame buster
*/
killFrame: function () {
if (windowAlias.location !== windowAlias.top.location) {
windowAlias.top.location = windowAlias.location;
}
},
/**
* Redirect if browsing offline (aka file: buster)
*
* @param string url Redirect to this URL
*/
redirectFile: function (url) {
if (windowAlias.location.protocol === 'file:') {
windowAlias.location = url;
}
},
/**
* Count sites in pre-rendered state
*
* @param bool enable If true, track when in pre-rendered state
*/
setCountPreRendered: function (enable) {
configCountPreRendered = enable;
},
/**
* Trigger a goal
*
* @param int|string idGoal
* @param int|float customRevenue
* @param mixed customData
*/
trackGoal: function (idGoal, customRevenue, customData) {
trackCallback(function () {
logGoal(idGoal, customRevenue, customData);
});
},
/**
* Manually log a click from your own code
*
* @param string sourceUrl
* @param string linkType
* @param mixed customData
* @param function callback
*/
trackLink: function (sourceUrl, linkType, customData, callback) {
trackCallback(function () {
logLink(sourceUrl, linkType, customData, callback);
});
},
/**
* Log visit to this page
*
* @param string customTitle
* @param mixed customData
*/
trackPageView: function (customTitle, customData) {
trackedContentImpressions = [];
if (isOverlaySession(configTrackerSiteId)) {
trackCallback(function () {
injectOverlayScripts(configTrackerUrl, configApiUrl, configTrackerSiteId);
});
} else {
trackCallback(function () {
logPageView(customTitle, customData);
});
}
},
/**
* Scans the entire DOM for all content blocks and tracks all impressions once the DOM ready event has
* been triggered.
*
* If you only want to track visible content impressions have a look at `trackVisibleContentImpressions()`.
* We do not track an impression of the same content block twice if you call this method multiple times
* unless `trackPageView()` is called meanwhile. This is useful for single page applications.
*/
trackAllContentImpressions: function () {
if (isOverlaySession(configTrackerSiteId)) {
return;
}
trackCallback(function () {
trackCallbackOnReady(function () {
// we have to wait till DOM ready
var contentNodes = content.findContentNodes();
var requests = getContentImpressionsRequestsFromNodes(contentNodes);
sendBulkRequest(requests, configTrackerPause);
});
});
},
/**
* Scans the entire DOM for all content blocks as soon as the page is loaded. It tracks an impression
* only if a content block is actually visible. Meaning it is not hidden and the content is or was at
* some point in the viewport.
*
* If you want to track all content blocks have a look at `trackAllContentImpressions()`.
* We do not track an impression of the same content block twice if you call this method multiple times
* unless `trackPageView()` is called meanwhile. This is useful for single page applications.
*
* Once you have called this method you can no longer change `checkOnScroll` or `timeIntervalInMs`.
*
* If you do want to only track visible content blocks but not want us to perform any automatic checks
* as they can slow down your frames per second you can call `trackVisibleContentImpressions()` or
* `trackContentImpressionsWithinNode()` manually at any time to rescan the entire DOM for newly
* visible content blocks.
* o Call `trackVisibleContentImpressions(false, 0)` to initially track only visible content impressions
* o Call `trackVisibleContentImpressions()` at any time again to rescan the entire DOM for newly visible content blocks or
* o Call `trackContentImpressionsWithinNode(node)` at any time to rescan only a part of the DOM for newly visible content blocks
*
* @param boolean [checkOnScroll=true] Optional, you can disable rescanning the entire DOM automatically
* after each scroll event by passing the value `false`. If enabled,
* we check whether a previously hidden content blocks became visible
* after a scroll and if so track the impression.
* Note: If a content block is placed within a scrollable element
* (`overflow: scroll`), we can currently not detect when this block
* becomes visible.
* @param integer [timeIntervalInMs=750] Optional, you can define an interval to rescan the entire DOM
* for new impressions every X milliseconds by passing
* for instance `timeIntervalInMs=500` (rescan DOM every 500ms).
* Rescanning the entire DOM and detecting the visible state of content
* blocks can take a while depending on the browser and amount of content.
* In case your frames per second goes down you might want to increase
* this value or disable it by passing the value `0`.
*/
trackVisibleContentImpressions: function (checkOnSroll, timeIntervalInMs) {
if (isOverlaySession(configTrackerSiteId)) {
return;
}
if (!isDefined(checkOnSroll)) {
checkOnSroll = true;
}
if (!isDefined(timeIntervalInMs)) {
timeIntervalInMs = 750;
}
enableTrackOnlyVisibleContent(checkOnSroll, timeIntervalInMs, this);
trackCallback(function () {
trackCallbackOnLoad(function () {
// we have to wait till CSS parsed and applied
var contentNodes = content.findContentNodes();
var requests = getCurrentlyVisibleContentImpressionsRequestsIfNotTrackedYet(contentNodes);
sendBulkRequest(requests, configTrackerPause);
});
});
},
/**
* Tracks a content impression using the specified values. You should not call this method too often
* as each call causes an XHR tracking request and can slow down your site or your server.
*
* @param string contentName For instance "Ad Sale".
* @param string [contentPiece='Unknown'] For instance a path to an image or the text of a text ad.
* @param string [contentTarget] For instance the URL of a landing page.
*/
trackContentImpression: function (contentName, contentPiece, contentTarget) {
if (isOverlaySession(configTrackerSiteId)) {
return;
}
if (!contentName) {
return;
}
contentPiece = contentPiece || 'Unknown';
trackCallback(function () {
var request = buildContentImpressionRequest(contentName, contentPiece, contentTarget);
sendRequest(request, configTrackerPause);
});
},
/**
* Scans the given DOM node and its children for content blocks and tracks an impression for them if
* no impression was already tracked for it. If you have called `trackVisibleContentImpressions()`
* upfront only visible content blocks will be tracked. You can use this method if you, for instance,
* dynamically add an element using JavaScript to your DOM after we have tracked the initial impressions.
*
* @param Element domNode
*/
trackContentImpressionsWithinNode: function (domNode) {
if (isOverlaySession(configTrackerSiteId) || !domNode) {
return;
}
trackCallback(function () {
if (isTrackOnlyVisibleContentEnabled) {
trackCallbackOnLoad(function () {
// we have to wait till CSS parsed and applied
var contentNodes = content.findContentNodesWithinNode(domNode);
var requests = getCurrentlyVisibleContentImpressionsRequestsIfNotTrackedYet(contentNodes);
sendBulkRequest(requests, configTrackerPause);
});
} else {
trackCallbackOnReady(function () {
// we have to wait till DOM ready
var contentNodes = content.findContentNodesWithinNode(domNode);
var requests = getContentImpressionsRequestsFromNodes(contentNodes);
sendBulkRequest(requests, configTrackerPause);
});
}
});
},
/**
* Tracks a content interaction using the specified values. You should use this method only in conjunction
* with `trackContentImpression()`. The specified `contentName` and `contentPiece` has to be exactly the
* same as the ones that were used in `trackContentImpression()`. Otherwise the interaction will not count.
*
* @param string contentInteraction The type of interaction that happened. For instance 'click' or 'submit'.
* @param string contentName The name of the content. For instance "Ad Sale".
* @param string [contentPiece='Unknown'] The actual content. For instance a path to an image or the text of a text ad.
* @param string [contentTarget] For instance the URL of a landing page.
*/
trackContentInteraction: function (contentInteraction, contentName, contentPiece, contentTarget) {
if (isOverlaySession(configTrackerSiteId)) {
return;
}
if (!contentInteraction || !contentName) {
return;
}
contentPiece = contentPiece || 'Unknown';
trackCallback(function () {
var request = buildContentInteractionRequest(contentInteraction, contentName, contentPiece, contentTarget);
sendRequest(request, configTrackerPause);
});
},
/**
* Tracks an interaction with the given DOM node / content block.
*
* By default we track interactions on click but sometimes you might want to track interactions yourself.
* For instance you might want to track an interaction manually on a double click or a form submit.
* Make sure to disable the automatic interaction tracking in this case by specifying either the CSS
* class `piwikContentIgnoreInteraction` or the attribute `data-content-ignoreinteraction`.
*
* @param Element domNode This element itself or any of its parent elements has to be a content block
* element. Meaning one of those has to have a `piwikTrackContent` CSS class or
* a `data-track-content` attribute.
* @param string [contentInteraction='Unknown] The name of the interaction that happened. For instance
* 'click', 'formSubmit', 'DblClick', ...
*/
trackContentInteractionNode: function (domNode, contentInteraction) {
if (isOverlaySession(configTrackerSiteId) || !domNode) {
return;
}
trackCallback(function () {
var request = buildContentInteractionRequestNode(domNode, contentInteraction);
sendRequest(request, configTrackerPause);
});
},
/**
* Records an event
*
* @param string category The Event Category (Videos, Music, Games...)
* @param string action The Event's Action (Play, Pause, Duration, Add Playlist, Downloaded, Clicked...)
* @param string name (optional) The Event's object Name (a particular Movie name, or Song name, or File name...)
* @param float value (optional) The Event's value
*/
trackEvent: function (category, action, name, value) {
trackCallback(function () {
logEvent(category, action, name, value);
});
},
/**
* Log special pageview: Internal search
*
* @param string keyword
* @param string category
* @param int resultsCount
*/
trackSiteSearch: function (keyword, category, resultsCount) {
trackCallback(function () {
logSiteSearch(keyword, category, resultsCount);
});
},
/**
* Used to record that the current page view is an item (product) page view, or a Ecommerce Category page view.
* This must be called before trackPageView() on the product/category page.
* It will set 3 custom variables of scope "page" with the SKU, Name and Category for this page view.
* Note: Custom Variables of scope "page" slots 3, 4 and 5 will be used.
*
* On a category page, you can set the parameter category, and set the other parameters to empty string or false
*
* Tracking Product/Category page views will allow Piwik to report on Product & Categories
* conversion rates (Conversion rate = Ecommerce orders containing this product or category / Visits to the product or category)
*
* @param string sku Item's SKU code being viewed
* @param string name Item's Name being viewed
* @param string category Category page being viewed. On an Item's page, this is the item's category
* @param float price Item's display price, not use in standard Piwik reports, but output in API product reports.
*/
setEcommerceView: function (sku, name, category, price) {
if (!isDefined(category) || !category.length) {
category = "";
} else if (category instanceof Array) {
category = JSON2.stringify(category);
}
customVariablesPage[5] = ['_pkc', category];
if (isDefined(price) && String(price).length) {
customVariablesPage[2] = ['_pkp', price];
}
// On a category page, do not track Product name not defined
if ((!isDefined(sku) || !sku.length)
&& (!isDefined(name) || !name.length)) {
return;
}
if (isDefined(sku) && sku.length) {
customVariablesPage[3] = ['_pks', sku];
}
if (!isDefined(name) || !name.length) {
name = "";
}
customVariablesPage[4] = ['_pkn', name];
},
/**
* Adds an item (product) that is in the current Cart or in the Ecommerce order.
* This function is called for every item (product) in the Cart or the Order.
* The only required parameter is sku.
*
* @param string sku (required) Item's SKU Code. This is the unique identifier for the product.
* @param string name (optional) Item's name
* @param string name (optional) Item's category, or array of up to 5 categories
* @param float price (optional) Item's price. If not specified, will default to 0
* @param float quantity (optional) Item's quantity. If not specified, will default to 1
*/
addEcommerceItem: function (sku, name, category, price, quantity) {
if (sku.length) {
ecommerceItems[sku] = [ sku, name, category, price, quantity ];
}
},
/**
* Tracks an Ecommerce order.
* If the Ecommerce order contains items (products), you must call first the addEcommerceItem() for each item in the order.
* All revenues (grandTotal, subTotal, tax, shipping, discount) will be individually summed and reported in Piwik reports.
* Parameters orderId and grandTotal are required. For others, you can set to false if you don't need to specify them.
*
* @param string|int orderId (required) Unique Order ID.
* This will be used to count this order only once in the event the order page is reloaded several times.
* orderId must be unique for each transaction, even on different days, or the transaction will not be recorded by Piwik.
* @param float grandTotal (required) Grand Total revenue of the transaction (including tax, shipping, etc.)
* @param float subTotal (optional) Sub total amount, typically the sum of items prices for all items in this order (before Tax and Shipping costs are applied)
* @param float tax (optional) Tax amount for this order
* @param float shipping (optional) Shipping amount for this order
* @param float discount (optional) Discounted amount in this order
*/
trackEcommerceOrder: function (orderId, grandTotal, subTotal, tax, shipping, discount) {
logEcommerceOrder(orderId, grandTotal, subTotal, tax, shipping, discount);
},
/**
* Tracks a Cart Update (add item, remove item, update item).
* On every Cart update, you must call addEcommerceItem() for each item (product) in the cart, including the items that haven't been updated since the last cart update.
* Then you can call this function with the Cart grandTotal (typically the sum of all items' prices)
*
* @param float grandTotal (required) Items (products) amount in the Cart
*/
trackEcommerceCartUpdate: function (grandTotal) {
logEcommerceCartUpdate(grandTotal);
}
};
}
/************************************************************
* Proxy object
* - this allows the caller to continue push()'ing to _paq
* after the Tracker has been initialized and loaded
************************************************************/
function TrackerProxy() {
return {
push: apply
};
}
/************************************************************
* Constructor
************************************************************/
// initialize the Piwik singleton
addEventListener(windowAlias, 'beforeunload', beforeUnloadHandler, false);
addReadyListener();
Date.prototype.getTimeAlias = Date.prototype.getTime;
asyncTracker = new Tracker();
var applyFirst = {setTrackerUrl: 1, setAPIUrl: 1, setSiteId: 1, disableCookies: 1, enableLinkTracking: 1};
var methodName;
// find the call to setTrackerUrl or setSiteid (if any) and call them first
for (iterator = 0; iterator < _paq.length; iterator++) {
methodName = _paq[iterator][0];
if (applyFirst[methodName]) {
apply(_paq[iterator]);
delete _paq[iterator];
if (applyFirst[methodName] > 1) {
if (console !== undefined && console && console.error) {
console.error('The method ' + methodName + ' is registered more than once in "_paq" variable. Only the last call has an effect. Please have a look at the multiple Piwik trackers documentation: http://developer.piwik.org/api-reference/tracking-javascript#multiple-piwik-trackers');
}
}
applyFirst[methodName]++;
}
}
// apply the queue of actions
for (iterator = 0; iterator < _paq.length; iterator++) {
if (_paq[iterator]) {
apply(_paq[iterator]);
}
}
// replace initialization array with proxy object
_paq = new TrackerProxy();
/************************************************************
* Public data and methods
************************************************************/
Piwik = {
/**
* Add plugin
*
* @param string pluginName
* @param Object pluginObj
*/
addPlugin: function (pluginName, pluginObj) {
plugins[pluginName] = pluginObj;
},
/**
* Get Tracker (factory method)
*
* @param string piwikUrl
* @param int|string siteId
* @return Tracker
*/
getTracker: function (piwikUrl, siteId) {
return new Tracker(piwikUrl, siteId, asyncTracker.getVisitorId());
},
/**
* Get internal asynchronous tracker object
*
* @return Tracker
*/
getAsyncTracker: function () {
return asyncTracker;
}
};
// Expose Piwik as an AMD module
if (typeof define === 'function' && define.amd) {
define('piwik', [], function () { return Piwik; });
}
return Piwik;
}());
}
if (window && window.piwikAsyncInit) {
window.piwikAsyncInit();
}
/*jslint sloppy: true */
(function () {
var jsTrackerType = (typeof AnalyticsTracker);
if (jsTrackerType === 'undefined') {
AnalyticsTracker = Piwik;
}
}());
/*jslint sloppy: false */
/************************************************************
* Deprecated functionality below
* Legacy piwik.js compatibility ftw
************************************************************/
/*
* Piwik globals
*
* var piwik_install_tracker, piwik_tracker_pause, piwik_download_extensions, piwik_hosts_alias, piwik_ignore_classes;
*/
/*global piwik_log:true */
/*global piwik_track:true */
/**
* Track page visit
*
* @param string documentTitle
* @param int|string siteId
* @param string piwikUrl
* @param mixed customData
*/
if (typeof piwik_log !== 'function') {
piwik_log = function (documentTitle, siteId, piwikUrl, customData) {
'use strict';
function getOption(optionName) {
try {
return eval('piwik_' + optionName);
} catch (ignore) { }
return; // undefined
}
// instantiate the tracker
var option,
piwikTracker = Piwik.getTracker(piwikUrl, siteId);
// initialize tracker
piwikTracker.setDocumentTitle(documentTitle);
piwikTracker.setCustomData(customData);
// handle Piwik globals
option = getOption('tracker_pause');
if (option) {
piwikTracker.setLinkTrackingTimer(option);
}
option = getOption('download_extensions');
if (option) {
piwikTracker.setDownloadExtensions(option);
}
option = getOption('hosts_alias');
if (option) {
piwikTracker.setDomains(option);
}
option = getOption('ignore_classes');
if (option) {
piwikTracker.setIgnoreClasses(option);
}
// track this page view
piwikTracker.trackPageView();
// default is to install the link tracker
if (getOption('install_tracker')) {
/**
* Track click manually (function is defined below)
*
* @param string sourceUrl
* @param int|string siteId
* @param string piwikUrl
* @param string linkType
*/
piwik_track = function (sourceUrl, siteId, piwikUrl, linkType) {
piwikTracker.setSiteId(siteId);
piwikTracker.setTrackerUrl(piwikUrl);
piwikTracker.trackLink(sourceUrl, linkType);
};
// set-up link tracking
piwikTracker.enableLinkTracking();
}
};
}
/*! @license-end */
|