diff --git a/gdrive/idva/flow_analytics.py b/gdrive/idva/flow_analytics.py index acf2570..38bf4e3 100644 --- a/gdrive/idva/flow_analytics.py +++ b/gdrive/idva/flow_analytics.py @@ -116,7 +116,7 @@ def create_pages(sheets_id: str) -> dict: names_to_id (dict): A Dictionary mapping string sheet names to IDs """ new_sheet_name_to_id = sheets_client.add_new_pages( - [SheetsEnum.REKREWT.value, SheetsEnum.GSA.value], sheets_id + [SheetsEnum.REKREWT.value, SheetsEnum.GSA.value], sheets_id, column_count=30 ) log.info("Added %s pages to %s" % (len(new_sheet_name_to_id.keys()), sheets_id)) return new_sheet_name_to_id @@ -133,6 +133,7 @@ def create_pivot_tables(df: pd.DataFrame, names_to_id: dict, sheets_id: str): reddit_pivot(sheets_id, names_to_id, col_dict) twitter_x_pivot(sheets_id, names_to_id, col_dict) linkedin_pivot(sheets_id, names_to_id, col_dict) + linked_pivot(sheets_id, names_to_id, col_dict) sheets_client.add_pivot_tables( sheets_id, names_to_id[SheetsEnum.GSA.value], idva.clicks(col_dict) @@ -380,6 +381,50 @@ def linkedin_pivot(sheets_id, names_to_id, col_dict): ) +def linked_pivot(sheets_id, names_to_id, col_dict): + sheets_client.update_cell_value( + sheets_id, SheetsEnum.REKREWT.value, "AA5", "LINKED.COM" + ) # Pivot table Label + sheets_client.update_cell_value( + sheets_id, SheetsEnum.REKREWT.value, "H1", "LINKED.COM" + ) # Totals label + + sheets_client.add_pivot_tables( + sheets_id, + names_to_id[SheetsEnum.REKREWT.value], + idva.linkedin(col_dict), + row_idx=5, + col_idx=26, + ) + + linkedin_sessions = FormulaBuilder( + FormulaEnum.GET_PIVOT_DATA, + params=[ + StringLiteral("SUM of eventCount"), + "AA6", + StringLiteral("eventName"), + StringLiteral("session_start"), + ], + ) + + linkedin_visit = FormulaBuilder( + FormulaEnum.GET_PIVOT_DATA, + params=[ + StringLiteral("SUM of eventCount"), + "AA6", + StringLiteral("eventName"), + StringLiteral("first_visit"), + ], + ) + + sheets_client.update_cell_value( + sheets_id, SheetsEnum.REKREWT.value, "H2", linkedin_sessions.render() + ) + sheets_client.update_cell_value( + sheets_id, SheetsEnum.REKREWT.value, "H3", linkedin_visit.render() + ) + + def generate_filename(date: datetime, end_date: datetime = None): """ Return filename for the new spreadsheet to be saved as diff --git a/gdrive/idva/pivot_director.py b/gdrive/idva/pivot_director.py index 1e65ef7..9faa80f 100644 --- a/gdrive/idva/pivot_director.py +++ b/gdrive/idva/pivot_director.py @@ -272,3 +272,51 @@ def linkedin(self, col_dict: dict) -> dict: ) return builder.render() + + def linked(self, col_dict: dict) -> dict: + builder = PivotTableBuilder(0, col_dict) + builder.add_row("eventName", SortOrderEnum.ASCENDING, show_totals=False) + builder.add_row("firstUserMedium", SortOrderEnum.ASCENDING) + builder.add_row("firstUserSource", SortOrderEnum.ASCENDING) + builder.add_value("eventCount", SummarizeFunctionEnum.SUM) + + # =OR(regexmatch(firstUserSource,"linked.com")) + linked = FormulaBuilder( + FormulaEnum.OR, + [ + FormulaBuilder( + FormulaEnum.REGEX_MATCH, + ["firstUserSource", StringLiteral("linked.com")], + ), + FormulaBuilder( + FormulaEnum.REGEX_MATCH, + ["firstUserMedium", StringLiteral("linked.com")], + ), + ], + ) + + sessions = FormulaBuilder( + FormulaEnum.OR, + [ + FormulaBuilder( + FormulaEnum.REGEX_MATCH, + ["eventName", StringLiteral("session_start")], + ), + FormulaBuilder( + FormulaEnum.REGEX_MATCH, ["eventName", StringLiteral("first_visit")] + ), + ], + ) + + builder.add_filter( + "firstUserSource", + FilterTypeEnum.CUSTOM, + values=[UserEnteredValue(linked.render())], + ) + builder.add_filter( + "eventName", + FilterTypeEnum.CUSTOM, + values=[UserEnteredValue(sessions.render())], + ) + + return builder.render() diff --git a/gdrive/sheets_client.py b/gdrive/sheets_client.py index 2c766a5..72fa2f8 100644 --- a/gdrive/sheets_client.py +++ b/gdrive/sheets_client.py @@ -118,13 +118,19 @@ def add_pivot_tables( return response -def add_new_pages(page_names: [str], sheets_id: str): +def add_new_pages( + page_names: [str], sheets_id: str, row_count: int = 1000, column_count: int = 26 +): new_sheets_reqs = [] for label in page_names: req = { "addSheet": { "properties": { "title": label, + "gridProperties": { + "rowCount": row_count, + "columnCount": column_count, + }, } } }