Browse Source

add ga code

master
filesite 3 weeks ago
parent
commit
7d96c54070
  1. 4
      conf/config.json
  2. 25
      i18n.mjs
  3. 10
      public/de/index.html
  4. 10
      public/en-us/index.html
  5. 10
      public/es/index.html
  6. 10
      public/hi/index.html
  7. 10
      public/index.html
  8. 10
      public/ja/index.html
  9. 10
      public/ru/index.html
  10. 10
      public/template/index.html
  11. 10
      public/zh-tw/index.html
  12. 10
      public/zh/index.html

4
conf/config.json

@ -26,5 +26,9 @@ @@ -26,5 +26,9 @@
"tokens": {
"herounion_demo": "hello#world!"
},
"templateConfigs": {
"GTAG_ID": "G-DZRYEJF89T"
}
}

25
i18n.mjs

@ -13,11 +13,12 @@ import common from './common.mjs'; @@ -13,11 +13,12 @@ import common from './common.mjs';
class I18N {
//构造函数,设置默认配置
constructor(defaultLang, templateDir, langDir, buildDir) {
constructor(defaultLang, templateDir, langDir, buildDir, configFilename) {
this.defaultLang = typeof(defaultLang) != 'undefined' && defaultLang ? defaultLang : 'en';
this.templateDir = typeof(templateDir) != 'undefined' && templateDir ? templateDir : './public/template/';
this.langDir = typeof(langDir) != 'undefined' && langDir ? langDir : './i18n/';
this.buildDir = typeof(buildDir) != 'undefined' && buildDir ? buildDir : './public/';
this.configFile = typeof(configFilename) != 'undefined' && configFilename ? configFilename : 'config.json';
}
//从模板文件中解析语言占位变量,并生成语言包文件
@ -63,6 +64,7 @@ class I18N { @@ -63,6 +64,7 @@ class I18N {
for (const file of files) {
newHtml = await _self.replaceLangToTemplate(_self.templateDir + file, langData);
if (newHtml) {
newHtml = await _self.replaceConfigToTemplate(newHtml); //replace configs
saved = await _self.saveBuildHtml(langFile.replace('.json', ''), file, newHtml);
console.log('Template file [%s] lang data replace with [%s] done, html build [%s].', file, langFile, (saved ? 'success' : 'failed'));
}
@ -200,6 +202,27 @@ class I18N { @@ -200,6 +202,27 @@ class I18N {
return html;
}
//根据配置文件,替换配置项
async replaceConfigToTemplate(html_template) {
const _self = this;
let html = html_template;
try {
let config = await common.getConfigFromJsonFile(_self.configFile);
if (typeof(config['templateConfigs']) == 'undefined' || !config['templateConfigs']) {return html;}
let tempConfigs = config['templateConfigs'];
for (let key in tempConfigs) {
html = html.replaceAll(`{config:${key}}`, tempConfigs[key]);
}
} catch (err) {
console.error('replaceConfigToTemplate failed', err);
return false;
}
return html;
}
//保存替换了语言包的html文件
async saveBuildHtml(lang, htmlFilename, htmlContent) {
const _self = this;

10
public/de/index.html

@ -276,5 +276,15 @@ @@ -276,5 +276,15 @@
setInterval(loadUnionStats, 20000);
</script>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-DZRYEJF89T"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-DZRYEJF89T');
</script>
</body>
</html>

10
public/en-us/index.html

@ -276,5 +276,15 @@ @@ -276,5 +276,15 @@
setInterval(loadUnionStats, 20000);
</script>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-DZRYEJF89T"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-DZRYEJF89T');
</script>
</body>
</html>

10
public/es/index.html

@ -276,5 +276,15 @@ @@ -276,5 +276,15 @@
setInterval(loadUnionStats, 20000);
</script>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-DZRYEJF89T"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-DZRYEJF89T');
</script>
</body>
</html>

10
public/hi/index.html

@ -276,5 +276,15 @@ @@ -276,5 +276,15 @@
setInterval(loadUnionStats, 20000);
</script>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-DZRYEJF89T"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-DZRYEJF89T');
</script>
</body>
</html>

10
public/index.html

@ -276,5 +276,15 @@ @@ -276,5 +276,15 @@
setInterval(loadUnionStats, 20000);
</script>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-DZRYEJF89T"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-DZRYEJF89T');
</script>
</body>
</html>

10
public/ja/index.html

@ -276,5 +276,15 @@ @@ -276,5 +276,15 @@
setInterval(loadUnionStats, 20000);
</script>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-DZRYEJF89T"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-DZRYEJF89T');
</script>
</body>
</html>

10
public/ru/index.html

@ -276,5 +276,15 @@ @@ -276,5 +276,15 @@
setInterval(loadUnionStats, 20000);
</script>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-DZRYEJF89T"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-DZRYEJF89T');
</script>
</body>
</html>

10
public/template/index.html

@ -276,5 +276,15 @@ @@ -276,5 +276,15 @@
setInterval(loadUnionStats, 20000);
</script>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id={config:GTAG_ID}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{config:GTAG_ID}');
</script>
</body>
</html>

10
public/zh-tw/index.html

@ -276,5 +276,15 @@ @@ -276,5 +276,15 @@
setInterval(loadUnionStats, 20000);
</script>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-DZRYEJF89T"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-DZRYEJF89T');
</script>
</body>
</html>

10
public/zh/index.html

@ -276,5 +276,15 @@ @@ -276,5 +276,15 @@
setInterval(loadUnionStats, 20000);
</script>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-DZRYEJF89T"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-DZRYEJF89T');
</script>
</body>
</html>
Loading…
Cancel
Save