Google Tag Manage and Google Analytics

Hello,

Having trouble with 2 aspects. There is a glitch on your Google Analytics extnesion, and no easy way to install Tag Manager.

Website: daynamics.co.uk

Google Analytics Glitch

I am adding the tracking code that Analytics provides me:

When hitting update to save, the script then appears like so:

The tag is being stripped out by your plugin. How can this be fixed?

Google Tag Manager

How do I install this on X Theme? The examples on other threads are outdated and do not account to the multiple header files you now have.

Enjoying the theme a lot - its great. You just need to make Tag Manager MUCH easier to install.

Many thanks,

Hey there,

I’ve replicated this in my test site and confirm this is a bug. I’ll forward this to our development team.

For now, you’ll need to add your tag manager code via an action hook or a third party plugin that will add your code in the header like the Google Analytics extension.

Thanks.

Hi, @chexd,

Bug confirmed. Google Analytics code has changed and security check against the script tag is avoiding attributes.

To immediately fix this, change the file wp-content/plugins/tco-google-analytics/functions/options.php at line 30 from:

$tco_google_analytics_options['tco_google_analytics_code']     = stripslashes( wp_kses( $_POST['tco_google_analytics_code'], array( 'script' => array() ) ) );

to:

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

This fix will be on next release.

Thanks!

2 Likes

Thank you! I can confirm the fix works! :slight_smile:

Is there a future plan to make Google Tag Manager easier?

Even with this fix, Tag Manager implementation is not clearly documented for this Theme. Other forum posts are outdated as the file structure has changed.

Many thanks,

1 Like

Hi, @chexd,

Glad to hear that our fix worked for you.

We don’t have a specific support for Google Tag Manager, but we will consider for future development. It’s not planned yet, but we’re adding to our wishlist.

Thanks!

1 Like

I have tried your fix and I still am not getting any traffic reported to Google Analytics. I edited line 30 of tco-google-analytics/functions/options.php to now read:

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

This is the code I pasted into the X Theme Google Analytics Code window:

<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-107097482-1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments)};
  gtag('js', new Date());

  gtag('config', 'UA-107097482-1');
</script>

I have logged out of wordpress to check google analytics and see absolutely no traffic.
Please help, this is not acceptable to my client.

I don’t know why the X Theme Google Analytics Code didn’t show up in my previous question, here it is again:

<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-107097482-1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments)};
  gtag('js', new Date());

  gtag('config', 'UA-107097482-1');
</script>

ok, I’m clearly missing something, the code won’t show up, so I’m trying adding " at the beginning and ending…

<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-107097482-1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments)};
  gtag('js', new Date());

  gtag('config', 'UA-107097482-1');
</script>

Hi, there,

I edit your posts to add 3 back quotes before and after the codes to display them. For security reasons, any HTML tags will be ignored here.

 use ```html to start a highlighted HTML code area, ```php to start a highlighted PHP code area, and ``` to finish

Now about your question. Check the source code of your page to confirm that your Google Analytics code is correct. Send us your url so we can take a look.

Thanks!

Hello,

I tried the fix posted above and I don’t think it’s working. (I opened an incognito window and went to my site, then checked the real-time traffic on Google Analytics—it showed 0 visitors.)

Can you please look?
Thank you,
Shannon

Hi, there,

Please take a look at the solution on the answer https://theme.co/apex/forum/t/google-tag-manage-and-google-analytics/8966/3?u=rafaelgou above.

Your Google Analytics script tag is missing attributes and a temporary solution is provided until next extension update.

Thanks!

Hi!

I did what you suggested. I still can’t get it to work. I’ve spent hours trying to figure it out. This is not the first site that I connect to my Google Analytics account, but I do have issues with Pro doing it. Could you login to my site and see what’s up?

Hi, there,

It seems there was some caching issue avoiding the code to work. At first, I was unable to save Google Analytics snippet (always cleaning the <script> tag attributes).

So I edit the plugin, confirm that you did the fix correctly; I saved again, then (just that) and then I was able to save the snippet on plugin’s screen, and now it works.

Please confirm if everything is ok on your end.

Thanks!

I already did this, but it doesn’t work. Can you help?

Hi, there,

Could share your site credentials on a Secure Note so we can take a look?

Thanks!

Hi!

I can’t see that it works unfortunately. I’m trying to connect Google Analytics Dashboard and that gives me an 401 error message. What am I doing wrong?

Hi! I FINALLY got it to work. I still don’t quite get it but it works now at least. Google’s own info on this is surprisingly bad, I believe. Maybe someone should make an idiot proof set up guide in the Themeco Forum? That would be so awesome. Too bad I’m not good enough to help.

Thank you!

<3
A

Glad to hear it works!

1 Like

Hello rafaelgo,

I’ve replaced the line 30 but that did not help. What can I do?

I also have a topic open regarding this.