PluginProbe
Parse.ly / 3.14.3
Parse.ly v3.14.3
3.24.1 3.24.0 3.23.7 3.23.6 3.23.5 3.23.4 3.23.3 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.17.0 3.18.0 3.18.1 3.19.0 3.19.1 3.19.2 3.19.3 3.2.0 3.2.1 3.20.0 3.20.1 3.20.2 3.20.3 All 105 releases
wp-parsely / src / Integrations / class-google-web-stories.php

class-google-web-stories.php in Parse.ly 3.14.3, at src/Integrations/class-google-web-stories.php

56 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 extends 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 * @since 3.2.0
36 *
37 * @see https://docs.parse.ly/google-amp/
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 Site ID, 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