2025-2-26-fixed
This commit is contained in:
11
themes/next/layout/_third-party/analytics/baidu-analytics.swig
vendored
Normal file
11
themes/next/layout/_third-party/analytics/baidu-analytics.swig
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
{%- if theme.baidu_analytics %}
|
||||
<script{{ pjax }}>
|
||||
var _hmt = _hmt || [];
|
||||
(function() {
|
||||
var hm = document.createElement("script");
|
||||
hm.src = "https://hm.baidu.com/hm.js?{{ theme.baidu_analytics }}";
|
||||
var s = document.getElementsByTagName("script")[0];
|
||||
s.parentNode.insertBefore(hm, s);
|
||||
})();
|
||||
</script>
|
||||
{%- endif %}
|
||||
31
themes/next/layout/_third-party/analytics/google-analytics.swig
vendored
Normal file
31
themes/next/layout/_third-party/analytics/google-analytics.swig
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
{%- if theme.google_analytics.tracking_id %}
|
||||
{%- if not theme.google_analytics.only_pageview %}
|
||||
<script async src="https://www.googletagmanager.com/gtag/js?id={{ theme.google_analytics.tracking_id }}"></script>
|
||||
<script{{ pjax }}>
|
||||
if (CONFIG.hostname === location.hostname) {
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
function gtag(){dataLayer.push(arguments);}
|
||||
gtag('js', new Date());
|
||||
gtag('config', '{{ theme.google_analytics.tracking_id }}');
|
||||
}
|
||||
</script>
|
||||
{%- endif %}
|
||||
{%- if theme.google_analytics.only_pageview %}
|
||||
<script>
|
||||
function sendPageView() {
|
||||
if (CONFIG.hostname !== location.hostname) return;
|
||||
var uid = localStorage.getItem('uid') || (Math.random() + '.' + Math.random());
|
||||
localStorage.setItem('uid', uid);
|
||||
navigator.sendBeacon('https://www.google-analytics.com/collect', new URLSearchParams({
|
||||
v : 1,
|
||||
tid: '{{ theme.google_analytics.tracking_id }}',
|
||||
cid: uid,
|
||||
t : 'pageview',
|
||||
dp : encodeURIComponent(location.pathname)
|
||||
}));
|
||||
}
|
||||
document.addEventListener('pjax:complete', sendPageView);
|
||||
sendPageView();
|
||||
</script>
|
||||
{%- endif %}
|
||||
{%- endif %}
|
||||
7
themes/next/layout/_third-party/analytics/growingio.swig
vendored
Normal file
7
themes/next/layout/_third-party/analytics/growingio.swig
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
{%- if theme.growingio_analytics %}
|
||||
<script{{ pjax }}>
|
||||
!function(e,t,n,g,i){e[i]=e[i]||function(){(e[i].q=e[i].q||[]).push(arguments)},n=t.createElement("script"),tag=t.getElementsByTagName("script")[0],n.async=1,n.src=('https:'==document.location.protocol?'https://':'http://')+g,tag.parentNode.insertBefore(n,tag)}(window,document,"script","assets.growingio.com/2.1/gio.js","gio");
|
||||
gio('init', '{{ theme.growingio_analytics }}', {});
|
||||
gio('send');
|
||||
</script>
|
||||
{%- endif %}
|
||||
3
themes/next/layout/_third-party/analytics/index.swig
vendored
Normal file
3
themes/next/layout/_third-party/analytics/index.swig
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{% include 'google-analytics.swig' %}
|
||||
{% include 'baidu-analytics.swig' %}
|
||||
{% include 'growingio.swig' %}
|
||||
Reference in New Issue
Block a user