YunYouJun/hexo-theme-yun

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

chitang233 opened this issue · 4 comments

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

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

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

No, I can't write themes

@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');

Thanks, that's quite useful!