Google Tag Manager Definitive Set Up for X

Hi Chaps!

I’ve been reading through various threads about the issues when setting up tag manager and have tried a couple of them! More than once…

My client is getting a tad frustrated but I’m running out of ideas as to why this issn’t working?

Is there any chance someone could have a look at tenav.co.uk for me, happy to provide credentials if required.

Google Tag manager installed.

I have this in my child theme in a new _header.php file
/wp-content/themes/x-child/framework/legacy/cranium/headers/views/global/_header.php

<!DOCTYPE html>

<html class="no-js" <?php language_attributes(); ?>>

<head>
<?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>

<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-        XXXXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->

<div id="x-root" class="x-root">

<?php do_action( 'x_before_site_begin' ); ?>

<div id="top" class="site">

<?php do_action( 'x_after_site_begin' ); ?>

And this under functions.php
wp-content/themes/x-child/functions.php

// Additional Functions
//=============================================================================

add_action( 'wp_head', 'add_head_script', 999 );
function add_head_script(){
?>
<!-- Google Tag Manager -->
<script>(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','GTM-XXXXXXX');</script>
<!-- End Google Tag Manager -->
	<?php
}

Hey there,

I see the code blocks are successfully added. I see you’ve added two slightly different variations of your Google Tag Manager <head> code though. Is that the normal setup? If not, please remove the other one. If you’re using the Google Analytics extension to add the code, you can remove the code in functions.php

Thanks.

Hey Christian,

I figured we should start at the beginning.

Google analytics wasn’t working it seems in the first instance. I found this link about the bug and changed the code in “wp-content/plugins/tco-google-analytics/functions/options.php” at line 30 as suggested.

My plug-in was “x-google-analytics” rather than “tco” and the line of code though used an “x” as well, rather than “tco”?

$x_google_analytics_options['x_google_analytics_code']     = stripslashes( wp_kses( $_POST['x_google_analytics_code'], array( 'script' => array( 'async' => array(), 'src' => array() ) ) ) );

I presume this is all correct?

However, I am not showing any active users, is the Google Analytics plug-in not working?

Many thanks,

Steve

Hi Steve,

This means that you have the version 1.x of the google-analytics extension. Lets update that first.

To update this extension to version 2.x, follow these steps:

-Ensure your theme is validated so Extensions can be installed automaticaly
-Deactivate and delete the plugin._
-On the theme overview page, locate and install the plugin from "Extensions".
-Visit "Plugins" in your Dashbaord to activate the newly installed version.

Because all of the plugin settings are stored in the database, and because version 2.x will migrate settings from older versions, it's safe to use this method of deleting the previous version.

Refer here for the latest supported versions.

Clear your caching after updating.

Thanks,

Hi Friech,

Apologies for the delay in replying, adding SSL to 200 or so websites for Chrome…!!! Nightmare!

OK - We now have the relevant version of X and Google analytics. I have added the tracking code to Google Analytics but we’re not seeing any active users?

Many thanks,

Steve

Hi, there,

So far you still have to apply the patch you mentioned (https://theme.co/apex/forum/t/google-tag-manage-and-google-analytics/8966); this fix will be released soon but it’s not yet on latest Google Analytics version.

Thanks!