-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1563 from WordPress/add/wwo-gtag-offloading
Integrate with WooCommerce to offload Google Analytics to Web Worker
- Loading branch information
Showing
10 changed files
with
348 additions
and
124 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
"optimization-detective", | ||
"performance-lab", | ||
"speculation-rules", | ||
"web-worker-offloading", | ||
"webp-uploads" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
/** | ||
* Helpers for Web Worker Offloading. | ||
* | ||
* @since 0.1.0 | ||
* @package web-worker-offloading | ||
*/ | ||
|
||
if ( ! defined( 'ABSPATH' ) ) { | ||
exit; // Exit if accessed directly. | ||
} | ||
|
||
/** | ||
* Gets configuration for Web Worker Offloading. | ||
* | ||
* @since 0.1.0 | ||
* @link https://partytown.builder.io/configuration | ||
* @link https://github.com/BuilderIO/partytown/blob/b292a14047a0c12ca05ba97df1833935d42fdb66/src/lib/types.ts#L393-L548 | ||
* | ||
* @return array<string, mixed> Configuration for Partytown. | ||
*/ | ||
function wwo_get_configuration(): array { | ||
$config = array( | ||
'lib' => wp_parse_url( plugin_dir_url( __FILE__ ), PHP_URL_PATH ) . 'build/', | ||
); | ||
|
||
if ( WP_DEBUG && SCRIPT_DEBUG ) { | ||
$config['debug'] = true; | ||
} | ||
|
||
/** | ||
* Add configuration for Web Worker Offloading. | ||
* | ||
* Many of the configuration options are not documented publicly, so refer to the TypeScript definitions. | ||
* Additionally, not all of the configuration options (e.g. functions) can be serialized as JSON and must instead be | ||
* defined in JavaScript instead. To do so, use the following PHP code instead of filtering `wwo_configuration`: | ||
* | ||
* add_action( | ||
* 'wp_enqueue_scripts', | ||
* function () { | ||
* wp_add_inline_script( | ||
* 'web-worker-offloading', | ||
* <<<JS | ||
* window.partytown = { | ||
* ...(window.partytown || {}), | ||
* resolveUrl: (url, location, type) => { | ||
* if (type === 'script') { | ||
* const proxyUrl = new URL('https://my-reverse-proxy.example.com/'); | ||
* proxyUrl.searchParams.append('url', url.href); | ||
* return proxyUrl; | ||
* } | ||
* return url; | ||
* }, | ||
* }; | ||
* JS, | ||
* 'before' | ||
* ); | ||
* } | ||
* ); | ||
* | ||
* There are also many configuration options which are not documented, so refer to the TypeScript definitions. | ||
* | ||
* @since 0.1.0 | ||
* @link https://partytown.builder.io/configuration | ||
* @link https://github.com/BuilderIO/partytown/blob/b292a14047a0c12ca05ba97df1833935d42fdb66/src/lib/types.ts#L393-L548 | ||
* | ||
* @param array<string, mixed> $config Configuration for Partytown. | ||
*/ | ||
return (array) apply_filters( 'wwo_configuration', $config ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.