Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove window.gtag function #54

Merged
merged 7 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"],
flashdesignory marked this conversation as resolved.
Show resolved Hide resolved
"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}}'})",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is also a breaking change

"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;
flashdesignory marked this conversation as resolved.
Show resolved Hide resolved
}

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

export interface GoogleAnalyticsApi {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is technically a breaking change for the types

it's probably safe as i can't imagine anyone besides Nuxt Scripts using it but please be mindful of these changes down the line

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct, Nuxt Script is currently the only framework using the types from here

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

/* 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;
flashdesignory marked this conversation as resolved.
Show resolved Hide resolved
}

/* Google Maps Embed */
Expand Down
Loading