Comments (11)
@Mizyan take a look at this : https://itnext.io/how-to-add-google-tag-manager-to-an-angular-application-fc68624386e2
from angular-google-tag-manager.
Hi Mizyan,
to use the service you simply need to provide it in your module (take a look to the readme)
then inject it in your controller's constructor like:
constructor(
private router: Router,
...
private gtmService: GoogleTagManagerService,
) {
the simplest way to use the library is provide it in your module and just invoke the "pushTag" method, gtm tags will be added to dom automatically, example:
this.gtmService.pushTag({vent: 'application_loaded'});
if for some reason you don't want to push any tags simply invoke the "addGtmToDom" method in any controller of your application, controllers outside the router outlet are the best ones (In my applications I use it in the header conntroller)
the library is extracted from a service that my company is using in production with angular 8 applications so should work fine with angular 8
feel free to contact me for further information
from angular-google-tag-manager.
exactly, you have to invoke the pushTag method for the events you want to track ()
I'm currently working on a small example application to include in the repository
from angular-google-tag-manager.
I think you have some issues inside your google tag manager configuration, you need to to setup your gtm to recive the informations and send it to analytics (take a look to this tutorial )
You can check the tracked events in your agular application by watching the variable "dataLayer" in your chrome console
[
{
"gtm.start": 1579076379537,
"event": "gtm.js"
},
{
"event": "page",
"pageName": "/"
},
{
"event": "page",
"pageName": "/page1"
},
{
"event": "button-click",
"data": "my-custom-event"
}
]
every time you navigate to a page o trigger an event this array will grow if the dataLayer is fine your angular setup is OK, you only need to properly configure GTM, i think you need to set add an "all pages" trigger and link it to analytics, take a look to the official google documentation
page don't have fixed attributes, you can sent to GTM every kind of custom information required by your "SEO guys"
I'm working on a complete tutorial but it require some time, I will publish it as soon as possible.
from angular-google-tag-manager.
Thank you for update, It is working, But still the google analytics not changes until refresh the page. Have i to invoke pushTag method for pageviews?
I used your code:
this.router.events.forEach(item => {
if (item instanceof NavigationEnd) {
const gtmTag = {
event: 'page',
pageName: item.url
};
this.gtmService.pushTag(gtmTag);
}
});
Sorry for bothering you, But from where i can get those?
event: 'page',
pageName: item.url
from angular-google-tag-manager.
in the last commits you can find a working example in the demo-application folder
from angular-google-tag-manager.
Hello @mzuccaroli
Thank you very much for your updates, But i face a problem (and it is exist in your demo too).
in real time analytics, the urls are not changed.
Sometimes the url changed, sometimes no changed. I tried to change the component but no effect.
Question about this please:
event: 'page',
pageName: item.url
page is fixed attributes? and pageName? can i use it too? where i can find it in my GTM? I just want to apply this for pageviews (google analytics)
Many thanks
from angular-google-tag-manager.
Many thanks! @mzuccaroli
from angular-google-tag-manager.
Many thanks @mzuccaroli
It is woking, the problem was in my GTM, and i solved it.
from angular-google-tag-manager.
Documentation for open-source projects should not be located behind paywalls.
from angular-google-tag-manager.
I'm sorry but this is not a library issue is a GTM misconfiguration, that is not purpose of this project.
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.