-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: added analytics script to get a simple csv of outlinks (#3202)
- Loading branch information
Showing
1 changed file
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import analytics.charts as ac\n", | ||
"import analytics_anvil as anvil\n", | ||
"\n", | ||
"\n", | ||
"SECRET_NAME = 'GA4_CREDENTIALS'\n", | ||
"GA_PROPERTY_PORTAL = \"368678391\" # AnVIL Portal - GA4\n", | ||
"PRE_AUDIENCE_EXCLUDE_PAGES_FILTER = \"landingPagePlusQueryString!=/guides/content/creating-links\"\n", | ||
"EXCLUDE_PAGES_FILTER = {\"filter\": {\"fieldName\": \"audienceId\", \"numericFilter\": {\"operation\": \"EQUAL\", \"value\": {\"doubleValue\": 5559548544}}}}\n", | ||
"ANALYTICS_START = \"2021-01-01\"\n", | ||
"TODAY = 'today'\n", | ||
"PERIOD = \"2024-08\"\n", | ||
"PREV_PERIOD = \"2024-07\"\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"\n", | ||
"default_params_portal = {\n", | ||
" \"service_system\": anvil.authenticate_ga_portal(SECRET_NAME),\n", | ||
" \"property\": GA_PROPERTY_PORTAL,\n", | ||
" \"index_key_formatter\": anvil.adjust_table_index_key,\n", | ||
" \"base_dimension_filter\": EXCLUDE_PAGES_FILTER\n", | ||
"}\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"default_params_portal_with_date_and_filter = {\n", | ||
" **default_params_portal,\n", | ||
" \"start_date\": '30daysAgo',\n", | ||
" \"end_date\": TODAY,\n", | ||
" \"dimensionFilter\": {\n", | ||
" \"filter\": {\n", | ||
" \"stringFilter\": {\n", | ||
" \"matchType\": \"EXACT\",\n", | ||
" \"value\": \"true\"\n", | ||
" },\n", | ||
" \"fieldName\": \"outbound\"\n", | ||
" }\n", | ||
" }\n", | ||
"}" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df_outlink_domains = ac.get_data_df(\n", | ||
" [\"eventCount\"],\n", | ||
" [\"linkDomain\", \"linkUrl\"], \n", | ||
" **default_params_portal_with_date_and_filter, \n", | ||
" df_processor=lambda df: df.loc[df.index.get_level_values(0) != \"\"]\n", | ||
")\n", | ||
"df_outlink_domains.to_csv(\"outlink_domains.csv\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "venv", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.12.4" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |