
Research
/Security News
Toptal’s GitHub Organization Hijacked: 10 Malicious Packages Published
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
ng-google-tag-manager
Advanced tools
A service library for integrate google tag manager in your angular project
Fork of "angular-google-tag-manager" as there were some issues that needed to be fixed, and some features that I have added. I am using this in production, so will continue to maintain it and encourage feature requests and pull requests.
A service library for integrate google tag manager in your angular project This library was generated with Angular CLI For more info see this how to install google tag manager article
After installing it you need to provide your GTM id in app.module.ts
providers: [
...
{provide: 'googleTagManagerId', useValue: YOUR_GTM_ID}
],
Or use the module's forRoot
method
import { GoogleTagManagerModule } from 'angular-google-tag-manager';
imports: [
...
GoogleTagManagerModule.forRoot({
id: YOUR_GTM_ID,
})
]
Or use the APP_INITIALIZER
import { GoogleTagManagerConfiguration } from 'angular-google-tag-manager-config.service';
imports: [
...
GoogleTagManagerModule.forRoot()
]
providers: [
{
...
provide: APP_INITIALIZER,
useFactory: configInitializer,
deps: [
HttpBackend,
GoogleTagManagerConfiguration,
],
multi: true,
},
],
set the config in the method assigned to useFactory
googleTagManagerConfiguration.set({id: XYZ});
inject the gtmService in your controller
constructor(
...
private gtmService: GoogleTagManagerService,
) { }
then you can start pushing events on your gtm
this.router.events.forEach(item => {
if (item instanceof NavigationEnd) {
const gtmTag = {
event: 'page',
pageName: item.url
};
this.gtmService.pushTag(gtmTag);
}
});
if you want to recive tags without pushing events simply call the function to enable it
this.gtmService.addGtmToDom();
In your Angular project run
npm i --save angular-google-tag-manager
You can pass gtm_preview and gtm_auth optional variables to your GTM by providing them in app.module.ts
providers: [
...
{provide: 'googleTagManagerId', useValue: YOUR_GTM_ID},
{provide: 'googleTagManagerAuth', useValue: YOUR_GTM_AUTH},
{provide: 'googleTagManagerPreview', useValue: YOUR_GTM_ENV},
{provide: 'googleTagManagerResourcePath', useValue: YOUR_GTM_RESOURCE_PATH},
{provide: 'googleTagManagerCSPNonce', useValue: YOUR_CSP_NONCE},
{provide: 'googleTagManagerMode', useValue: "silent" | "noisy"}
],
Or using forRoot
import { GoogleTagManagerModule } from 'angular-google-tag-manager';
imports: [
...
GoogleTagManagerModule.forRoot({
id: YOUR_GTM_ID,
gtm_auth: YOUR_GTM_AUTH,
gtm_preview: YOUR_GTM_ENV
})
]
Added "Silent mode" to stop error from throwing if GTM can't attach. Particularly useful is dynamically loading GTM ids that may or may not exist.
providers: [
...
{provide: 'googleTagManagerMode', useValue: "silent" | "noisy"}
],
See also the list of contributors who participated in this project.
This project is licensed under the MIT License
FAQs
A service library for integrate google tag manager in your angular project
We found that ng-google-tag-manager demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Research
/Security News
Socket researchers investigate 4 malicious npm and PyPI packages with 56,000+ downloads that install surveillance malware.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.