diff --git a/scripts/deploy.js b/scripts/deploy.js index 176a4c437bcc94ac2d74e524995def9088f344e1..5fde259a00cac0e03fe680410768fabd5d42dc0d 100644 --- a/scripts/deploy.js +++ b/scripts/deploy.js @@ -14,6 +14,9 @@ const buildDir = path.resolve(__dirname, '../build/'); const deployDir = path.resolve(buildDir, 'deploy/'); const localPath = path.resolve(deployDir, 'molstar.github.io/'); +const analyticsTag = /<!-- __MOLSTAR_ANALYTICS__ -->/g; +const analyticsCode = `<!-- Cloudflare Web Analytics --><script defer src='https://static.cloudflareinsights.com/beacon.min.js' data-cf-beacon='{"token": "c414cbae2d284ea995171a81e4a3e721"}'></script><!-- End Cloudflare Web Analytics -->`; + function log(command, stdout, stderr) { if (command) { console.log('\n###', command); @@ -22,11 +25,18 @@ function log(command, stdout, stderr) { } } +function addAnalytics(path) { + const data = fs.readFileSync(path, 'utf8'); + const result = data.replace(analyticsTag, analyticsCode); + fs.writeFileSync(path, result, 'utf8'); +} + function copyViewer() { console.log('\n###', 'copy viewer files'); const viewerBuildPath = path.resolve(buildDir, '../build/viewer/'); const viewerDeployPath = path.resolve(localPath, 'viewer/'); fse.copySync(viewerBuildPath, viewerDeployPath, { overwrite: true }); + addAnalytics(path.resolve(viewerDeployPath, 'index.html')); } if (!fs.existsSync(localPath)) { diff --git a/src/apps/viewer/index.html b/src/apps/viewer/index.html index 40af8122b84c07e39c0c4392580fa905b75b0165..90808052807b6f987b53a46e6de5d7af670d4f72 100644 --- a/src/apps/viewer/index.html +++ b/src/apps/viewer/index.html @@ -91,5 +91,6 @@ var emdb = getParam('emdb', '[^&]+').trim(); if (emdb) viewer.loadEmdb(emdb); </script> + <!-- __MOLSTAR_ANALYTICS__ --> </body> </html> \ No newline at end of file