<% if (config.google_analytics_key) { %>
<!-- Global site tag (gtag.js) - Google Analytics -->
<!-- https://github.com/volantis-x/hexo-theme-volantis/issues/63 -->
<script>
	setTimeout(function() {
	  volantis.js("https://www.googletagmanager.com/gtag/js?id=<%- config.google_analytics_key %>");
	  window.dataLayer = window.dataLayer || [];
	  function gtag(){dataLayer.push(arguments);}
	  gtag('js', new Date());
	  gtag('config', '<%- config.google_analytics_key %>');
	}, 1000);
	// 关于谷歌统计对 SPA 页面的处理：
	// 当应用以动态方式加载内容并更新地址栏中的网址时，也应该更新通过 gtag.js 存储的网页网址。
	// https://developers.google.cn/analytics/devguides/collection/gtagjs/single-page-applications?hl=zh-cn
	volantis.pjax.push(()=>{
		window.dataLayer = window.dataLayer || [];
		function gtag(){dataLayer.push(arguments);}
		gtag('config', '<%- config.google_analytics_key %>', {'page_path': document.location.pathname});
	},'google_analytics')
</script>
<% } %>

<% if (config.baidu_analytics_key) { %>
<!-- baidu Analytics -->
<script>
var _hmt = _hmt || [];
(function() {
  setTimeout(function() {
    volantis.js("https://hm.baidu.com/hm.js?<%= config.baidu_analytics_key %>")
  }, 1000);
})();
// 关于百度统计对 SPA 页面的处理：
// 方案一：百度统计>管理>单页应用设置中，打开开启按钮即可对SPA进行统计。 https://tongji.baidu.com/web/help/article?id=324
// 方案二：取消注释下列代码。 https://tongji.baidu.com/web/help/article?id=235
volantis.pjax.push(()=>{_hmt.push(['_trackPageview', document.location.pathname]);},'baidu_analytics')
</script>
<% } %>

<% if (config.tencent_aegis_id) { %>
<script>
  const genUuid = () => {
    let s = [];
    let hexDigits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    for (let i = 0; i < 36; i++) {
      s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1)
    }
    s[14] = "4"
    s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1)
    s[8] = s[13] = s[18] = s[23] = "-"
    let uuid = s.join("")
    return uuid;
  }
  setTimeout(() => {
    let uin = localStorage.getItem('Aegis_UIN');
    if(!uin) {
      uin = genUuid();
      localStorage.setItem('Aegis_UIN', uin);
    }
    volantis.js("https://cdn-go.cn/aegis/aegis-sdk/latest/aegis.min.js").then(()=>{
      const aegis=new Aegis({id:"<%- config.tencent_aegis_id %>",reportApiSpeed:true,reportAssetSpeed:true,spa:true,uin:uin});
    })
  }, 1000)
</script>
<% } %>

<% if (config.v6_51_la) { %>
  <script charset="UTF-8" id="LA_COLLECT" src="//sdk.51.la/js-sdk-pro.min.js"></script>
  <script>
    volantis.js("https://sdk.51.la/js-sdk-pro.min.js").then(() => {
      LA.init({id: "<%= config.v6_51_la %>",ck: "<%= config.v6_51_la %>",autoTrack:true,hashMode:true})
    })
  </script>
<% } %>

<% if (config.perf_51_la) { %>
  <script src="https://sdk.51.la/perf/js-sdk-perf.min.js" crossorigin="anonymous"></script>
  <script>
    volantis.js("https://sdk.51.la/perf/js-sdk-perf.min.js").then(() => {
      new LingQue.Monitor().init({id:"<%= config.perf_51_la %>",sendSuspicious:true});
    })
  </script>
<% } %>