8889841cWeb_Tag.php000064400000006037150516016350006575 0ustar00get_method_proxy_once( 'render_no_js' ); add_action( 'wp_head', $this->get_method_proxy( 'render' ) ); // For non-AMP (if `wp_body_open` supported). add_action( 'wp_body_open', $render_no_js, -9999 ); // For non-AMP (as fallback). add_action( 'wp_footer', $render_no_js ); add_filter( 'wp_resource_hints', $this->get_dns_prefetch_hints_callback( '//www.googletagmanager.com' ), 10, 2 ); $this->do_init_tag_action(); } /** * Outputs Tag Manager script. * * @since 1.24.0 */ protected function render() { $tag_manager_inline_script = sprintf( " ( function( w, d, s, l, i ) { w[l] = w[l] || []; w[l].push( {'gtm.start': new Date().getTime(), event: 'gtm.js'} ); var f = d.getElementsByTagName( s )[0], j = d.createElement( s ), dl = l != 'dataLayer' ? '&l=' + l : ''; j.async = true; j.src = 'https://www.googletagmanager.com/gtm.js?id=' + i + dl; f.parentNode.insertBefore( j, f ); } )( window, document, 'script', 'dataLayer', '%s' ); ", esc_js( $this->tag_id ) ); $tag_manager_consent_attribute = $this->get_tag_blocked_on_consent_attribute_array(); printf( "\n\n", esc_html__( 'Google Tag Manager snippet added by Site Kit', 'google-site-kit' ) ); BC_Functions::wp_print_inline_script_tag( $tag_manager_inline_script, $tag_manager_consent_attribute ); printf( "\n\n", esc_html__( 'End Google Tag Manager snippet added by Site Kit', 'google-site-kit' ) ); } /** * Outputs Tag Manager iframe for when the browser has JavaScript disabled. * * @since 1.24.0 */ private function render_no_js() { // Consent-based blocking requires JS to be enabled so we need to bail here if present. if ( $this->get_tag_blocked_on_consent_attribute() ) { return; } $iframe_src = 'https://www.googletagmanager.com/ns.html?id=' . rawurlencode( $this->tag_id ); ?> register_legacy_keys_migration( array( 'account_id' => 'accountID', 'accountId' => 'accountID', 'container_id' => 'containerID', 'containerId' => 'containerID', ) ); $this->register_owned_keys(); } /** * Returns keys for owned settings. * * @since 1.16.0 * * @return array An array of keys for owned settings. */ public function get_owned_keys() { return array( 'accountID', 'ampContainerID', 'containerID', 'internalAMPContainerID', 'internalContainerID', ); } /** * Gets the default value. * * @since 1.2.0 * * @return array */ protected function get_default() { return array( 'ownerID' => 0, 'accountID' => '', 'ampContainerID' => '', 'containerID' => '', 'internalContainerID' => '', 'internalAMPContainerID' => '', 'useSnippet' => true, 'gaPropertyID' => '', ); } /** * Gets the callback for sanitizing the setting's value before saving. * * @since 1.6.0 * * @return callable|null */ protected function get_sanitize_callback() { return function( $option ) { if ( is_array( $option ) ) { if ( isset( $option['useSnippet'] ) ) { $option['useSnippet'] = (bool) $option['useSnippet']; } } return $option; }; } } AMP_Tag.php000064400000005004150516016350006466 0ustar00get_method_proxy_once( 'render' ); // Which actions are run depends on the version of the AMP Plugin // (https://amp-wp.org/) available. Version >=1.3 exposes a // new, `amp_print_analytics` action. // For all AMP modes, AMP plugin version >=1.3. add_action( 'amp_print_analytics', $render ); // For AMP Standard and Transitional, AMP plugin version <1.3. add_action( 'wp_footer', $render, 20 ); // For AMP Reader, AMP plugin version <1.3. add_action( 'amp_post_template_footer', $render, 20 ); // For Web Stories plugin. add_action( 'web_stories_print_analytics', $render ); // Load amp-analytics component for AMP Reader. $this->enqueue_amp_reader_component_script( 'amp-analytics', 'https://cdn.ampproject.org/v0/amp-analytics-0.1.js' ); $this->do_init_tag_action(); } /** * Outputs Tag Manager tag. * * @since 1.24.0 */ protected function render() { // Add the optoutElementId for compatibility with our Analytics opt-out mechanism. // This configuration object will be merged with the configuration object returned // by the `config` attribute URL. $gtm_amp_opt = array( 'optoutElementId' => '__gaOptOutExtension', ); printf( "\n\n", esc_html__( 'Google Tag Manager AMP snippet added by Site Kit', 'google-site-kit' ) ); printf( '', esc_url( 'https://www.googletagmanager.com/amp.json?id=' . rawurlencode( $this->tag_id ) ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped $this->get_tag_blocked_on_consent_attribute(), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped wp_json_encode( $gtm_amp_opt ) ); printf( "\n\n", esc_html__( 'End Google Tag Manager AMP snippet added by Site Kit', 'google-site-kit' ) ); } } Tag_Guard.php000064400000002560150516016350007117 0ustar00is_amp = $is_amp; } /** * Determines whether the guarded tag can be activated or not. * * @since 1.24.0 * * @return bool|WP_Error TRUE if guarded tag can be activated, otherwise FALSE or an error. */ public function can_activate() { $settings = $this->settings->get(); $container_id = $this->is_amp ? $settings['ampContainerID'] : $settings['containerID']; return ! empty( $settings['useSnippet'] ) && ! empty( $container_id ); } }