hexo-theme-amane/layout/plugin/baidu_analytics.jsx

29 lines
836 B
React
Raw Normal View History

2019-12-22 17:16:19 +00:00
const { Component } = require('inferno');
const { cacheComponent } = require('../util/cache');
class BaiduAnalytics extends Component {
render() {
const { trackingId } = this.props;
const js = `var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "//hm.baidu.com/hm.js?${trackingId}";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();`;
return <script dangerouslySetInnerHTML={{ __html: js }}></script>;
}
}
module.exports = cacheComponent(BaiduAnalytics, 'plugin.baiduanalytics', props => {
const { head, plugin } = props;
if (!head || !plugin.tracking_id) {
2019-12-22 17:16:19 +00:00
return null;
}
return {
trackingId: plugin.tracking_id
2019-12-22 17:16:19 +00:00
};
});