Skip to content

Commit

Permalink
chore: fake gtag function in dev & test env if forceEnable is not true (
Browse files Browse the repository at this point in the history
  • Loading branch information
romgere authored Oct 25, 2023
1 parent 9b54b3e commit 0c15728
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions app/initializers/gtag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ const { gTag, environment } = config;

export function initialize() {
if (!gTag?.forceEnable && ['development', 'test'].includes(environment)) {
// Just define gtag function to prevent dev/test to fail
fakeGtag();
return;
} else if (!gTag?.tag) {
console.error('no GTAG defined, skipping Gtag script load');
return;
}

Expand All @@ -31,6 +34,14 @@ function initGtag() {
document.body.appendChild(script);
}

function fakeGtag() {
const script = document.createElement('script');
script.innerHTML = `function gtag(){}`;

// Append the script tag to the document.
document.body.appendChild(script);
}

export default {
initialize,
};
2 changes: 1 addition & 1 deletion config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = function (environment) {

gTag: {
tag: 'G-47QBQ5GB3Y',
forceEnable: true,
// forceEnable: true, // For testing
},

'ember-toggle': {
Expand Down

0 comments on commit 0c15728

Please sign in to comment.