Comments (8)
you could probably do it with a useFactory function instead of useValue
something like:
providers: [
{provide: 'googleTagManagerId', useFactory: () => {
if (window.location.href.toString().includes('gtagId')) {
const vars = {};
const parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,
function(m,key,value) {
return vars[key] = value;
});
return vars['gtagId'] || 'SOME_SENSIBLE_DEFAULT_IF_POSSIBLE';
}
}
],
from angular-google-tag-manager.
I think that the source of the problem could be the usage of "window.location.href", global variables are usually messy
have you tried using the angular ActivatedRoute?
from angular-google-tag-manager.
This is in my app.module file so Im unsure if I can access ActivatedRoute at this point. Is that possible and or smart to do?
Also, its still logging the correct gtagId. So the variable should be fine
from angular-google-tag-manager.
Just added some more logs and getting same error. I dont think its the window object as its returning true prior to the gtag error:
Here is what was logged:
GTM-WBJL4SD
main-es2015.932a9cccfc421ae0b4a2.js:1 true "GTM-WBJL4SD"
Here us the code
let gtmId = '';
if (window.location.href.toString().includes('gtagId')) {
const vars = {};
const parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
return vars[key] = value;
});
gtmId = vars['gtagId'];
console.log(gtmId);
}
console.log(window.location.href.toString().includes('gtagId'), gtmId);
from angular-google-tag-manager.
from angular-google-tag-manager.
Do you have any other suggestions on how to make the gtagId dyanmic?
from angular-google-tag-manager.
if you build your production code and run it from your dist folder you have the same issue?
also a good (and safer) idea to make your gtmId dynamic is retrieve it from a dedicated API or a AWS Systems Manager Parameter Store, than leaving it on on query string
from angular-google-tag-manager.
Same error when building in production ng serve --prod
. When I run ng serve without the --prod flag it works fine. I cant nail down why this is happening.
from angular-google-tag-manager.
Related Issues (20)
- ERROR in ./node_modules/angular-google-tag-manager/fesm2015/angular-google-tag-manager.mjs 32:30-36 Can't import the named export 'Inject' from non EcmaScript module (only default export is available) HOT 8
- Dublicated tag fire
- Wrong documentation? HOT 10
- Null-Like GTM-ID should not throw an error HOT 3
- document is not defined on SSR
- Weird appendage
- Angular 15 support HOT 1
- The library does not add GTM script to the DOM HOT 3
- Push values into the data layer HOT 1
- Unable to import angular-google-tag-manager-config.service HOT 7
- Unable to resolve dependency tree - v1.6.1 tries to check v1.7.0 HOT 1
- Clear the dataLayer HOT 1
- gtm_resource_path appends to url
- Add tag at the beginning of dataLayer
- Console exception when loading GTM using the library HOT 1
- Angular 16 support HOT 7
- Youtube video keep emitting gtm.video after navigating away HOT 3
- Unable to resolve dependency tree. v1.7.0 tries to check v1.8.0
- Angular 17 Support HOT 11
- Feature request: Add removeGtmFromDom function to GoogleTagManagerService
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-google-tag-manager.