[Resolved] SEO Tracking code stripped out

Permalink
Hello,

I'm an experienced web developer, but not so much with Concrete5,
and there is _something_ which strip the Google Analytics script out of my pages and I can't figure how.

Let me explain:

- `seo.tracking.code.footer` is correctly set and visible in admin
- All templates include `footer_bottom.php`
- `footer_bottom.php` correctly include `footer_required`
- `footer_required` is Concrete5's default one (`concrete/elements/footer_required.php`)
- I clear the cache everytime
- I look at the response using Postman, so it isn't JS related.

Originally, `footer_required.php` contains the lines:

if (empty($disableTrackingCode)) {
    echo $config->get('seo.tracking.code.footer');
}


> (yes, the condition pass)

Now if I change the code as:

if (empty($disableTrackingCode)) {
    var_dump($config->get('seo.tracking.code.footer'));
}


then clear the cache and refresh, it prints:

string(443) ""


> WTF!

If I add slashes:

if (empty($disableTrackingCode)) {
    var_dump(addslashes($config->get('seo.tracking.code.footer')));
}


It prints:

string(461) "<script>
  (function(i,s,o,g,r,a,m){i[\'GoogleAnalyticsObject\']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,\'script\',\'https://www.google-analytics.com/analytics.js\',\'ga\');
  ga(\'create\', \'XX-XXXXXXXX-X\', \'auto\');
  ga(\'send\', \'pageview\');
</script>"


> OK, so `$config->get()` returns the correct value, but something clean the output of the view.

If I directly put the code:

// if (empty($disableTrackingCode)) {
//     echo $config->get('seo.tracking.code.footer');
// }
?>
<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  ga('create', 'XX-XXXXXXXX-X', 'auto');
  ga('send', 'pageview');
</script>
<?php


> It works ?!

Does anyone understand what's going on ?

 
JohntheFish replied on at Permalink Reply
JohntheFish
Perhaps a privacy plugin on your browser is cleaning out the tracking code.
Check the 'view source ' for the raw source of the page, rather than the dev console's current source.
Ascarius replied on at Permalink Reply
Hello,

Thank you for your answer.

I check with Postman, so it's not JS related.

Also, there are 2 plugins installed:
- ExchangeCore reCAPTCHA (1.1.1)
- GDPR (1.7.0)

GDPR has a setting to disable tracking codes, but after inspection, it appears to only toggle $disableTrackingCode variable which is not the case.

What bother me it's I don't understand how it can even happen.

If I print the code directly, it's not stripped out.
Maybe what I get from $config is not what it seems ?
Lapalica replied on at Permalink Reply
but is it possible to use already made website analytics soft?
YodaNoFear replied on at Permalink Reply
Dude, I'm not even surprised, because 80 percent of Google analytics users face various problems. I also used the services of Google analytics, but in the end I was tired of the fact that the service provides inaccurate data and I decided to find another service. I turned to my friends who work in the field of CEO and marketing and they told me about the
[url="https://www.finteza.com/en/website-analytics"]Finteza web analytics tool[/url]
. The advantage of this service is that it is inexpensive and provides very accurate data. I paid 25 bucks and started using this service and it is really very cool. It has a very user-friendly interface, accurate data on site visits, and there is even the possibility of Identify 12 types of bad traffic. I am very glad that I learned about this service!
Ascarius replied on at Permalink Best Answer Reply
Finally it was the GDPR plugin.
Not sure how, but it started to work after I uninstalled that plugin.

Since I have to keep the GDPR plugin, I finally removed the tracking code from the config and pasted it in my `footer_bottom.php`...
JohntheFish replied on at Permalink Reply
JohntheFish
The GDPR plugin enables or disables the tracking code depending on consent.