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

ReactGA.event sends event title with first letter captitalised #22

Closed
sakshambhatt opened this issue Nov 2, 2021 · 6 comments
Closed

Comments

@sakshambhatt
Copy link

ReactGA initialize, gives options to make the titleCase boolean false. Could such an option be added in react-ga4 as well?
image

So that following code, leads to add_to_cart and not in Add_to_cart?

ReactGA.initialize( process.env.GA_MEASUREMENT_ID, { gaOptions: { titleCase: false } } );
ReactGA.event({
      category: "shopping",
      action: "add_to_cart",
      label: "name",
});
@codler
Copy link
Contributor

codler commented Nov 2, 2021

You can use the following code for add_to_cart.

ReactGA.event("add_to_cart", {
  items: [{ item_name: "name" }],
});

https://developers.google.com/tag-platform/gtagjs/reference/events#add_to_cart

@sakshambhatt
Copy link
Author

Thank you for the above comment. The above link has many relevant events, and that certainly helps. But what if I were to create a custom event like for example, price_compared or view_certificate? It becomes increasingly difficult with custom events if there is existing data as I will have both Price_compared and price_compared.

@codler
Copy link
Contributor

codler commented Nov 2, 2021

I don't understand what you meant. If you use ReactGA.event(name, params) method signature you won't have titleCase.

@codler codler closed this as completed Nov 2, 2021
@quyctd
Copy link

quyctd commented Nov 3, 2021

@sakshambhatt, I have the same issue. Maybe the suggestion of Codler is not clear. You can do like this:

ReactGA.event("add_to_cart", {
      event_category: "shopping",
      event_label: "name",
});

It'll result in no titleCase as you expected.

@sakshambhatt
Copy link
Author

Thank you @quyctd , I tried this and it works. @codler , it would be really appreciated if a sample were added to README like the one suggested by @quyctd in above comment. In fact, I will raise a PR myself.

@djakaitis
Copy link

I think the bigger issue here is presumptively adding title case. Shouldn't user input be kept as is?

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

No branches or pull requests

4 participants