YunYouJun / hexo-theme-yun

☁️ A fast & light & lovely theme for Hexo. 一个对可爱自以为是的 Hexo 主题。
https://yun.yunyoujun.cn
MIT License
1.38k stars 167 forks source link

[Feature Request] 增加对 umami 访问统计的支持 #332

Closed chitang233 closed 1 year ago

chitang233 commented 1 year ago

Is your feature request related to a problem? Please describe. umami 是在 中添加一个 js 进行加载,但需要传入一个参数 yun 只能选择加载方式而无法传入参数

Describe the solution you'd like 增加对 umami 的支持或允许用户在添加自定义 js 时传参

YunYouJun commented 1 year ago

I haven't used it, and I don't know how to add parameters. Do you want to create a PR for it?

chitang233 commented 1 year ago

No, I can't write themes

asadahimeka commented 1 year ago

@chitang233 , You can use hexo(version > 5) injector to insert the script tag like this:

// <blog_root>/scripts/injector.js
hexo.extend.injector.register('head_end', '<script async defer data-website-id="<your-website-id>" src="<your-umami-url>"></script>');

Then you can track events using CSS classes or Javascript

For example:

<button id="signup-button" class="button umami--click--signup-button">Sign up</button>
// in your custom js
function addUmamiClickEvent(sel, name) {
  const el = document.querySelector(sel);
  el && el.addEventListener('click', () => {
    window.umami(name);
  });
}
addUmamiClickEvent('#search', 'click search btn');
chitang233 commented 1 year ago

Thanks, that's quite useful!