<jupyter_start><jupyter_text>Analytics report<jupyter_code># !pip install google_auth_oauthlib 
# !pip install install google-api-python-client
# !pip install pandas 
# !pip install numpy
# !pip install matplotlib
# !pip install google-cloud-bigquery
# !pip install db-dtypes

# DEV GUIDES
#https://developers.google.com/analytics/devguides/reporting
    



import warnings
warnings.filterwarnings('ignore')
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build
from IPython.display import display
import os
import pprint
# import pandas as pd
# import matplotlib.pyplot as plt
# import numpy as np
import analytics_api as ga

%load_ext autoreload
%autoreload 2

import analytics_charts as ac
GA_PROPERTY = "185740629" # HCA Data Portal/Browser
DCP_ANALYTICS_START = "2019-03-01"
TODAY = 'today'

ac.authenticate_ga()


ac.plot_users_over_time(GA_PROPERTY, DCP_ANALYTICS_START,TODAY)

ac.plot_hbar(GA_PROPERTY,"Top Referrers, Last 90 Days", "Users", "Referrer", "ga:users","ga:source", '90daysAgo',"today")
ac.plot_hbar(GA_PROPERTY, "Top Countries, Last 90 Days", "Users", "Country", "ga:users","ga:country", '90daysAgo',"today")
ac.plot_hbar(GA_PROPERTY, "Entrances", "Entrances", "Page", "ga:entrances","ga:pagePath", '90daysAgo',"today")


