refactor: Remove UTM references just set source in web page view to simplify things
This commit is contained in:
parent
3eff93ea6e
commit
6c8f88b8cd
5 changed files with 21 additions and 75 deletions
|
|
@ -202,10 +202,10 @@ class Newsletter(WebsiteGenerator):
|
|||
|
||||
html = frappe.render_template(message, {"doc": self.as_dict()})
|
||||
|
||||
return self.add_utm(html)
|
||||
return self.add_source(html)
|
||||
|
||||
def add_utm(self, html: str) -> str:
|
||||
"""Add UTM parameters to internal links in the newsletter."""
|
||||
def add_source(self, html: str) -> str:
|
||||
"""Add source to the site links in the newsletter content."""
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
soup = BeautifulSoup(html, "html.parser")
|
||||
|
|
@ -216,8 +216,8 @@ class Newsletter(WebsiteGenerator):
|
|||
if href and not href.startswith("#"):
|
||||
if not frappe.utils.is_site_link(href):
|
||||
continue
|
||||
new_href = frappe.utils.add_utm_to_url(
|
||||
href, source="Newsletter", medium="Email", campaign=self.name
|
||||
new_href = frappe.utils.add_source_to_url(
|
||||
href, reference_doctype=self.doctype, reference_docname=self.name
|
||||
)
|
||||
link["href"] = new_href
|
||||
|
||||
|
|
|
|||
|
|
@ -2187,21 +2187,10 @@ def is_site_link(link: str) -> bool:
|
|||
return urlparse(link).netloc == urlparse(frappe.utils.get_url()).netloc
|
||||
|
||||
|
||||
def add_utm_to_url(url: str, source: str, medium: str, campaign: str) -> str:
|
||||
"""Add utm parameters to url.
|
||||
|
||||
Args:
|
||||
url (str): URL to add utm parameters to.
|
||||
utm (dict[str, str]): Dictionary of utm parameters.
|
||||
|
||||
Returns:
|
||||
str: URL with utm parameters added.
|
||||
"""
|
||||
def add_source_to_url(url: str, reference_doctype: str, reference_docname: str) -> str:
|
||||
url_parts = list(urlparse(url))
|
||||
query = dict(parse_qsl(url_parts[4])) | {
|
||||
"utm_source": source,
|
||||
"utm_medium": medium,
|
||||
"utm_campaign": campaign,
|
||||
"source": f"{reference_doctype} > {reference_docname}",
|
||||
}
|
||||
|
||||
url_parts[4] = urlencode(query)
|
||||
|
|
|
|||
|
|
@ -14,12 +14,7 @@
|
|||
"time_zone",
|
||||
"user_agent",
|
||||
"visitor_id",
|
||||
"utm_trackers_section",
|
||||
"utm_source",
|
||||
"utm_medium",
|
||||
"utm_campaign",
|
||||
"utm_content",
|
||||
"utm_term"
|
||||
"source"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
|
|
@ -61,52 +56,23 @@
|
|||
"fieldtype": "Data",
|
||||
"label": "User Agent"
|
||||
},
|
||||
{
|
||||
"fieldname": "utm_trackers_section",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "UTM Trackers"
|
||||
},
|
||||
{
|
||||
"fieldname": "utm_source",
|
||||
"fieldtype": "Data",
|
||||
"label": "Source",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "utm_medium",
|
||||
"fieldtype": "Data",
|
||||
"label": "Medium",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "utm_campaign",
|
||||
"fieldtype": "Data",
|
||||
"label": "Campaign",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "utm_content",
|
||||
"fieldtype": "Data",
|
||||
"label": "Content",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "utm_term",
|
||||
"fieldtype": "Data",
|
||||
"label": "Term",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "visitor_id",
|
||||
"fieldtype": "Data",
|
||||
"label": "Visitor ID",
|
||||
"read_only": 1,
|
||||
"search_index": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "source",
|
||||
"fieldtype": "Data",
|
||||
"label": "Source",
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"in_create": 1,
|
||||
"links": [],
|
||||
"modified": "2023-02-28 10:12:28.960509",
|
||||
"modified": "2023-02-28 11:55:04.533663",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Website",
|
||||
"name": "Web Page View",
|
||||
|
|
|
|||
|
|
@ -18,11 +18,7 @@ def make_view_log(
|
|||
browser=None,
|
||||
version=None,
|
||||
user_tz=None,
|
||||
utm_source=None,
|
||||
utm_medium=None,
|
||||
utm_campaign=None,
|
||||
utm_term=None,
|
||||
utm_content=None,
|
||||
source=None,
|
||||
visitor_id=None,
|
||||
):
|
||||
if not is_tracking_enabled():
|
||||
|
|
@ -45,6 +41,9 @@ def make_view_log(
|
|||
if path != "/" and path.startswith("/"):
|
||||
path = path[1:]
|
||||
|
||||
if path.startswith(("api/", "app/", "assets/", "private/files/")):
|
||||
return
|
||||
|
||||
is_unique = visitor_id and not bool(frappe.db.exists("Web Page View", {"visitor_id": visitor_id}))
|
||||
|
||||
view = frappe.new_doc("Web Page View")
|
||||
|
|
@ -55,11 +54,7 @@ def make_view_log(
|
|||
view.time_zone = user_tz
|
||||
view.user_agent = user_agent
|
||||
view.is_unique = is_unique
|
||||
view.utm_source = utm_source
|
||||
view.utm_medium = utm_medium
|
||||
view.utm_campaign = utm_campaign
|
||||
view.utm_term = utm_term
|
||||
view.utm_content = utm_content
|
||||
view.source = source
|
||||
view.visitor_id = visitor_id
|
||||
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -32,11 +32,7 @@ ga('send', 'pageview');
|
|||
browser: browser.name,
|
||||
version: browser.version,
|
||||
user_tz: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
||||
utm_source: query_params.utm_source,
|
||||
utm_medium: query_params.utm_medium,
|
||||
utm_campaign: query_params.utm_campaign,
|
||||
utm_term: query_params.utm_term,
|
||||
utm_content: query_params.utm_content,
|
||||
source: query_params.source,
|
||||
visitor_id: result.visitorId
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue