-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
visualion for pageviews in GA4 and UA
Visualization code to compare GA4 and Universal analytics page views
- Loading branch information
Showing
1 changed file
with
96 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,96 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import pandas as pd\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"import seaborn as sns" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"ga = pd.read_excel('views_ga4_ua.xlsx',sheet_name='GA4')\n", | ||
"ua = pd.read_excel('views_ga4_ua.xlsx',sheet_name='UA')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"ga=ga.set_index('Views')\n", | ||
"ua=ua.set_index('Views')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"ga = ga.T\n", | ||
"ua = ua.T" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def visualize(index,ga_val,ua_val,region):\n", | ||
" sns.set_style(\"whitegrid\")\n", | ||
" plt.figure(figsize=(10,5))\n", | ||
" sns.lineplot(x=index,y=ga_val, label = 'GA-4',color = 'blue')\n", | ||
" sns.lineplot(x=index,y=ua_val, label = 'UA',color = 'orangered')\n", | ||
" plt.title(region +' - Page Views (2023)')\n", | ||
" plt.legend(loc = 'upper left')\n", | ||
" plt.xlabel('Months')\n", | ||
" plt.ylabel('Page Views')\n", | ||
" plt.tight_layout()\n", | ||
" plt.savefig(\"graph/\"+region+\".jpeg\", format='jpeg')\n", | ||
" plt.show()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"for (gaCol,gaData),(uaCol,uaData) in zip(ga.items(),ua.items()):\n", | ||
" visualize(gaData.index, gaData.values, uaData.values, gaCol)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"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.11.5" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |