| 1 |
<?php |
| 2 |
/** |
| 3 |
* Integrations: Google Web Stories integration class |
| 4 |
* |
| 5 |
* @package Parsely |
| 6 |
* @since 3.2.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
declare(strict_types=1); |
| 10 |
|
| 11 |
namespace Parsely\Integrations; |
| 12 |
|
| 13 |
/** |
| 14 |
* Integrates Parse.ly tracking with the Google Web Stories plugin. |
| 15 |
* |
| 16 |
* @since 3.2.0 |
| 17 |
*/ |
| 18 |
final class Google_Web_Stories implements Integration { |
| 19 |
/** |
| 20 |
* Applies the hooks that integrate the plugin or theme with the Parse.ly |
| 21 |
* plugin. |
| 22 |
* |
| 23 |
* @since 3.2.0 |
| 24 |
*/ |
| 25 |
public function integrate(): void { |
| 26 |
if ( defined( 'WEBSTORIES_PLUGIN_FILE' ) ) { |
| 27 |
add_action( 'web_stories_print_analytics', array( $this, 'render_amp_analytics_tracker' ) ); |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Loads additional JavaScript for Google's Web Stories WordPress plugin. |
| 33 |
* This relies on the `amp-analytics` element. |
| 34 |
* |
| 35 |
* See more at: https://www.parse.ly/help/integration/google-amp. |
| 36 |
* |
| 37 |
* @since 3.2.0 |
| 38 |
*/ |
| 39 |
public function render_amp_analytics_tracker(): void { |
| 40 |
$json = Amp::construct_amp_json(); |
| 41 |
if ( strlen( $json ) > 0 ) { |
| 42 |
?> |
| 43 |
<amp-analytics type="parsely"> |
| 44 |
<script type="application/json"> |
| 45 |
<?php |
| 46 |
// Output contains the API key, and it's already escaped in the construct_amp_json function. |
| 47 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 48 |
echo $json; |
| 49 |
?> |
| 50 |
</script> |
| 51 |
</amp-analytics> |
| 52 |
<?php |
| 53 |
} |
| 54 |
} |
| 55 |
} |
| 56 |
|