1+ /*
2+ * Licensed to the Apache Software Foundation (ASF) under one or more
3+ * contributor license agreements. See the NOTICE file distributed with
4+ * this work for additional information regarding copyright ownership.
5+ * The ASF licenses this file to You under the Apache License, Version 2.0
6+ * (the "License"); you may not use this file except in compliance with
7+ * the License. You may obtain a copy of the License at
8+ *
9+ * http://www.apache.org/licenses/LICENSE-2.0
10+ *
11+ * Unless required by applicable law or agreed to in writing, software
12+ * distributed under the License is distributed on an "AS IS" BASIS,
13+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ * See the License for the specific language governing permissions and
15+ * limitations under the License.
16+ */
17+
18+ import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment' ;
19+
20+ ( function ( ) {
21+ if ( ExecutionEnvironment . canUseDOM ) {
22+ let prefix = '' ;
23+ if ( location . pathname . startsWith ( '/zh-cn' ) ) {
24+ prefix = '/zh-cn' ;
25+ }
26+ let s = document . getElementsByTagName ( 'script' ) [ 0 ] ;
27+
28+ let matomo = document . createElement ( 'script' ) ;
29+ matomo . text = `
30+ /* -- Matomo */
31+ var _paq = window._paq = window._paq || [];
32+ /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
33+ /* _paq.push(["setDoNotTrack", true]); */
34+ _paq.push(["disableCookies"]);
35+ _paq.push(['trackPageView']);
36+ _paq.push(['enableLinkTracking']);
37+ (function() {
38+ var u="https://analytics.apache.org/";
39+ _paq.push(['setTrackerUrl', u+'matomo.php']);
40+ _paq.push(['setSiteId', '83']);
41+ var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
42+ g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
43+ })();
44+ /* End Matomo Code */
45+ ` ;
46+ s . parentNode . insertBefore ( matomo , s ) ;
47+
48+ const controller = new AbortController ( ) ;
49+ const signal = controller . signal ;
50+ // set timeout
51+ setTimeout ( ( ) => {
52+ controller . abort ( ) ;
53+ } , 5000 ) ;
54+ fetch ( prefix + '/config.json' , { signal} )
55+ . then ( ( res ) => res . json ( ) )
56+ . then ( ( data ) => {
57+ if ( data . analytics ) {
58+ }
59+ } ) . catch ( ( err => {
60+ // do nothing
61+ } ) ) ;
62+ }
63+ } ) ( ) ;
0 commit comments