-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added event class, added documentation
- Loading branch information
1 parent
89a81f8
commit 21d5425
Showing
119 changed files
with
4,470 additions
and
517 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
const ga4 = require("index"); | ||
const helpers = require("dataform-ga4-helpers"); | ||
|
||
// 2 events have the save event_timestamp, event_name, user_pseudo_id but engagement_time_msec is different | ||
|
||
// 3 tests for each standard rule from sourceMediumRules | ||
const { rows } = require("includes/tests/data/form_events_input.js"); | ||
|
||
const { | ||
rows: resultSessionStart, | ||
} = require("includes/tests/data/session_start_result.js"); | ||
|
||
const { | ||
rows: resultLead, | ||
} = require("includes/tests/data/generate_lead_result.js"); | ||
|
||
// Base session config | ||
const eventConfig = { | ||
database: constants.GA4_DATABASE, | ||
dataset: dataform.projectConfig.vars.GA4_DATASET, | ||
incrementalTableName: dataform.projectConfig.vars.GA4_TABLE, | ||
nonIncrementalTableName: dataform.projectConfig.vars.GA4_TABLE, | ||
}; | ||
|
||
const sessionStartConfig = [ | ||
{ | ||
eventName: "session_start", | ||
columns: [ | ||
{ | ||
name: "privacy_info.analytics_storage", | ||
columnName: "analytics_storage", | ||
}, | ||
], | ||
eventParams: [{ name: "engagement_time_msec", type: "int" }], | ||
}, | ||
{ | ||
eventName: "generate_lead", | ||
eventParams: [ | ||
{ name: "value", type: "coalesce_float" }, | ||
{ name: "currency", type: "string" }, | ||
], | ||
}, | ||
]; | ||
|
||
const ef = new ga4.EventFactory(eventConfig); | ||
let events = ef.createEvents(sessionStartConfig); | ||
events.forEach((event) => { | ||
event.target = { | ||
tableName: event.target.tableName + "_create_test", | ||
}; | ||
event.getConfig = () => { | ||
return { | ||
type: "table", | ||
schema: eventConfig.dataset, | ||
}; | ||
}; | ||
|
||
event.publish(); | ||
}); | ||
|
||
// Run tests | ||
test("test_create_session_start") | ||
.dataset("session_start_create_test") | ||
.input( | ||
{ | ||
database: constants.GA4_DATABASE, | ||
schema: dataform.projectConfig.vars.GA4_DATASET, | ||
name: dataform.projectConfig.vars.GA4_TABLE, | ||
}, | ||
helpers.getSqlUnionAllFromRows(rows) | ||
) | ||
.expect(helpers.getSqlUnionAllFromRows(resultSessionStart)); | ||
|
||
test("test_create_generate_lead") | ||
.dataset("generate_lead_create_test") | ||
.input( | ||
{ | ||
database: constants.GA4_DATABASE, | ||
schema: dataform.projectConfig.vars.GA4_DATASET, | ||
name: dataform.projectConfig.vars.GA4_TABLE, | ||
}, | ||
helpers.getSqlUnionAllFromRows(rows) | ||
) | ||
.expect(helpers.getSqlUnionAllFromRows(resultLead)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const ga4 = require("index"); | ||
const helpers = require("dataform-ga4-helpers"); | ||
|
||
// 2 events have the save event_timestamp, event_name, user_pseudo_id but engagement_time_msec is different | ||
|
||
// 3 tests for each standard rule from sourceMediumRules | ||
const { rows } = require("includes/tests/data/custom_event_id_input.js"); | ||
const { | ||
rows: result, | ||
} = require("includes/tests/data/custom_event_id_result.js"); | ||
|
||
// Base session config | ||
const eventConfig = { | ||
database: constants.GA4_DATABASE, | ||
dataset: dataform.projectConfig.vars.GA4_DATASET, | ||
incrementalTableName: dataform.projectConfig.vars.GA4_TABLE, | ||
nonIncrementalTableName: dataform.projectConfig.vars.GA4_TABLE, | ||
}; | ||
|
||
let event = new ga4.Event(eventConfig); | ||
event.setEventName("form_visibility"); | ||
|
||
event.target = { | ||
tableName: "custom_event_id_tbl", | ||
}; | ||
// Unit testing working only for table type | ||
event.getConfig = () => { | ||
return { | ||
type: "table", | ||
schema: eventConfig.dataset, | ||
}; | ||
}; | ||
|
||
event.getSqlUniqueId = () => { | ||
return `(select value.int_value from unnest(event_params) where key = 'ga_session_id') as event_id`; | ||
}; | ||
// Publish session model | ||
event.publish(); | ||
|
||
// Run tests | ||
test("test_custom_event_id") | ||
.dataset("custom_event_id_tbl") | ||
.input( | ||
{ | ||
database: constants.GA4_DATABASE, | ||
schema: dataform.projectConfig.vars.GA4_DATASET, | ||
name: dataform.projectConfig.vars.GA4_TABLE, | ||
}, | ||
helpers.getSqlUnionAllFromRows(rows) | ||
) | ||
.expect(helpers.getSqlUnionAllFromRows(result)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const ga4 = require("index"); | ||
const helpers = require("dataform-ga4-helpers"); | ||
|
||
const { rows } = require("includes/tests/data/source_medium_input.js"); | ||
const { | ||
rows: result, | ||
} = require("includes/tests/data/custom_session_id_result.js"); | ||
|
||
// Base session config | ||
const sessionConfig = { | ||
database: constants.GA4_DATABASE, | ||
dataset: dataform.projectConfig.vars.GA4_DATASET, | ||
incrementalTableName: dataform.projectConfig.vars.GA4_TABLE, | ||
nonIncrementalTableName: dataform.projectConfig.vars.GA4_TABLE, | ||
}; | ||
|
||
const sessions = new ga4.Session(sessionConfig); | ||
|
||
// Rename table | ||
sessions.target = { | ||
tableName: "custom_session_id", | ||
}; | ||
|
||
// Unit testing working only for table type | ||
sessions.getConfig = () => { | ||
return { | ||
type: "table", | ||
}; | ||
}; | ||
|
||
sessions.getSqlUniqueId = () => { | ||
return `(select value.int_value from unnest(event_params) where key = 'ga_session_id') as session_id`; | ||
}; | ||
|
||
// Publish session model | ||
sessions.publish(); | ||
|
||
// Run tests | ||
|
||
test(`test_custom_session_id`) | ||
.dataset("custom_session_id") | ||
.input( | ||
{ | ||
database: constants.GA4_DATABASE, | ||
schema: dataform.projectConfig.vars.GA4_DATASET, | ||
name: dataform.projectConfig.vars.GA4_TABLE, | ||
}, | ||
helpers.getSqlUnionAllFromRows([rows[0]]) | ||
) | ||
.expect(helpers.getSqlUnionAllFromRows(result)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const ga4 = require("index"); | ||
const helpers = require("dataform-ga4-helpers"); | ||
|
||
// 2 events have the save event_timestamp, event_name, user_pseudo_id but engagement_time_msec is different | ||
|
||
// 3 tests for each standard rule from sourceMediumRules | ||
const { rows } = require("includes/tests/data/event_id_input.js"); | ||
const { rows: result } = require("includes/tests/data/event_id_result.js"); | ||
|
||
// Base session config | ||
const eventConfig = { | ||
database: constants.GA4_DATABASE, | ||
dataset: dataform.projectConfig.vars.GA4_DATASET, | ||
incrementalTableName: dataform.projectConfig.vars.GA4_TABLE, | ||
nonIncrementalTableName: dataform.projectConfig.vars.GA4_TABLE, | ||
}; | ||
|
||
let event = new ga4.Event(eventConfig); | ||
event.setEventName("form_visibility"); | ||
|
||
// Unit testing working only for table type | ||
event.getConfig = () => { | ||
return { | ||
type: "table", | ||
schema: eventConfig.dataset, | ||
}; | ||
}; | ||
|
||
// Publish session model | ||
event.publish(); | ||
|
||
// Run tests | ||
test("test_event_id") | ||
.dataset("form_visibility") | ||
.input( | ||
{ | ||
database: constants.GA4_DATABASE, | ||
schema: dataform.projectConfig.vars.GA4_DATASET, | ||
name: dataform.projectConfig.vars.GA4_TABLE, | ||
}, | ||
helpers.getSqlUnionAllFromRows(rows) | ||
) | ||
.expect(helpers.getSqlUnionAllFromRows(result)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const ga4 = require("index"); | ||
const helpers = require("dataform-ga4-helpers"); | ||
|
||
// 2 events have the save event_timestamp, event_name, user_pseudo_id but engagement_time_msec is different | ||
|
||
// 3 tests for each standard rule from sourceMediumRules | ||
const { rows } = require("includes/tests/data/form_events_input.js"); | ||
const { | ||
rows: resultStart, | ||
} = require("includes/tests/data/event_id_with_event_param_result.js"); | ||
|
||
// Base session config | ||
const eventConfig = { | ||
database: constants.GA4_DATABASE, | ||
dataset: dataform.projectConfig.vars.GA4_DATASET, | ||
incrementalTableName: dataform.projectConfig.vars.GA4_TABLE, | ||
nonIncrementalTableName: dataform.projectConfig.vars.GA4_TABLE, | ||
}; | ||
|
||
const ef = new ga4.EventFactory(eventConfig); | ||
// Just for testing purposes | ||
ef.timestampEventParamName = "engagement_time_msec"; | ||
|
||
// let purchase = ef.createPurchase(); | ||
// purchase.publish(); | ||
let events = ef.createFormEvents(); | ||
// Unit testing working only for table type | ||
|
||
const event = events.filter((ev) => ev._target.tableName === "form_submit")[0]; | ||
|
||
event.target = { | ||
tableName: "form_submit_event_id_test", | ||
}; | ||
event.getConfig = () => { | ||
return { | ||
type: "table", | ||
schema: eventConfig.dataset, | ||
}; | ||
}; | ||
|
||
event.publish(); | ||
|
||
// Run tests | ||
test("test_event_id_with_event_param") | ||
.dataset("form_submit_event_id_test") | ||
.input( | ||
{ | ||
database: constants.GA4_DATABASE, | ||
schema: dataform.projectConfig.vars.GA4_DATASET, | ||
name: dataform.projectConfig.vars.GA4_TABLE, | ||
}, | ||
helpers.getSqlUnionAllFromRows([rows[0]]) | ||
) | ||
.expect(helpers.getSqlUnionAllFromRows(resultStart)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.