Skip to content

Commit

Permalink
visualion for pageviews in GA4 and UA
Browse files Browse the repository at this point in the history
Visualization code to compare GA4 and Universal analytics page views
  • Loading branch information
babli18 committed Jul 10, 2024
1 parent 32dc7ac commit 385c79b
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions views_visualization.ipynb
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
}

0 comments on commit 385c79b

Please sign in to comment.