Community @ The Turning Gate

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.

  • New user registrations are disabled.
  • Users cannot create new topics.
  • Users cannot reply to existing topics.

You are not logged in.

#1 2017-11-17 10:09:49

No_name
Member
From: Germany
Registered: 2016-07-14
Posts: 30
Website

Googel Analytics set anonymizeIp

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

#2 2017-11-17 10:10:54

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Googel Analytics set anonymizeIp

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

#3 2017-11-17 10:21:19

No_name
Member
From: Germany
Registered: 2016-07-14
Posts: 30
Website

Re: Googel Analytics set anonymizeIp

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

#4 2017-11-17 10:23:51

JimR
Member
Registered: 2012-11-30
Posts: 348
Website

Re: Googel Analytics set anonymizeIp

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)


https://support.google.com/analytics/an … 3052?hl=en

https://developers.google.com/analytics … nymization


--Jim

Offline

#5 2017-11-17 10:25:53

No_name
Member
From: Germany
Registered: 2016-07-14
Posts: 30
Website

Re: Googel Analytics set anonymizeIp

Thank you Jim

Offline

#6 2017-11-17 12:16:25

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Googel Analytics set anonymizeIp

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

#7 2017-11-17 14:38:56

Matthew
Administrator
From: San Francisco, CA
Registered: 2012-09-24
Posts: 5,795
Website

Re: Googel Analytics set anonymizeIp

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.


Matt

The Turning Gate, http://theturninggate.net

Offline

#8 2017-11-18 00:48:37

JimR
Member
Registered: 2012-11-30
Posts: 348
Website

Re: Googel Analytics set anonymizeIp

Matthew wrote:

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

#9 2017-11-18 00:55:13

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Googel Analytics set anonymizeIp

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

#10 2017-11-18 02:59:55

charlie.choc
Member
From: Marietta, GA
Registered: 2014-01-09
Posts: 359
Website

Re: Googel Analytics set anonymizeIp

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.

Offline

#11 2017-11-18 16:36:59

Matthew
Administrator
From: San Francisco, CA
Registered: 2012-09-24
Posts: 5,795
Website

Re: Googel Analytics set anonymizeIp

charlie.choc wrote:

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.


Matt

The Turning Gate, http://theturninggate.net

Offline

#12 2017-11-18 19:30:12

charlie.choc
Member
From: Marietta, GA
Registered: 2014-01-09
Posts: 359
Website

Re: Googel Analytics set anonymizeIp

No problem, obviously the folks who are legally required take precedence and there is always phplugins for those who want more granularity. Thanks.

Offline

#13 2017-11-19 04:36:47

JimR
Member
Registered: 2012-11-30
Posts: 348
Website

Re: Googel Analytics set anonymizeIp

Matthew wrote:

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

#14 2017-11-19 10:38:20

Matthew
Administrator
From: San Francisco, CA
Registered: 2012-09-24
Posts: 5,795
Website

Re: Googel Analytics set anonymizeIp

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.


Matt

The Turning Gate, http://theturninggate.net

Offline

#15 2017-11-20 07:41:48

No_name
Member
From: Germany
Registered: 2016-07-14
Posts: 30
Website

Re: Googel Analytics set anonymizeIp

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

#16 2017-11-20 07:48:51

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Googel Analytics set anonymizeIp

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

#17 2017-11-20 08:03:20

charlie.choc
Member
From: Marietta, GA
Registered: 2014-01-09
Posts: 359
Website

Re: Googel Analytics set anonymizeIp

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.

Offline

#18 2017-11-20 08:18:14

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Googel Analytics set anonymizeIp

charlie.choc wrote:

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

#19 2017-11-20 09:33:39

Matthew
Administrator
From: San Francisco, CA
Registered: 2012-09-24
Posts: 5,795
Website

Re: Googel Analytics set anonymizeIp

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 /**/

Matt

The Turning Gate, http://theturninggate.net

Offline

#20 2017-11-26 02:54:11

No_name
Member
From: Germany
Registered: 2016-07-14
Posts: 30
Website

Re: Googel Analytics set anonymizeIp

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

#21 2017-11-26 03:06:33

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Googel Analytics set anonymizeIp

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

#22 2017-11-26 03:12:12

charlie.choc
Member
From: Marietta, GA
Registered: 2014-01-09
Posts: 359
Website

Re: Googel Analytics set anonymizeIp

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 /**/

Offline

#23 2017-11-27 21:12:35

No_name
Member
From: Germany
Registered: 2016-07-14
Posts: 30
Website

Re: Googel Analytics set anonymizeIp

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

#24 2017-11-28 03:09:16

peter
Member
Registered: 2012-09-26
Posts: 271

Re: Googel Analytics set anonymizeIp

Haha! Ironic user name for this thread... smile

Offline

Board footer

Powered by FluxBB