Skip to content

Commit 0c600c6

Browse files
Merge pull request #79 from wafflestudio/fix/ga4
fix: restore ensureGtag return value to fix TypeScript build error
2 parents f7efd56 + 2e51f87 commit 0c600c6

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

src/lib/ga4.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ const ensureDataLayer = () => {
1818

1919
const ensureGtag = () => {
2020
if (typeof window.gtag === "function") {
21-
return;
21+
return window.gtag;
2222
}
2323

2424
window.gtag = function gtag(...args: unknown[]) {
2525
window.dataLayer?.push(args);
2626
};
27+
28+
return window.gtag;
2729
};
2830

2931
const loadGtagScript = (measurementId: string) => {
@@ -48,14 +50,14 @@ export const initGA4 = () => {
4850
const measurementId = getMeasurementId();
4951

5052
ensureDataLayer();
51-
ensureGtag();
53+
const gtag = ensureGtag();
5254
loadGtagScript(measurementId);
5355

54-
window.gtag("js", new Date());
55-
window.gtag("config", measurementId, {
56+
gtag("js", new Date());
57+
gtag("config", measurementId, {
5658
send_page_view: false,
5759
});
58-
window.gtag("set", "user_properties", DEFAULT_USER_PROPERTIES);
60+
gtag("set", "user_properties", DEFAULT_USER_PROPERTIES);
5961

6062
initialized = true;
6163
};

0 commit comments

Comments
 (0)