Skip to content

Commit

Permalink
Adding craigslist pivot table and fixing rt bug (#88)
Browse files Browse the repository at this point in the history
* Adding craigslist pivot table and fixing rt bug

* Changing completions to conversions
  • Loading branch information
nathan-moore-97 authored Nov 3, 2023
1 parent 8eb9be7 commit 72e7aea
Showing 1 changed file with 137 additions and 7 deletions.
144 changes: 137 additions & 7 deletions gdrive/idva_flow_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def create_pages_and_pivot_tables(df: pd.DataFrame, sheets_id: str):
page1 = "Rekrewt Pivot Table - First Visit"
page2 = "Rekrewt Pivot Table - Sessions"
page3 = "GSA Use Pivot Table"
page4 = "Completions"
page4 = "Conversions"

new_sheet_name_to_id = sheets_client.add_new_pages(
[page1, page2, page3, page4], sheets_id
Expand All @@ -86,12 +86,12 @@ def create_pivot_tables(

create_first_visit_pt(sheets_id, names_to_id[page_names[0]], col_dict)
log.info(
"Added 2 pivot tables to %s (%s)" % (page_names[0], names_to_id[page_names[0]])
"Added 3 pivot tables to %s (%s)" % (page_names[0], names_to_id[page_names[0]])
)

create_session_start_pt(sheets_id, names_to_id[page_names[1]], col_dict)
log.info(
"Added 2 pivot tables to %s (%s)" % (page_names[1], names_to_id[page_names[1]])
"Added 3 pivot tables to %s (%s)" % (page_names[1], names_to_id[page_names[1]])
)

create_clicks_pt(sheets_id, names_to_id[page_names[2]], col_dict)
Expand All @@ -111,7 +111,7 @@ def create_pivot_tables(
sheets_id,
page_names[0],
"A18",
'=GETPIVOTDATA("SUM of eventCount",A1, "eventName", "first_visit") + GETPIVOTDATA("SUM of eventCount",F1, "eventName", "first_visit")',
'=GETPIVOTDATA("SUM of eventCount",A1, "eventName", "first_visit") + GETPIVOTDATA("SUM of eventCount",F1, "eventName", "first_visit") + GETPIVOTDATA("SUM of eventCount",K1, "eventName", "first_visit")',
)
log.info("Wrote totals to %s" % (page_names[0]))

Expand All @@ -120,7 +120,7 @@ def create_pivot_tables(
sheets_id,
page_names[1],
"A18",
'=GETPIVOTDATA("SUM of eventCount",A1, "eventName", "session_start") + GETPIVOTDATA("SUM of eventCount",F1, "eventName", "session_start")',
'=GETPIVOTDATA("SUM of eventCount",A1, "eventName", "session_start") + GETPIVOTDATA("SUM of eventCount",F1, "eventName", "session_start") + GETPIVOTDATA("SUM of eventCount",K1, "eventName", "session_start")',
)
log.info("Wrote totals to %s" % (page_names[1]))

Expand Down Expand Up @@ -229,7 +229,7 @@ def create_first_visit_pt(sheets_id, page_id, col_dict):
{
"filterCriteria": {
"condition": {
"type": "TEXT_CONTAINS",
"type": "TEXT_EQ",
"values": [
{
"userEnteredValue": "rt",
Expand All @@ -250,6 +250,68 @@ def create_first_visit_pt(sheets_id, page_id, col_dict):
"valueLayout": "HORIZONTAL",
}
}
first_visit_craigslist_pt_def = {
"pivotTable": {
"source": {
# First Sheet (Sheet1) is always ID 0
"sheetId": 0,
},
"rows": [
{
"sourceColumnOffset": col_dict["eventName"],
"showTotals": True,
"sortOrder": "ASCENDING",
},
{
"sourceColumnOffset": col_dict["firstUserSource"],
"showTotals": True,
"sortOrder": "ASCENDING",
},
{
"sourceColumnOffset": col_dict["eventCount"],
"showTotals": True,
"sortOrder": "ASCENDING",
},
],
"filterSpecs": [
{
"filterCriteria": {
"condition": {
"type": "TEXT_CONTAINS",
"values": [
{
"userEnteredValue": "first_visit",
}
],
},
"visibleByDefault": True,
},
"columnOffsetIndex": col_dict["eventName"],
},
{
"filterCriteria": {
"condition": {
"type": "TEXT_CONTAINS",
"values": [
{
"userEnteredValue": "craigslist",
},
],
},
"visibleByDefault": True,
},
"columnOffsetIndex": col_dict["firstUserSource"],
},
],
"values": [
{
"summarizeFunction": "SUM",
"sourceColumnOffset": col_dict["eventCount"],
}
],
"valueLayout": "HORIZONTAL",
}
}

sheets_client.add_pivot_tables(
sheets_id,
Expand All @@ -263,6 +325,9 @@ def create_first_visit_pt(sheets_id, page_id, col_dict):
row_idx=0,
col_idx=5,
)
sheets_client.add_pivot_tables(
sheets_id, page_id, first_visit_craigslist_pt_def, row_idx=0, col_idx=10
)


def create_session_start_pt(sheets_id, page_id, col_dict):
Expand Down Expand Up @@ -370,7 +435,7 @@ def create_session_start_pt(sheets_id, page_id, col_dict):
{
"filterCriteria": {
"condition": {
"type": "TEXT_CONTAINS",
"type": "TEXT_EQ",
"values": [
{
"userEnteredValue": "rt",
Expand All @@ -391,11 +456,76 @@ def create_session_start_pt(sheets_id, page_id, col_dict):
"valueLayout": "HORIZONTAL",
}
}
sessions_craigslist_pt_def = {
"pivotTable": {
"source": {
# First Sheet (Sheet1) is always ID 0
"sheetId": 0,
},
"rows": [
{
"sourceColumnOffset": col_dict["eventName"],
"showTotals": True,
"sortOrder": "ASCENDING",
},
{
"sourceColumnOffset": col_dict["firstUserSource"],
"showTotals": True,
"sortOrder": "ASCENDING",
},
{
"sourceColumnOffset": col_dict["eventCount"],
"showTotals": True,
"sortOrder": "ASCENDING",
},
],
"filterSpecs": [
{
"filterCriteria": {
"condition": {
"type": "TEXT_CONTAINS",
"values": [
{
"userEnteredValue": "session_start",
}
],
},
"visibleByDefault": True,
},
"columnOffsetIndex": col_dict["eventName"],
},
{
"filterCriteria": {
"condition": {
"type": "TEXT_CONTAINS",
"values": [
{
"userEnteredValue": "craigslist",
},
],
},
"visibleByDefault": True,
},
"columnOffsetIndex": col_dict["firstUserSource"],
},
],
"values": [
{
"summarizeFunction": "SUM",
"sourceColumnOffset": col_dict["eventCount"],
}
],
"valueLayout": "HORIZONTAL",
}
}

sheets_client.add_pivot_tables(sheets_id, page_id, sessions_facebook_pt_def)
sheets_client.add_pivot_tables(
sheets_id, page_id, sessions_rt_pt_def, row_idx=0, col_idx=5
)
sheets_client.add_pivot_tables(
sheets_id, page_id, sessions_craigslist_pt_def, row_idx=0, col_idx=10
)


def create_clicks_pt(sheets_id, page_id, col_dict):
Expand Down

0 comments on commit 72e7aea

Please sign in to comment.