Use dynamic function load analytic scripts avoid affecting the execution of page functions.

This commit is contained in:
凡梦星尘 2022-07-20 09:03:11 +08:00
parent 81cff8a5c2
commit ad271c1c20
3 changed files with 22 additions and 3 deletions

View File

@ -28,6 +28,11 @@ css:
# 第三方服务组件资源
# 3rd servcies Resource
# 站点统计
# Site analytics engine
analytics:
la: https://sdk.51.la/js-sdk-pro.min.js
# 文章分享
# Share
addthis:

View File

@ -1,2 +1,15 @@
<script charset="UTF-8" id="LA_COLLECT" src="https://sdk.51.la/js-sdk-pro.min.js"></script>
<script>LA.init({id: "{{ . }}",ck: "{{ . }}",autoTrack:true})</script>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', () => {
var script = document.createElement('script');
script.charset = "UTF-8";
script.id = "LA_COLLECT";
script.src = "{{ .ctx.Site.Data.resources.analytics.la }}";
script.async = "true"
script.onload = function() {
LA.init({ id: "{{ .id }}",ck: "{{ .id }}", autoTrack:true });
}
document.head.appendChild(script);
});
</script>

View File

@ -1,5 +1,6 @@
{{ $ctx := . }}
{{- with .Site.Params.analytics }}
{{- if isset . "laid" }}
{{ partial "_thirdparty/analytics/51la.html" .laId }}
{{ partial "_thirdparty/analytics/51la.html" (dict "ctx" $ctx "id" .laId) }}
{{- end }}
{{- end }}