Skip to content

Commit dcc2319

Browse files
Add more params to file_download event
1 parent 35dfdeb commit dcc2319

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

pmg/utils.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ def track_file_download():
7272
client_id = request.cookies.get("_ga")
7373

7474
path = request.path
75-
file_name, file_extension = os.path.splitext(path)
75+
last_slash_index = path.rfind("/")
76+
file_dir = path[:last_slash_index]
77+
page_location = f"{request.url_root}{file_dir[1:]}"
7678

7779
url = f"{ga_url}?measurement_id={ga_id}&api_secret={api_secret}"
7880
payload = {
@@ -82,9 +84,11 @@ def track_file_download():
8284
{
8385
"name": "file_download",
8486
"params": {
85-
"file_extension": file_extension.replace(".", ""),
86-
"file_name": file_name,
87+
"file_extension": path.split(".")[-1],
88+
"file_name": path,
8789
"link_url": request.url,
90+
"page_location": page_location,
91+
"page_referrer": request.referrer,
8892
},
8993
}
9094
],

0 commit comments

Comments
 (0)