Skip to content

Commit 6a89d7b

Browse files
committed
Ensure gtag() can be called from main thread
1 parent eeb4327 commit 6a89d7b

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

plugins/web-worker-offloading/third-party/google-site-kit.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@
2323
function plwwo_google_site_kit_configure( $configuration ): array {
2424
$configuration = (array) $configuration;
2525

26-
$configuration['globalFns'][] = 'gtag'; // Because gtag() is defined in one script and called in another.
27-
$configuration['globalFns'][] = 'wp_has_consent'; // See <https://github.com/google/site-kit-wp/blob/abbb74ff21f98a8779fbab0eeb9a16279a122bc4/assets/js/consent-mode/consent-mode.js#L61C13-L61C27>.
28-
$configuration['forward'][] = 'dataLayer.push'; // See <https://partytown.builder.io/forwarding-event>.
26+
$configuration['globalFns'][] = 'gtag'; // Allow calling from other Partytown scripts.
27+
$configuration['globalFns'][] = 'wp_has_consent'; // Allow calling function from main thread. See <https://github.com/google/site-kit-wp/blob/abbb74ff21f98a8779fbab0eeb9a16279a122bc4/assets/js/consent-mode/consent-mode.js#L61C13-L61C27>.
28+
29+
// Expose on the main tread. See <https://partytown.builder.io/forwarding-event>.
30+
$configuration['forward'][] = 'dataLayer.push';
31+
$configuration['forward'][] = 'gtag';
2932

3033
// See <https://github.com/google/site-kit-wp/blob/abbb74ff21f98a8779fbab0eeb9a16279a122bc4/includes/Core/Consent_Mode/Consent_Mode.php#L244-L259>,
3134
// and <https://github.com/google/site-kit-wp/blob/abbb74ff21f98a8779fbab0eeb9a16279a122bc4/assets/js/consent-mode/consent-mode.js>.

plugins/web-worker-offloading/third-party/seo-by-rank-math.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ function plwwo_rank_math_configure( $configuration ): array {
2424
$configuration = (array) $configuration;
2525

2626
$configuration['globalFns'][] = 'gtag'; // Because gtag() is defined in one script and called in another.
27-
$configuration['forward'][] = 'dataLayer.push'; // See <https://partytown.builder.io/forwarding-event>.
27+
28+
// Expose on the main tread. See <https://partytown.builder.io/forwarding-event>.
29+
$configuration['forward'][] = 'dataLayer.push';
30+
$configuration['forward'][] = 'gtag';
2831
return $configuration;
2932
}
3033
add_filter( 'plwwo_configuration', 'plwwo_rank_math_configure' );

plugins/web-worker-offloading/third-party/woocommerce.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,15 @@
2323
function plwwo_woocommerce_configure( $configuration ): array {
2424
$configuration = (array) $configuration;
2525

26+
$configuration['globalFns'][] = 'gtag'; // Allow calling from other Partytown scripts.
27+
28+
// Expose on the main tread. See <https://partytown.builder.io/forwarding-event>.
29+
$configuration['forward'][] = 'dataLayer.push';
30+
$configuration['forward'][] = 'gtag';
31+
2632
$configuration['mainWindowAccessors'][] = 'wp'; // Because woocommerce-google-analytics-integration needs to access wp.i18n.
2733
$configuration['mainWindowAccessors'][] = 'ga4w'; // Because woocommerce-google-analytics-integration needs to access window.ga4w.
28-
$configuration['globalFns'][] = 'gtag'; // Because gtag() is defined in one script and called in another.
29-
$configuration['forward'][] = 'dataLayer.push'; // Because the Partytown integration has this in its example config.
34+
3035
return $configuration;
3136
}
3237
add_filter( 'plwwo_configuration', 'plwwo_woocommerce_configure' );

0 commit comments

Comments
 (0)