Skip to main content

Analytics

The theme has built-in config for Baidu Analytics and Google Analytics — no manual script injection needed.

Baidu Analytics

# Baidu Webmaster verification code
# See: https://ziyuan.baidu.com/site
baidu_site_verification:

# Baidu Analytics App ID
# See: https://tongji.baidu.com
baidu_analytics: # <app_id>
FieldDescription
baidu_site_verificationBaidu Webmaster verification code (for search engine ownership verification)
baidu_analyticsBaidu Analytics App ID — auto-injects the tracking script when set

Getting the App ID

  1. Sign in to Baidu Analytics and add your site.
  2. In "Code Acquisition", find the ID in hm.js?xxxxxxxxxxxxxxxxx.
  3. Fill it into baidu_analytics.

Google Analytics

google_ad:
enable: false
meta_tag: "G-XXXXXXXXXX" # Google Analytics 4 Measurement ID
FieldDescription
google_ad.enableWhether to enable Google Analytics
google_ad.meta_tagGoogle Analytics 4 Measurement ID, format G-XXXXXXXXXX

Getting the Measurement ID

  1. Sign in to Google Analytics and create a GA4 property.
  2. In "Data Streams", find the Measurement ID (starts with G-).
  3. Fill it into google_ad.meta_tag and set enable: true.

Other analytics services

For services not built into the theme (Umami, Plausible, 51.LA, CNZZ, etc.), inject the code via Inject Custom Head Code. Example with Umami:

// scripts/custom-head.js
hexo.extend.injector.register('head_end', `
<script async defer data-website-id="your-website-id" src="https://umami.example.com/script.js"></script>
`, 'all');

Privacy & compliance

  • GDPR / Cookie laws: Baidu Analytics and Google Analytics collect user data. Sites serving European users must disclose this in a privacy policy and obtain consent.
  • Cookie-less alternatives: for privacy-conscious sites, try Umami or Plausible (self-hosted or SaaS, no cookies, no PII).
  • Do Not Track: privacy-focused analytics tools respect the user's DNT preference and skip data collection.