Google Tag Manager - Version 1.0.1

Version Description

  • Change to static methods to avoid errors in some versions of php
Download this release

Release Info

Developer georgestephanis
Plugin Icon wp plugin Google Tag Manager
Version 1.0.1
Comparing to
See all releases

Version 1.0.1

Files changed (2) hide show
  1. google-tag-manager.php +46 -0
  2. readme.txt +44 -0
google-tag-manager.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
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.1
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 function go() {
15
+ add_filter( 'admin_init', array( __CLASS__, 'register_fields' ) );
16
+ add_action( 'wp_footer', array( __CLASS__, 'print_tag' ) );
17
+ }
18
+ public static function register_fields() {
19
+ register_setting( 'general', 'google_tag_manager_id', 'esc_attr' );
20
+ add_settings_field( 'google_tag_manager_id', '<label for="google_tag_manager_id">' . __( 'Google Tag Manager ID' , 'google_tag_manager' ) . '</label>' , array( __CLASS__, 'fields_html') , 'general' );
21
+ }
22
+ public static function fields_html() {
23
+ ?>
24
+ <input type="text" id="google_tag_manager_id" name="google_tag_manager_id" placeholder="ABC-DEFG" class="regular-text code" value="<?php echo get_option( 'google_tag_manager_id', '' ); ?>" />
25
+ <p class="description"><?php _e( 'The ID from Google&rsquo;s provided code (as emphasized):', 'google_tag_manager' ); ?><br />
26
+ <code>&lt;noscript&gt;&lt;iframe src="//www.googletagmanager.com/ns.html?id=<strong style="color:#c00;">ABC-DEFG</strong>"</code></p>
27
+ <p class="description"><?php _e( 'You can get yours <a href="https://www.google.com/tagmanager/">here</a>!', 'google_tag_manager' ); ?></p>
28
+ <?php
29
+ }
30
+ public static function print_tag() {
31
+ if( ! $id = get_option( 'google_tag_manager_id', '' ) ) return;
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
+ '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
40
+ })(window,document,'script','dataLayer','<?php echo $id; ?>');</script>
41
+ <!-- End Google Tag Manager -->
42
+ <?php
43
+ }
44
+ }
45
+
46
+ google_tag_manager::go();
readme.txt ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Plugin Name ===
2
+ Contributors: georgestephanis
3
+ Donate link: http://www.charitywater.org/donate/
4
+ Tags: google, tag manager, tag management, analytics
5
+ Requires at least: 2.7
6
+ Tested up to: 4.7
7
+ Stable tag: 1.0.1
8
+ License: GPLv2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
+
11
+ The Google Tag Manager plugin adds a field to the existing General Settings page for the ID and outputs the javascript in the front-end footer.
12
+
13
+ == Description ==
14
+
15
+ [You can sign up for a Google Tag Manager account here.](https://www.google.com/tagmanager/ "Google Tag Manager")
16
+
17
+ This plugin makes it even easier to use Google Tag Manager, adding all the code itself -- all you need to do is provide the Account ID!
18
+
19
+ [youtube http://www.youtube.com/watch?v=KRvbFpeZ11Y]
20
+
21
+ == Installation ==
22
+
23
+ 1. Upload `google-tag-manager.php` to the `/wp-content/plugins/` directory
24
+ 1. Activate the plugin through the 'Plugins' menu in WordPress
25
+ 1. Go to `Settings` > `General` and set the ID from your Google Tag Manager account.
26
+
27
+ == Frequently Asked Questions ==
28
+
29
+ = Why isn't the output displaying? =
30
+
31
+ Two possibilities: First, you haven't yet specified the ID in the admin panel, or second, your theme is missing a `<?php wp_footer(); ?>` call.
32
+
33
+ == Changelog ==
34
+
35
+ = 1.0.1 =
36
+ * Change to static methods to avoid errors in some versions of php
37
+
38
+ = 1.0 =
39
+ * Initial Public Release
40
+
41
+ == Upgrade Notice ==
42
+
43
+ = 1.0 =
44
+ Initial Public Release