Support community for TTG plugins and products.
NOTICE
The Turning Gate's Community has moved to a new home, at https://discourse.theturninggate.net.
This forum is now closed, and exists here as a read-only archive.
You are not logged in.
Pages: 1
Hello Community,
i must anonymize the IP addresses before to send it.
This ist legally required.
i want chang the code.
see the exampel
<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','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXX-X', 'website.de');
ga('set', 'anonymizeIp', true);
ga('send', 'pageview');
</script>
can your help me ?
Offline
can you be more specific as to the help you need?
Rod
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site
Offline
your code supporter not the anonymiz IP
i search a way to insert " ga('set', 'anonymizeIp', true);" on the line.
the write the code on php plug and switch of "Google Analytics Web Property ID" has not work :-(
have you a idea
Offline
Rod, I think he's asking how to add the following line to the Backlight Google analytics tracking code. It's missing in the Backlight code generated for tracking.
ga('set', 'anonymizeIp', true);
This is an option that Google prefers to be used in their tracking code. It's also a legal requirement for some parts of the world (e.g. Europe)
--Jim
Offline
Offline
I don't see any way for the user to change that. But this will give Matt and Ben something to go on.
Rod
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site
Offline
I'll add this to the code snippet in our next updates to Backlight and the Wordpress Add-on, which are the two places the snippet exists. From what I can tell, there's no harm in making this the always-on default, so the change will be transparent to users and appear in all updated templates after clearing the template cache.
If you'd like to do your own code in the meantime, you can disable Google Analytics in Backlight's settings, then use PHPlugins and the ttg_head hook to inject your own personalized snippet.
Offline
disable Google Analytics in Backlight's settings
I had looked for how to do this, but didn't see it. I know how to disable it in the Wordpress theme, but not in Backlight.
Do you simply leave Google Analytics Web Property ID blank?
--Jim
Offline
yep, just empty the Google Analyticse Web Property ID field.
I just tried it. My test site had nothing in that field and the script wasn't showing up in the page source of my test site.
I then added my Google Analytics ID, saved, cleared template and browser cache, and the script appeared.
Rod
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site
Offline
This does slightly decrease the accuracy of geographic reporting in analytics, so if anyone cares about this aspect it would be nice to have a way to turn it on or off rather than having it one way or the other by default. For what it's worth.
Charlie
www.stalkinglight.com
Offline
This does slightly decrease the accuracy of geographic reporting in analytics, so if anyone cares about this aspect it would be nice to have a way to turn it on or off rather than having it one way or the other by default. For what it's worth.
I see.
Not something I want to handle in templates. So it would have to be an option in Settings, which usually requires updating the database, and jumping through other hoops. Not really worth it just for this. The next time Ben is prepping a big update, maybe. I think for now, though, I am going to go ahead with my previous proposal, just making it a part of the basic snippet.
Thanks for the perspective, though.
Offline
No problem, obviously the folks who are legally required take precedence and there is always phplugins for those who want more granularity. Thanks.
Charlie
www.stalkinglight.com
Offline
Not something I want to handle in templates. So it would have to be an option in Settings, which usually requires updating the database, and jumping through other hoops. Not really worth it just for this. The next time Ben is prepping a big update, maybe. I think for now, though, I am going to go ahead with my previous proposal, just making it a part of the basic snippet.
Analytics tracking code can be complex. I track events, such as clicking buttons that download. It's such a custom operation with different needs when you go beyond the very basic (as provided by Backlight).
I'd rather see the PHPlugins sample code updated to include an example of how to add analytics tracking code. That would be enough to quickly get people like me started. I already have PHPlugins running now. Adding my own tracking code is on my do to list. I just didn't realize I could remove the Backlight code by simply removing the tracking ID.
--Jim
Offline
JimR, it's the simplest example:
function ttg_head( $style, $path ) {
echo '<script>
// copy and paste tracking code snippet from Google or whatever
</script>';
return false;
} // END /**/
You don't have to use ttg_head, but that's where I think most of these things want to go, just before the closing of the HEAD element. If your particular tracking code wants to live at the end of the page, then ttg_scripts.
Anyway, there's no special or tricky logic to it. Just drop the tracking snippet into the page. Be mindful of single quotes that might be in your copied snippet, as they will need to be escaped so as not to break the PHP echo statement that wraps the snippet.
Offline
Thank you Matthew,
ich have tested this and that have don't work
This is what the Server say me:
"Something went wrong
Unexpected error: syntax error, unexpected '_setAccount' (T_STRING), expecting ',' or ';' in phplugins-sample.php on line 27
Please report error at http://community.theturninggate.net" :-)
The Code what a have us is that:
function ttg_head( $style, $path ) {
echo '<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','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXX-X', 'website.de');
ga('set', 'anonymizeIp', true);
ga('send', 'pageview');
</script>';
return false;
} // END /**/
The PHP line 27 is
/(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
but i have not good experience whit php i will wait of the next update
Offline
See the last paragraph in Matt’s post above (#14) about escaping single quotes
to escape single quotes, put a backslash in front of each: \'
Rod
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site
Offline
I think you can also use
echo <<<SCRIPT
...
SCRIPT;
in place of
echo '
...
';
That way you don't have to escape single quotes. I'm no expert, though, so I could be mistaken.
Charlie
www.stalkinglight.com
Offline
I think you can also use
echo <<<SCRIPT
...
SCRIPT;
in place of
echo '
...
';
That way you don't have to escape single quotes. I'm no expert, though, so I could be mistaken.
There's an example of using that in the phplugins-pangolin-sample.php file included in the backlight/custom/phplugins/ folder.
Rod
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site
Offline
You're right, Charlie. I always just forget that's a thing.
So, No_Name, try this:
function ttg_head( $style, $path ) {
echo <<<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','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXX-X', 'website.de');
ga('set', 'anonymizeIp', true);
ga('send', 'pageview');
SCRIPT;
return false;
} // END /**/
Offline
Thank you Matthew, but is not work
The script appears about the masthead.
Note:
When I analyze thy sorce code abut Firefox
She say me the header close without to open ?
Offline
Can you post the script you’re using as well as a link to a page that’s having the problem?
Also, if you copied Matt’s script above into a word processor first, you might have picked up some formatting that would break the script, like slanted or curly quote marks rather than straight quote marks
Rod
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site
Offline
try adding <script> and </script> around the function code:
function ttg_head( $style, $path ) {
echo <<<SCRIPT
<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','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXX-X', 'website.de');
ga('set', 'anonymizeIp', true);
ga('send', 'pageview');
</script>
SCRIPT;
return false;
} // END /**/
Charlie
www.stalkinglight.com
Offline
it work
Thank you very much!
This is the code wich a use:
I have use the new google - analytic - code and have integrated the option for give clients can deactivate Google Analytic
/* Google Analytics
========================================================================== */
function ttg_head( $style, $path ) {
echo <<<SCRIPT
<script>
<!-- Opt-Out-Cookie -->
// Set to the same value as the web property used on the site
var gaProperty = 'UA-xxxxxxxx-x';
var disableStr = 'ga-disable-' + gaProperty;
// Disable tracking if the opt-out cookie exists.
if (document.cookie.indexOf(disableStr + '=true') > -1) {
window[disableStr] = true;
}
// Opt-out function
function GAOptOut() {
document.cookie = disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';
window[disableStr] = true;
}
</script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-xxxxxxx-x"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-xxxxxxxx-x', { 'anonymize_ip': true });
</script>
SCRIPT;
return false;
} // END /**/
Offline
Haha! Ironic user name for this thread...
Offline
Pages: 1