ac.show_difference_table(GA_PROPERTY, "Entrances", "Page", "ga:entrances","ga:pagePath", "2022Q1", "2021Q4")<jupyter_output><empty_output><jupyter_text>Users and Sessions<jupyter_code>ac.show_difference_table(GA_PROPERTY, "Total Users", None, "ga:users", None, "2022Q1", "2021Q4")
ac.show_difference_table(GA_PROPERTY, "Returning Users", None, "ga:users", None, filters="ga:userType==Returning Visitor", period="2022Q1", prev_period="2021Q4")
ac.show_difference_table(GA_PROPERTY, "Total Visits", None, "ga:sessions", None, "2022Q1", "2021Q4")
ac.show_difference_table(GA_PROPERTY, "Sessions Including Visits to Data Portal", None, "ga:sessions", None, filters="ga:pagePath!~/explore", period="2022Q1", prev_period="2021Q4")
ac.show_difference_table(GA_PROPERTY, "Sessions Including Visits to Data Browser", None, "ga:sessions", None, filters="ga:pagePath=~/explore", period="2022Q1", prev_period="2021Q4")<jupyter_output><empty_output><jupyter_text>Social Network Referrers<jupyter_code>ac.show_difference_table(GA_PROPERTY, "User Sessions", "Social Network", "ga:sessions", "ga:socialNetwork", period="2022Q1", prev_period="2021Q4")<jupyter_output><empty_output><jupyter_text>Downloads<jupyter_code>ac.show_difference_table(GA_PROPERTY, ["Users", "Count"], "Action", ["ga:users", "ga:hits"], ["ga:eventAction", "ga:eventCategory"], filters="ga:eventCategory==Project;ga:eventAction==Download Project Manifest", ordered=False, period="2022Q1", prev_period="2021Q4")
ac.show_difference_table(GA_PROPERTY, ["Users", "Count"], "Download Type", ["ga:users", "ga:hits"], ["ga:dimension6", "ga:eventAction", "ga:eventCategory"], filters="ga:eventCategory==Project;ga:eventAction==Download Project Matrix", ordered=False, period="2022Q1", prev_period="2021Q4")
ac.show_difference_table(GA_PROPERTY, ["Users", "Count"], "curl Request From Search Results", ["ga:users", "ga:hits"], ["ga:dimension1", "ga:eventAction", "ga:eventCategory"], filters="ga:eventAction==Request;ga:dimension1==Bulk Download", ordered=False, period="2022Q1", prev_period="2021Q4")
ac.show_difference_table(GA_PROPERTY, ["Users", "Count"], "Metadata Request/Download From Search Results", ["ga:users", "ga:hits"], ["ga:dimension1", "ga:eventAction", "ga:eventCategory"], filters="ga:eventCategory==Manifest;ga:eventAction=~Request|Download;ga:dimension1=~Cohort Manifest|Cohort Manifest Link", ordered=False, period="2022Q1", prev_period="2021Q4")
ac.show_difference_table(GA_PROPERTY, ["Users", "Count"], "Request Export From Search Results", ["ga:users", "ga:hits"], ["ga:dimension3", "ga:dimension1", "ga:eventAction", "ga:eventCategory"], filters="ga:eventCategory==Export;ga:eventAction==Request;ga:dimension1==Cohort Export;ga:dimension3==Terra", ordered=False, period="2022Q1", prev_period="2021Q4")
ac.show_difference_table(GA_PROPERTY, ["Users", "Count"], "Action", ["ga:users", "ga:hits"], ["ga:eventAction", "ga:eventCategory"], filters="ga:eventCategory==File;ga:eventAction==Download", ordered=False, period="2022Q1", prev_period="2021Q4")<jupyter_output><empty_output><jupyter_text>Top Search Results Selected for Export<jupyter_code>ac.show_difference_table(GA_PROPERTY, "Selected for Export Count", "Query", "ga:pageviews", "ga:pagePath", filters="ga:pagePath=~/explore/export/export-to-terra|/explore/export/get-curl-command|/explore/export/download-manifest", period="2022Q1", prev_period="2021Q4")<jupyter_output><empty_output><jupyter_text>Top Direct File Downloads From Files Tab<jupyter_code>ac.show_difference_table(GA_PROPERTY, "Downloads", "File", "ga:hits", "ga:eventLabel", filters="ga:eventCategory==File;ga:eventAction==Download", period="2022Q1", prev_period="2021Q4")<jupyter_output><empty_output><jupyter_text>Top Direct File Download File Types (From Files Tab)<jupyter_code>ac.show_difference_table(GA_PROPERTY, "Downloads", "File Type", "ga:hits", "ga:dimension6", filters="ga:eventCategory==File;ga:eventAction==Download", period="2022Q1", prev_period="2021Q4")<jupyter_output><empty_output><jupyter_text>Top Facets<jupyter_code>ac.show_difference_table(GA_PROPERTY, "Count", "Facet", "ga:hits", "ga:dimension9", filters="ga:eventCategory==Search;ga:eventAction==Select", period="2022Q1", prev_period="2021Q4")<jupyter_output><empty_output><jupyter_text>Top Facet Terms<jupyter_code>ac.show_difference_table(GA_PROPERTY, "Count", ["Facet", "Term"], "ga:hits", ["ga:dimension9", "ga:dimension10"], filters="ga:eventCategory==Search;ga:eventAction==Select", period="2022Q1", prev_period="2021Q4")<jupyter_output><empty_output><jupyter_text>Entity Tabs Selections (Project, Samples, Files)<jupyter_code>ac.show_difference_table(GA_PROPERTY, "Count", "Entity Tab", "ga:hits", "ga:eventLabel", filters="ga:eventCategory==Entity;ga:eventAction==Select Tab", period="2022Q1", prev_period="2021Q4")<jupyter_output><empty_output><jupyter_text>Top Project Detail Pages<jupyter_code>ac.show_difference_table(GA_PROPERTY, "Count", "Project", "ga:pageviews", "ga:pagePath", filters="ga:pagePath=~^(\\/explore\\/projects\\/[0-9a-fA-F]{8}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{12})(\\/?\\?{0}|\\/?\\?{1}.*)$", period="2022Q1", prev_period="2021Q4")<jupyter_output><empty_output><jupyter_text>Project Detail Supplementary Links Visits (From External Resources)<jupyter_code>ac.show_difference_table(GA_PROPERTY, "Visits", "Link", "ga:hits", ["ga:dimension4", "ga:dimension6", "ga:eventLabel"], filters="ga:eventCategory==Project;ga:eventAction==View External Resource", period="2022Q1", prev_period="2021Q4")<jupyter_output><empty_output><jupyter_text>Withdrawn/Deprecated Projects Visits<jupyter_code>ac.show_difference_table(GA_PROPERTY, "Count", "Project Type", "ga:hits", "ga:eventAction", filters="ga:eventAction=~View Deprecated Project|View Withdrawn Project", period="2022Q1", prev_period="2021Q4")<jupyter_output><empty_output><jupyter_text>Analysis Protocol Portal Links<jupyter_code>ac.show_difference_table(GA_PROPERTY, "Count", "Analysis Protocol", "ga:hits", "ga:eventLabel", filters="ga:eventCategory==Portal Link;ga:eventAction==Click", period="2022Q1", prev_period="2021Q4")<jupyter_output><empty_output><jupyter_text>Top Landing Pages<jupyter_code>ac.show_difference_table(GA_PROPERTY, "Count", "Path", "ga:entrances", "ga:landingPagePath", filters="ga:landingPagePath!~^\/explore", period="2022Q1", prev_period="2021Q4")<jupyter_output><empty_output><jupyter_text>Top Pages<jupyter_code>ac.show_difference_table(GA_PROPERTY, "Count", "Path", "ga:pageviews", "ga:pagePath", filters="ga:pagePath!~^\/explore", period="2022Q1", prev_period="2021Q4")<jupyter_output><empty_output><jupyter_text>Top Searches<jupyter_code>ac.show_difference_table(GA_PROPERTY, "Count", "Search Text", "ga:hits", ["ga:eventLabel", "ga:eventAction"], filters="ga:eventCategory==Search;ga:eventAction==Enter Text", period="2022Q1", prev_period="2021Q4")<jupyter_output><empty_output><jupyter_text>Top Selected Search Results<jupyter_code>ac.show_difference_table(GA_PROPERTY, "Count", "Search Result", "ga:hits", ["ga:eventLabel", "ga:eventAction"], filters="ga:eventCategory==Search;ga:eventAction==Click", period="2022Q1", prev_period="2021Q4")
ac.plot_downloads()
ac.plot_ethnicity()<jupyter_output>D:\Hunter_ext\anaconda3\lib\site-packages\google\auth\_default.py:79: UserWarning: Your application has authenticated using end user credentials from Google Cloud SDK without a quota project. You might receive a "quota exceeded" or "API not enabled" error. We recommend you rerun `gcloud auth application-default login` and make sure a quota project is added. Or you can use service accounts instead. For more information about service accounts, see https://cloud.google.com/docs/authentication/
  warnings.warn(_CLOUD_SDK_CREDENTIALS_WARNING)
{'fraction_non_alphanumeric': 0.16535781440106184, 'fraction_numerical': 0.03705342329388342, 'mean_word_length': 12.142441860465116, 'pattern_counts': {'":': 0, '<': 72, '<?xml version=': 0, '>': 72, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '18', 'dir': 'jupyter-structured-clean-dedup', 'id': '257857', 'license': 'Apache-2.0', 'n_tokens_mistral': 3357, 'n_tokens_neox': 3150, 'n_words': 507, 'path': 'analytics/hdgar-book/.ipynb_checkpoints/hca-dcp-google-analytics-report-checkpoint.ipynb', 'repo_name': 'DataBiosphere/data-browser', 'size': '9041'}