File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
plugins/web-worker-offloading/third-party Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,10 @@ function plwwo_google_site_kit_configure( $configuration ): array {
26
26
$ configuration ['globalFns ' ][] = 'gtag ' ; // Because gtag() is defined in one script and called in another.
27
27
$ configuration ['forward ' ][] = 'dataLayer.push ' ; // Because the Partytown integration has this in its example config.
28
28
29
+ // See <https://github.com/google/site-kit-wp/blob/440dcd6e8289a8776acc60ecb3c13f99bfd0ac5a/includes/Core/Consent_Mode/Consent_Mode.php#L239-L240>.
30
+ $ configuration ['mainWindowAccessors ' ][] = '_googlesitekitConsentCategoryMap ' ;
31
+ $ configuration ['mainWindowAccessors ' ][] = '_googlesitekitConsents ' ;
32
+
29
33
return $ configuration ;
30
34
}
31
35
add_filter ( 'plwwo_configuration ' , 'plwwo_google_site_kit_configure ' );
@@ -35,3 +39,23 @@ function plwwo_google_site_kit_configure( $configuration ): array {
35
39
'google_gtagjs ' ,
36
40
)
37
41
);
42
+
43
+ /**
44
+ * Filters inline script attributes to offload Rank Math's GTag script tag to Partytown.
45
+ *
46
+ * @since n.e.x.t
47
+ * @access private
48
+ * @link https://github.com/rankmath/seo-by-rank-math/blob/c78adba6f78079f27ff1430fabb75c6ac3916240/includes/modules/analytics/class-gtag.php#L169-L174
49
+ *
50
+ * @param array|mixed $attributes Script attributes.
51
+ * @return array|mixed Filtered inline script attributes.
52
+ */
53
+ function plwwo_google_site_kit_filter_inline_script_attributes ( $ attributes ) {
54
+ if ( isset ( $ attributes ['id ' ] ) && 'google_gtagjs-js-consent-mode-data-layer ' === $ attributes ['id ' ] ) {
55
+ wp_enqueue_script ( 'web-worker-offloading ' );
56
+ $ attributes ['type ' ] = 'text/partytown ' ;
57
+ }
58
+ return $ attributes ;
59
+ }
60
+
61
+ add_filter ( 'wp_inline_script_attributes ' , 'plwwo_google_site_kit_filter_inline_script_attributes ' );
You can’t perform that action at this time.
0 commit comments