Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ga4 #591

Merged
merged 2 commits into from
Sep 15, 2023
Merged

Ga4 #591

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions views/index.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<head>
{{gaCode}}
<title>{{title}}</title>
<meta charset="UTF-8">
<meta name="description" content="{{description}}">
Expand Down
Loading