Skip to content
Snippets Groups Projects
Commit ccaf18af authored by Alexander Rose's avatar Alexander Rose
Browse files

add analytics to viewer on deployment

- only for molstar.org (done in ./scripts/deploy.js)
parent 2b72098f
No related branches found
No related tags found
No related merge requests found
...@@ -14,6 +14,9 @@ const buildDir = path.resolve(__dirname, '../build/'); ...@@ -14,6 +14,9 @@ const buildDir = path.resolve(__dirname, '../build/');
const deployDir = path.resolve(buildDir, 'deploy/'); const deployDir = path.resolve(buildDir, 'deploy/');
const localPath = path.resolve(deployDir, 'molstar.github.io/'); 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) { function log(command, stdout, stderr) {
if (command) { if (command) {
console.log('\n###', command); console.log('\n###', command);
...@@ -22,11 +25,18 @@ function log(command, stdout, stderr) { ...@@ -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() { function copyViewer() {
console.log('\n###', 'copy viewer files'); console.log('\n###', 'copy viewer files');
const viewerBuildPath = path.resolve(buildDir, '../build/viewer/'); const viewerBuildPath = path.resolve(buildDir, '../build/viewer/');
const viewerDeployPath = path.resolve(localPath, 'viewer/'); const viewerDeployPath = path.resolve(localPath, 'viewer/');
fse.copySync(viewerBuildPath, viewerDeployPath, { overwrite: true }); fse.copySync(viewerBuildPath, viewerDeployPath, { overwrite: true });
addAnalytics(path.resolve(viewerDeployPath, 'index.html'));
} }
if (!fs.existsSync(localPath)) { if (!fs.existsSync(localPath)) {
......
...@@ -91,5 +91,6 @@ ...@@ -91,5 +91,6 @@
var emdb = getParam('emdb', '[^&]+').trim(); var emdb = getParam('emdb', '[^&]+').trim();
if (emdb) viewer.loadEmdb(emdb); if (emdb) viewer.loadEmdb(emdb);
</script> </script>
<!-- __MOLSTAR_ANALYTICS__ -->
</body> </body>
</html> </html>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment