-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EventsSDK: Support Google Tag Manager #118
Conversation
In order to support Google Tag Manager, we will export a new function just specifically for sending Events API requests from it. This also adds a convertTypesGTM function which is used to convert booleans and numbers represented as strings to their correct types. This is unit tested in convertTypes.test.ts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Link the story
import { EventPayload } from './EventPayload'; | ||
|
||
// Define the list of possibly numerical properties to check and convert | ||
const propertiesToCheck = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyway to source this automatically from the event payload?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked into this a little bit and it appears that since interfaces do not exist at runtime, extracting any information from it at run time is not possible. It seems in order to use typeof
on fields of EventPayload the object would need to be initialized.
I also considered just looping through the data object and just determining to convert based on if it is a string representing a boolean or a number, but I am concerned that this will cause more complexity for fields that are strings that look like numbers, but are meant to stay strings in the payload. For example, browserVersion and alike fields.
I know its not ideal to maintain a hard coded list, but I can add this to the wiki for something to remember when adding a new field to the events schema.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gotcha thanks for the explanation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, had a small question about the actions warnings but feel free to ship if its expected.
|
||
beforeEach(() => { | ||
// Mock window['analyticsEventPayload'] | ||
(global as any).window = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to confirm, nothing we can do about these warnings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately not. The alternatives cause actual errors.
-
Changing to unknown leads to
Object is of type 'unknown'.
-
Changing to never leads to
Property 'window' does not exist on type 'never'.ts(2339)
-
Removing the cast complety leads to `Type '{}' is not assignable to type 'Window & typeof globalThis'.
If we decide this is noisy we can also add an ignore comment to the top of the file in a future PR.
/* eslint-disable @typescript-eslint/no-explicit-any */
In order to support Google Tag Manager, we will export a new function just specifically for sending Events API requests from it. This also adds a convertTypesGTM function which is used to convert booleans and numbers represented as strings to their correct types. This is unit tested in convertTypes.test.ts.
J=https://yexttest.atlassian.net/browse/FUS-6055
TEST=auto, unit