Skip to content

Commit

Permalink
chore: add tianji analytics script
Browse files Browse the repository at this point in the history
  • Loading branch information
moonrailgun committed Oct 22, 2023
1 parent 67a0e8f commit bdd240a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
28 changes: 19 additions & 9 deletions client/web/build/inject-analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,25 @@ const path = require('path');

const templatePath = path.resolve(__dirname, '../assets/template.html');

console.log('templatePath', templatePath);

function appendScript(script) {
let template = fs.readFileSync(templatePath, {
encoding: 'utf-8',
});
template = template.replace('</head>', script + '</head>');

fs.writeFileSync(templatePath, template);
}

// frontjs
// const script = `<script type="text/javascript">(function (w) {w.frontjsConfig={token:"acd42b4b4e2b2a9fa33b36e9cd60e866",behaviour:15,captureConsoleLog:true,trustVendor:true,ignoreVendor:true,optimisedForSPA:true,useHistory:true,FPSThreshold:10};w.frontjsTmpData = {r:[],e:[],l:[]};w.frontjsTmpCollector = function (ev) {(ev.message ? window.frontjsTmpData.e : window.frontjsTmpData.r).push([new Date().getTime(), ev])};w.FrontJS = {addEventListener: function (t, f) {w.frontjsTmpData.l.push([t, f]);return f;},removeEventListener: function (t, f) {for (var i = 0; i < w.frontjsTmpData.l.length; i++) {t === w.frontjsTmpData.l[i][0] && f === w.frontjsTmpData.l[i][1] && w.frontjsTmpData.l.splice(i, 1);}return f;}};w.document.addEventListener("error", w.frontjsTmpCollector, true);w.addEventListener("error", w.frontjsTmpCollector, true);w.addEventListener("load", function () {var n = w.document.createElement("script");n.src = "https://frontjs-static.pgyer.com/dist/current/frontjs.web.min.js"; w.document.body.appendChild(n);}, true);})(window);</script>`;
// umami
const script = `<script async defer data-website-id="550cf175-3bd2-4292-b0a8-ccdf85f7b807" src="https://umami.moonrailgun.com/script.js"></script>`;

console.log('templatePath', templatePath);
let template = fs.readFileSync(templatePath, {
encoding: 'utf-8',
});
template = template.replace('</head>', script + '</head>');

fs.writeFileSync(templatePath, template);
// umami
appendScript(
`<script async defer data-website-id="550cf175-3bd2-4292-b0a8-ccdf85f7b807" src="https://umami.moonrailgun.com/script.js"></script>`
);
// tianji
appendScript(
`<script async src="https://tianji.moonrailgun.com/tracker.js" data-website-id="clo1893di0001o65edzck6q6z"></script>`
);
8 changes: 8 additions & 0 deletions website/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,12 @@ module.exports = {
'data-website-id': '22f7ff7b-db54-4222-b123-c8e3acfbf1aa',
},
],
scripts: [
{
src: 'https://tianji.moonrailgun.com/tracker.js',
async: true,
defer: true,
'data-website-id': 'clo189w7r0003o65exm2pvdnp',
},
],
};

0 comments on commit bdd240a

Please sign in to comment.