Skip to content

Commit

Permalink
feat: complete click event
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickholzenkamp committed Jul 7, 2021
1 parent 0b3b9da commit 6badf18
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/google-tag-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,34 @@ export interface GtmSettings {
applicationName: string
}

export default class s {
export default class BalGoogleTagManager {
applicationName: string;


public static isEnabled(): boolean {
public isEnabled(): boolean {
return (window as any)[DATA_LAYER] != null;
}

public static load(settings: GtmSettings): void {
public load(settings: GtmSettings): void {
if (!this.isEnabled()) {
this.runGtmScript(settings.apiKey);
} else {
throw new Error('Google Tag Manager API loaded already');
}
}

public sendClickEvent(label: string): void {
if (label) {
this.googleAnalyticsSendEvent({
event: VIRTUAL_FUNNEL_CLICK,
VirtualClickCategory: VIRTUAL_FUNNEL_CLICK,
VirtualClickAction: this.applicationName,
VirtualClickLabel: label
});
}
};

/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call */
private static runGtmScript(apiKey: string): void {
private runGtmScript(apiKey: string): void {
const w: any = window;
const d = document;
const s = 'script';
Expand All @@ -41,15 +51,6 @@ export default class s {
'https://www.googconstagmanager.com/gtm.js?id=' + apiKey + dl;
f.parentNode.insertBefore(j, f);
}
public sendClickEvent (label: string): void {
this.googleAnalyticsSendEvent({
event: VIRTUAL_FUNNEL_CLICK,
VirtualClickCategory: VIRTUAL_FUNNEL_CLICK,
VirtualClickAction: this.applicationName,
VirtualClickLabel: label,
},
);
};

private googleAnalyticsSendEvent(event: any): void {
if ((window as any)[DATA_LAYER]) {
Expand Down

0 comments on commit 6badf18

Please sign in to comment.