Skip to content

Commit

Permalink
add ga config
Browse files Browse the repository at this point in the history
  • Loading branch information
ety001 committed Sep 15, 2023
1 parent c7dd965 commit be8beb6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ DELAY_SEND_SMS_TIMEOUT_WHEN_REG_NOT_SUCCESS=7200
HIGH_FREQUENCY_TIME_RANGE=2
HIGH_FREQUENCY_COUNT=10
CREATOR_INFO=steem|steemcurator01|steemcurator02|booming01|booming02|booming03|booming04
GOOGLE_ANALYTICS_ID=
14 changes: 14 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ https.globalAgent.maxSockets = 100;

const app = express();
const clientConfig = getClientConfig();
const clientConfigObject = JSON.parse(clientConfig);

// database cleanup task
// removes actions and completed requests older than 60 days
Expand Down Expand Up @@ -98,6 +99,19 @@ hbs.registerHelper('clientConfig', () => clientConfig);
hbs.registerHelper('baseCss', () => new hbs.SafeString(process.env.NODE_ENV !== 'production' ? '' : '<link rel="stylesheet" href="/css/base.css" type="text/css" media="all"/>'));
hbs.registerHelper('baseJs', () => new hbs.SafeString(`<script type="text/javascript" src="/js/${baseJsFile}"></script>`));
hbs.registerHelper('recaptchaJs', () => new hbs.SafeString(process.env.RECAPTCHA_SWITCH !== 'OFF' ? '<script src="//www.google.com/recaptcha/api.js"></script>' : ''));
hbs.registerHelper('gaCode', () => {
let gaCode = '';
if (clientConfigObject) {
gaCode = `<script async src="https://www.googletagmanager.com/gtag/js?id=${clientConfigObject.GOOGLE_ANALYTICS_ID}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${clientConfigObject.GOOGLE_ANALYTICS_ID}');
</script>`;
}
return new hbs.SafeString(gaCode);
});
hbs.registerPartials(`${__dirname}/views/partials`);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'hbs');
Expand Down
1 change: 1 addition & 0 deletions helpers/getClientConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function getClientConfig() {
'RECAPTCHA_SWITCH',
'PENDING_CLAIMED_ACCOUNTS_THRESHOLD',
'CREATOR_INFO',
'GOOGLE_ANALYTICS_ID',
];

return JSON.stringify(
Expand Down
9 changes: 1 addition & 8 deletions views/index.hbs
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-5ELS7X2YN3"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-5ELS7X2YN3');
</script>
{{gaCode}}
<title>{{title}}</title>
<meta charset="UTF-8">
<meta name="description" content="{{description}}">
Expand Down

0 comments on commit be8beb6

Please sign in to comment.