Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GA - obfuscate ip and user names #5791

Merged
merged 5 commits into from
Apr 12, 2018
Merged

GA - obfuscate ip and user names #5791

merged 5 commits into from
Apr 12, 2018

Conversation

cristinamanum
Copy link
Contributor

Add support to anonymizeIp and obfuscate user names in GA.

<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', '@propertyId', 'auto');
ga('set', 'anonymizeIp', true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

{
public static string ObfuscateRequestUrl(HttpContextBase httpContext, RouteCollection routes)
{
if (httpContext == null || httpContext.Request == null || httpContext.Request.Url == null || routes == null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplify
if (httpContext?.Request?.Url == null || routes == null)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

{
return string.Empty;
}
return route.ObfuscateUrlPath(httpContext.Request.Url.AbsolutePath.TrimStart('/'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use tertiary operator to reduce code

var route = routes.GetRouteData(httpContext)?.Route as Route;
return route == null ? string.Empty : route.ObfuscateUrlPath(httpContext.Request.Url.AbsolutePath.TrimStart('/'));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

}

[Fact]
public void NullContext()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: usually test cases have names to describe the expected response in addition to the input

e.g.

WithNullContextReturnsEmptyString

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@cristinamanum cristinamanum merged commit e2ddf4f into dev Apr 12, 2018
@cristinamanum cristinamanum deleted the cmanuga branch September 17, 2018 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants