Version Description
Download this release
Release Info
| Developer | georgestephanis |
| Plugin | |
| Version | 1.0.2-beta1 |
| Comparing to | |
| See all releases | |
Code changes from version 1.0.1 to 1.0.2-beta1
- google-tag-manager.php +31 -11
- readme.txt +5 -1
google-tag-manager.php
CHANGED
|
@@ -3,17 +3,23 @@
|
|
| 3 |
Plugin Name: Google Tag Manager
|
| 4 |
Plugin URI: http://wordpress.org/extend/plugins/google-tag-manager/
|
| 5 |
Description: This is an implementation of the new Tag Management system from Google. It adds a field to the existing General Settings page for the ID, and if specified, outputs the tag management javascript in the page footer.
|
| 6 |
-
Version: 1.0.
|
| 7 |
Author: George Stephanis
|
| 8 |
-
Author URI: http://
|
| 9 |
License: GPLv2 or later
|
| 10 |
*/
|
| 11 |
|
| 12 |
class google_tag_manager {
|
| 13 |
|
|
|
|
|
|
|
| 14 |
public static function go() {
|
| 15 |
-
add_filter( 'admin_init',
|
| 16 |
-
add_action( '
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
}
|
| 18 |
public static function register_fields() {
|
| 19 |
register_setting( 'general', 'google_tag_manager_id', 'esc_attr' );
|
|
@@ -28,19 +34,33 @@ class google_tag_manager {
|
|
| 28 |
<?php
|
| 29 |
}
|
| 30 |
public static function print_tag() {
|
| 31 |
-
|
| 32 |
-
|
| 33 |
<!-- Google Tag Manager -->
|
| 34 |
-
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=<?php echo $id; ?>"
|
| 35 |
-
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
|
| 36 |
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
|
| 37 |
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
|
| 38 |
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
|
| 39 |
-
'
|
| 40 |
-
})(window,document,'script','dataLayer','<?php echo $id; ?>');</script>
|
| 41 |
<!-- End Google Tag Manager -->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
<?php
|
| 43 |
}
|
| 44 |
}
|
| 45 |
|
| 46 |
-
google_tag_manager::go();
|
| 3 |
Plugin Name: Google Tag Manager
|
| 4 |
Plugin URI: http://wordpress.org/extend/plugins/google-tag-manager/
|
| 5 |
Description: This is an implementation of the new Tag Management system from Google. It adds a field to the existing General Settings page for the ID, and if specified, outputs the tag management javascript in the page footer.
|
| 6 |
+
Version: 1.0.2-beta1
|
| 7 |
Author: George Stephanis
|
| 8 |
+
Author URI: http://stephanis.info
|
| 9 |
License: GPLv2 or later
|
| 10 |
*/
|
| 11 |
|
| 12 |
class google_tag_manager {
|
| 13 |
|
| 14 |
+
public static $printed_noscript_tag = false;
|
| 15 |
+
|
| 16 |
public static function go() {
|
| 17 |
+
add_filter( 'admin_init', array( __CLASS__, 'register_fields' ) );
|
| 18 |
+
add_action( 'wp_head', array( __CLASS__, 'print_tag' ) );
|
| 19 |
+
add_action( 'genesis_before', array( __CLASS__, 'print_noscript_tag' ) ); // Genesis
|
| 20 |
+
add_action( 'tha_body_top', array( __CLASS__, 'print_noscript_tag' ) ); // Theme Hook Alliance
|
| 21 |
+
add_action( 'body_top', array( __CLASS__, 'print_noscript_tag' ) ); // THA Unprefixed
|
| 22 |
+
add_action( 'wp_footer', array( __CLASS__, 'print_noscript_tag' ) ); // Fallback!
|
| 23 |
}
|
| 24 |
public static function register_fields() {
|
| 25 |
register_setting( 'general', 'google_tag_manager_id', 'esc_attr' );
|
| 34 |
<?php
|
| 35 |
}
|
| 36 |
public static function print_tag() {
|
| 37 |
+
if ( ! $id = get_option( 'google_tag_manager_id', '' ) ) return;
|
| 38 |
+
?>
|
| 39 |
<!-- Google Tag Manager -->
|
|
|
|
|
|
|
| 40 |
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
|
| 41 |
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
|
| 42 |
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
|
| 43 |
+
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
|
| 44 |
+
})(window,document,'script','dataLayer','<?php echo esc_js( $id ); ?>');</script>
|
| 45 |
<!-- End Google Tag Manager -->
|
| 46 |
+
<?php
|
| 47 |
+
}
|
| 48 |
+
public static function print_noscript_tag() {
|
| 49 |
+
// Make sure we only print the noscript tag once.
|
| 50 |
+
// This is because we're trying for multiple hooks.
|
| 51 |
+
if ( self::$printed_noscript_tag ) {
|
| 52 |
+
return;
|
| 53 |
+
}
|
| 54 |
+
self::$printed_noscript_tag = true;
|
| 55 |
+
|
| 56 |
+
if ( ! $id = get_option( 'google_tag_manager_id', '' ) ) return;
|
| 57 |
+
?>
|
| 58 |
+
<!-- Google Tag Manager (noscript) -->
|
| 59 |
+
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=<?php echo esc_attr( $id ); ?>"
|
| 60 |
+
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
|
| 61 |
+
<!-- End Google Tag Manager (noscript) -->
|
| 62 |
<?php
|
| 63 |
}
|
| 64 |
}
|
| 65 |
|
| 66 |
+
google_tag_manager::go();
|
readme.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
===
|
| 2 |
Contributors: georgestephanis
|
| 3 |
Donate link: http://www.charitywater.org/donate/
|
| 4 |
Tags: google, tag manager, tag management, analytics
|
|
@@ -32,6 +32,10 @@ Two possibilities: First, you haven't yet specified the ID in the admin panel, o
|
|
| 32 |
|
| 33 |
== Changelog ==
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
= 1.0.1 =
|
| 36 |
* Change to static methods to avoid errors in some versions of php
|
| 37 |
|
| 1 |
+
=== Google Tag Manager ===
|
| 2 |
Contributors: georgestephanis
|
| 3 |
Donate link: http://www.charitywater.org/donate/
|
| 4 |
Tags: google, tag manager, tag management, analytics
|
| 32 |
|
| 33 |
== Changelog ==
|
| 34 |
|
| 35 |
+
= 1.0.2 =
|
| 36 |
+
* Switch to the new split-format for Google Tag Manager javascript and iframe format.
|
| 37 |
+
* Add support for Genesis and Theme Hook Alliance themes to echo the iframe sooner in the dom.
|
| 38 |
+
|
| 39 |
= 1.0.1 =
|
| 40 |
* Change to static methods to avoid errors in some versions of php
|
| 41 |
|
