PluginProbe
Parse.ly / 3.2.0
Parse.ly v3.2.0
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.2.0, at src/Integrations/class-google-web-stories.php

57 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 * Google Web Stories integration class
4 *
5 * @package Parsely\Integrations
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 * Apply the hooks that integrate the plugin or theme with the Parse.ly plugin.
21 *
22 * @since 3.2.0
23 *
24 * @return void
25 */
26 public function integrate(): void {
27 if ( defined( 'WEBSTORIES_PLUGIN_FILE' ) ) {
28 add_action( 'web_stories_print_analytics', array( $this, 'render_amp_analytics_tracker' ) );
29 }
30 }
31
32 /**
33 * Load additional JavaScript for Google's Web Stories WordPress plugin. This relies on the `amp-analytics` element.
34 * See more at: https://www.parse.ly/help/integration/google-amp.
35 *
36 * @since 3.2.0
37 *
38 * @return void
39 */
40 public function render_amp_analytics_tracker(): void {
41 $json = Amp::construct_amp_json();
42 if ( strlen( $json ) > 0 ) {
43 ?>
44 <amp-analytics type="parsely">
45 <script type="application/json">
46 <?php
47 // Output contains the API key, and it's already escaped in the construct_amp_json function.
48 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
49 echo $json;
50 ?>
51 </script>
52 </amp-analytics>
53 <?php
54 }
55 }
56 }
57