Skip to content

Commit

Permalink
chore: added analytics script to get a simple csv of outlinks (#3202)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpaten committed Sep 28, 2024
1 parent a8db457 commit 7a10f70
Showing 1 changed file with 104 additions and 0 deletions.
104 changes: 104 additions & 0 deletions analytics/anvil-analytics-portal/portal-outlinks.ipynb
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
}

0 comments on commit 7a10f70

Please sign in to comment.