In [165]:
%matplotlib inline
import numpy as np
import scipy as sp
import matplotlib as mpl
import matplotlib.cm as cm
import matplotlib.pyplot as plt
import pandas as pd
pd.set_option('display.width', 500)
pd.set_option('display.max_columns', 100)
pd.set_option('display.notebook_repr_html', True)
import seaborn as sns #sets up styles and gives us more plotting options
In [166]:
# Time period 15th Jan - 26th April (arbitrary )
# API credentials
# Email address 705762800217-compute@developer.gserviceaccount.com
# Key IDs 948ee8e2a420ef14a5d5a29bd35104fe2f1e6ed4
In [167]:
# open file. It is requested via API explorer using request parameters:
#Account: TMRW Tech Hub
#Property: TMRW
#View: All Web Site Data
#ids: ga:123303369
#start-date: 2017-02-01
#end-date: 2017-04-30
#metrics
#ga:sessions
#ga:sessionsWithEvent
#ga:bounceRate
#dimensions
#ga:deviceCategory
In [203]:
# Open file
input_mob= pd.read_csv('files/TMRW_mob_dev.csv')
In [204]:
# rename columns
input_mob.columns=['Device','Sessions','Bounce Rate','Conversions','CR']
In [205]:
# group by device
input_mob = input_mob.set_index('Device')
input_mob
Out[205]:
In [206]:
mobile_Sessions = input_mob.loc['mobile','Sessions']
desktop_CR = input_mob.loc['desktop','CR']
mobile_Conversions = input_mob.loc['mobile','Conversions']
mobile_CR = input_mob.loc['mobile','CR']
conv_increase = "%.0f" % (mobile_Sessions * desktop_CR - mobile_Conversions)
conv_increase = int(conv_increase)
#mobileSessions
#desktopCR
#mobileConversions
mobile_CR
Out[206]:
In [207]:
#if mobile CR is greater, equel or less by more than 20% result is failed
dif = mobile_CR / desktop_CR
if dif > 0.8:
result = False
else:
result = True
result
Out[207]:
In [214]:
output_chart_mob = input_mob.loc['mobile',['Sessions','Conversions']]
output_chart_mob.plot.barh(stacked=True)
labels = output_chart_mob.index
sizes = output_chart_mob
# colours are taken from http://tools.medialab.sciences-po.fr/iwanthue/
colors = ['#b94663','#6fac5d', '#677ad1']
explode = (0, 0, 0)
plt.xlabel('Visits')
plt.title('Only %s ' % ("%.2f" % (mobile_CR*100) +'% of all mobile visits end up completing a conversion' ))
#need to specify analytics time perdiod
print ("Have %s more conversions per month by optmising mobile UX" % conv_increase)
plt.show()
In [ ]:
In [ ]: