Skip to content
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

Merged
merged 13 commits into from
Feb 20, 2025

Conversation

gianfra-t
Copy link
Contributor

@gianfra-t gianfra-t commented Feb 5, 2025

Addresses #371 and #412

Changes

  • Adds the parameter input_amount to wallet_connect, amount_type and form_error events.
  • We use the current amount on the form for these events. For amount_type we need to delay a few seconds to avoid the amount to just be 0 or the default. If the interaction with the form is with the tokens, then the initial default amount will be sent.
  • For wallet_connect a new minimal storage is added, to avoid passing props to the context.
  • For Add network_selected parameter #412, we add the the network id to the event with parameter name network_selected.

Tag manager

Adds a new variable {{DLV | input_amount}} and link it to wallet_connect, amount_type and form_error.
Adds a new variable {{DLV | network_selected}}, and link it to wallet_connect.

Tested on the preview of tag manager and all events now register this new parameter.

@gianfra-t gianfra-t linked an issue Feb 5, 2025 that may be closed by this pull request
Copy link

netlify bot commented Feb 5, 2025

Deploy Preview for pendulum-pay ready!

Name Link
🔨 Latest commit 9ef4bde
🔍 Latest deploy log https://app.netlify.com/sites/pendulum-pay/deploys/67b741624576be000853eb19
😎 Deploy Preview https://deploy-preview-451--pendulum-pay.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@gianfra-t gianfra-t marked this pull request as ready for review February 5, 2025 18:43
@gianfra-t gianfra-t changed the title Add input_amount to events [IN-PROGRESS] Add input_amount to events Feb 5, 2025
@gianfra-t gianfra-t changed the title [IN-PROGRESS] Add input_amount to events Add input_amount to events Feb 6, 2025
@@ -0,0 +1,37 @@
import { create } from 'zustand';
Copy link
Contributor Author

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.

Copy link
Member

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 👍

@gianfra-t gianfra-t requested a review from a team February 6, 2025 14:02
Copy link
Member

@ebma ebma left a 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.

setTimeout(() => {
trackEvent({
event: 'amount_type',
input_amount: fromAmountRef.current ? fromAmountRef.current.toString() : '0',
Copy link
Member

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({...})
}}

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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 debouncedValueat 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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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';
Copy link
Member

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 👍

@ebma ebma merged commit 08efc18 into staging Feb 20, 2025
4 of 5 checks passed
@ebma ebma deleted the 371-add-parameter-to-the-amount_type-event-on-ga branch February 20, 2025 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add parameter to the amount_type event on GA
2 participants