Skip to content

Commit 86cd509

Browse files
authored
Merge pull request #11 from Knowit-Experience-MarTech/09_BigQuery.gs-bug-fix
09 big query.gs bug fix
2 parents c831304 + 0504618 commit 86cd509

2 files changed

Lines changed: 29 additions & 6 deletions

File tree

Google-Sheet/Apps-Script/09_BigQuery.gs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,20 +1024,43 @@ const helperSheet = ss.getSheetByName(helperGA4EventDataFromBigQueryTab);
10241024
const undocumentedEvents = allEventNames.filter(name => !eventDataDocumented.includes(name));
10251025

10261026
if (undocumentedEvents.length > 0) {
1027-
const undocumentedStartRow = headerRowNumber + sheetData.length + 1;
1028-
// Insert undocumented events
1027+
// 2) Find the last row that has data in the eventNameColumn (column #2, or your chosen column)
1028+
const eventNameValues = eventSheet
1029+
.getRange(1, eventNameColumn, eventSheet.getLastRow(), 1)
1030+
.getValues();
1031+
1032+
let lastRowWithDataInEventName = 0;
1033+
// Loop bottom-up to find the first non-empty cell in that column
1034+
for (let i = eventNameValues.length - 1; i >= 0; i--) {
1035+
// If not empty
1036+
if (eventNameValues[i][0].toString().trim() !== "") {
1037+
lastRowWithDataInEventName = i + 1; // 1-based
1038+
break;
1039+
}
1040+
}
1041+
1042+
// 3) We will start adding new rows after that last row
1043+
const undocumentedStartRow = lastRowWithDataInEventName + 1;
1044+
1045+
// 4) Insert each undocumented event in a new row
10291046
undocumentedEvents.forEach((eventName, i) => {
1030-
const { eventCount, platforms } = eventPlatformMap[eventName] || { eventCount: 0, platforms: new Set() };
1047+
const { eventCount, platforms } = eventPlatformMap[eventName] || {
1048+
eventCount: 0,
1049+
platforms: new Set()
1050+
};
10311051
const row = undocumentedStartRow + i;
1052+
1053+
// Set the event name
10321054
eventSheet.getRange(row, eventNameColumn).setValue(eventName);
1055+
// Set the count
10331056
eventSheet.getRange(row, eventEventCountColumn).setValue(eventCount);
10341057

1035-
// Insert checkboxes for these new rows
1058+
// Insert checkboxes
10361059
eventSheet.getRange(row, eventPlatformWebsiteColumn).insertCheckboxes();
10371060
eventSheet.getRange(row, eventPlatformIosColumn).insertCheckboxes();
10381061
eventSheet.getRange(row, eventPlatformAndroidColumn).insertCheckboxes();
10391062

1040-
// Set values
1063+
// Set platform checkboxes
10411064
eventSheet.getRange(row, eventPlatformWebsiteColumn).setValue(platforms.has('WEB'));
10421065
eventSheet.getRange(row, eventPlatformIosColumn).setValue(platforms.has('IOS'));
10431066
eventSheet.getRange(row, eventPlatformAndroidColumn).setValue(platforms.has('ANDROID'));

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This solution simplifies the documentation and management of **Events**, **Key Events**, and **Parameters** (Dimensions & Metrics) for **Google Analytics 4 (GA4)**.
44

5-
* [3.0 is latest version](../../releases/tag/3.0).
5+
* [3.1 is latest version](../../releases/tag/3.1).
66

77
### Key Components
88
- **[Google Sheet](Google-Sheet):** Central platform for documenting Events, Parameters, and Annotations.

0 commit comments

Comments
 (0)