Skip to content

Commit

Permalink
remove window.gtag function (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
flashdesignory authored Jul 24, 2024
1 parent 92b1495 commit d39b6a0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/third-parties/google-analytics/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
"scripts": [
{
"url": "https://www.googletagmanager.com/gtag/js",
"params": ["id"],
"params": ["id", "l"],
"strategy": "worker",
"location": "head",
"action": "append",
"key": "gtag"
},
{
"code": "window.dataLayers=window.dataLayers||{};window.dataLayers['{{dataLayerName}}']=window.dataLayers['{{dataLayerName}}']||[];window.gtag=function gtag(){window.dataLayers['{{dataLayerName}}'].push(arguments);};window.gtag('js',new Date());window.gtag('config','{{id}}')",
"params": ["id", "dataLayerName"],
"code": "window['{{l}}']=window['{{l}}']||[];window['{{l}}'].push({'js':new Date()});window['{{l}}'].push({'config':'{{id}}'})",
"params": ["id", "l"],
"strategy": "worker",
"location": "head",
"action": "append",
Expand Down
6 changes: 3 additions & 3 deletions src/third-parties/google-tag-manager/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
"scripts": [
{
"url": "https://www.googletagmanager.com/gtm.js",
"params": ["id"],
"params": ["id", "l"],
"strategy": "worker",
"location": "head",
"action": "append",
"key": "gtm"
},
{
"code": "window.dataLayers=window.dataLayers||{};window.dataLayers['{{dataLayerName}}']=window.dataLayers['{{dataLayerName}}']||[];window.dataLayers['{{dataLayerName}}'].push({'gtm.start':new Date().getTime(),event:'gtm.js'});",
"params": ["dataLayerName"],
"code": "window['{{l}}']=window['{{l}}']||[];window['{{l}}'].push({'gtm.start':new Date().getTime(),event:'gtm.js'});",
"params": ["l"],
"strategy": "worker",
"location": "head",
"action": "append",
Expand Down
18 changes: 11 additions & 7 deletions src/types/type-declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ export interface Output {
/* Google Analytics */
export interface GoogleAnalyticsParams {
id: string;
/**
* The name of the dataLayer object. Defaults to 'dataLayer'.
*/
l?: string;
}

export interface GTag {
Expand All @@ -75,14 +79,15 @@ export interface GTag {
(fn: 'config', opt: 'reset'): void;
}

export interface GoogleAnalyticsApi {
dataLayers: Record<string, Record<string, any>[]>;
gtag: GTag;
}
export type DataLayer = Record<string, unknown>[];

/* Google Tag Manager */
export interface GoogleTagManagerParams {
id: string;
/**
* The name of the dataLayer object. Defaults to 'dataLayer'.
*/
l?: string;
}

interface GoogleTagManagerDataLayerApi {
Expand All @@ -100,16 +105,15 @@ type GoogleTagManagerDataLayerStatus = {
};
};

export type GoogleTagManager = GoogleTagManagerDataLayerStatus & {
export type GoogleTagManagerInstance = GoogleTagManagerDataLayerStatus & {
[key: string]: {
callback: () => void;
dataLayer: GoogleTagManagerDataLayerApi;
};
};

export interface GoogleTagManagerApi {
dataLayers: Record<string, Record<string, any>[]>;
google_tag_manager: GoogleTagManager;
google_tag_manager: GoogleTagManagerInstance;
}

/* Google Maps Embed */
Expand Down

0 comments on commit d39b6a0

Please sign in to comment.