-
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
Add input_amount to events #451
Add input_amount to events #451
Conversation
✅ Deploy Preview for pendulum-pay ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
…ount for amount_type event
@@ -0,0 +1,37 @@ | |||
import { create } from 'zustand'; |
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.
@pendulum-chain/devs let me know if you like the addition of this state, if you prefer it to be more minimal (only fromAmount
) or to avoid this altogether.
Although it adds extra code, I found it less confusing than passing fromAmount
to the event context.
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'm fine with keeping it the way you implemented it 👍
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.
Looks good overall 👍 I also checked the events in Google Tag Manager.
src/pages/swap/index.tsx
Outdated
setTimeout(() => { | ||
trackEvent({ | ||
event: 'amount_type', | ||
input_amount: fromAmountRef.current ? fromAmountRef.current.toString() : '0', |
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.
Any reason we are using a ref, and especially using it only here? Alternatively, we could change the onChange
prop of the AssetNumericInput
component and pass teh new value in it. So you could access it right away. Here, you would then be able to do
onChange={(newValue: string) => {
trackEvent({...})
}}
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.
Well, the idea of the ref (and timeout) is because the onChange
will always be triggered right on first modification. We need to wait, somehow, for the actual stable amount.
If we just send the event on change, the value registered will be always 0
or whatever default value is on the form as soon as the user started typing.
I think we will have the same issue on the AssetNumericInput
. The other alternative I can think of, is to track it when the output is stable, here. Seems more cumbersome.
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.
So the ref is just used in order not to track the first (prefilled) amount?
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.
Yes, it is to store the value. I tried using the "current" fromAmount
value at the time of the first onChange
, but the timeout function will take the value as soon as it is triggered (the initial one), which will be again the default.
Since the ref updates from the useEffect
above, at the moment of triggering the event, it will read the last value typed.
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 pushed a new commit with a suggested change. I thought it might be easier to show an alternative approach instead of describing it. What do you think about using the ref only for tracking if the user touched the field but then debounce the actual value to avoid tracking too many amounts?
I also learned that useDeferredValue is not necessarily suited to debounce values like for user amounts as the timeout is not configurable.
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 saw you replaced the ref and timeout with a debounced value. Did it worked? Because I think this would send the current debouncedValue
at the moment of the first onChange
triggering.
Because here, since fromAmountFieldTouched
is a dependency, it would execute the effect right away.
Yes useDeferred was a loose import.
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 fixed that by adding another statement to the effect hook. I also removed the amount_type
event from the list of unique events. Everything seems to work as expected now.
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.
So we will capture all user quotes? Makes sense, only we will be flooded by events. But I suppose GA can handle such things.
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 personally understood that the valuable outcome of this change is that marketing is able to see all amounts that the user tried. If it's just about the final amount, we can check the input amount on the other events after all. So yes, 'flooding' would be intended I think.
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.
All good then!
@@ -0,0 +1,37 @@ | |||
import { create } from 'zustand'; |
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'm fine with keeping it the way you implemented it 👍
Addresses #371 and #412
Changes
input_amount
towallet_connect
,amount_type
andform_error
events.amount_type
we need to delay a few seconds to avoid the amount to just be0
or the default. If the interaction with the form is with the tokens, then the initial default amount will be sent.wallet_connect
a new minimal storage is added, to avoid passing props to the context.network_selected
.Tag manager
Adds a new variable
{{DLV | input_amount}}
and link it towallet_connect
,amount_type
andform_error
.Adds a new variable
{{DLV | network_selected}}
, and link it towallet_connect
.Tested on the preview of tag manager and all events now register this new parameter.