Merge pull request #11594 from frappe/google_analytics_anonymize_ip

feat: option to anonymize ip for google analytics
This commit is contained in:
mergify[bot] 2020-10-19 14:28:08 +00:00 committed by GitHub
commit 38b2c072ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 27 additions and 5 deletions

View file

@ -22,6 +22,9 @@
"use_ssl": 0,
"auto_email_id": "hello@example.com",
"google_analytics_id": "google_analytics_id",
"google_analytics_anonymize_ip": 1,
"google_login": {
"client_id": "google_client_id",
"client_secret": "google_client_secret"

View file

@ -6,6 +6,9 @@
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '{{ google_analytics_id }}', 'auto');
{% if google_analytics_anonymize_ip %}
ga('set', 'anonymizeIp', true);
{% endif %}
$(document).on("mousedown", function(event) {
if(!frappe && !frappe.get_route) return;

View file

@ -52,6 +52,7 @@
"indexing_authorization_code",
"column_break_17",
"google_analytics_id",
"google_analytics_anonymize_ip",
"misc_section",
"subdomain",
"disable_signup",
@ -206,7 +207,6 @@
"label": "Integrations"
},
{
"description": "Add Google Analytics ID: eg. UA-89XXX57-1. Please search help on Google Analytics for more information.",
"fieldname": "google_analytics_id",
"fieldtype": "Data",
"label": "Google Analytics ID"
@ -401,6 +401,12 @@
"fieldname": "edit_footer_template_values",
"fieldtype": "Button",
"label": "Edit Values"
},
{
"default": "1",
"fieldname": "google_analytics_anonymize_ip",
"fieldtype": "Check",
"label": "Google Analytics Anonymize IP"
}
],
"icon": "fa fa-cog",
@ -409,7 +415,7 @@
"issingle": 1,
"links": [],
"max_attachments": 10,
"modified": "2020-08-21 14:02:55.168829",
"modified": "2020-09-28 18:47:18.506700",
"modified_by": "Administrator",
"module": "Website",
"name": "Website Settings",
@ -433,4 +439,4 @@
"sort_field": "modified",
"sort_order": "ASC",
"track_changes": 1
}
}

View file

@ -43,6 +43,7 @@ def get_context(context):
"boot": boot if context.get("for_mobile") else boot_json,
"csrf_token": csrf_token,
"google_analytics_id": frappe.conf.get("google_analytics_id"),
"google_analytics_anonymize_ip": frappe.conf.get("google_analytics_anonymize_ip"),
"mixpanel_id": frappe.conf.get("mixpanel_id")
})

View file

@ -9,6 +9,9 @@ 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', '{{ google_analytics_id }}', 'auto');
{% if google_analytics_anonymize_ip %}
ga('set', 'anonymizeIp', true);
{% endif %}
ga('send', 'pageview');
// End Google Analytics
{%- endif %}

View file

@ -18,5 +18,11 @@ def get_context(context):
context.javascript += "\n" + js
if not frappe.conf.developer_mode:
context["google_analytics_id"] = (frappe.db.get_single_value("Website Settings", "google_analytics_id")
or frappe.conf.get("google_analytics_id"))
context['google_analytics_id'] = get_setting('google_analytics_id')
context['google_analytics_anonymize_ip'] = get_setting('google_analytics_anonymize_ip')
def get_setting(field_name):
"""Return value of field_name frok Website Settings or Site Config."""
website_settings = frappe.db.get_single_value('Website Settings', field_name)
conf = frappe.conf.get(field_name)
return website_settings or conf