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

Why create 200 dimensions & metrics with arbitrary values in custom_map? #21

Closed
Loque- opened this issue Nov 1, 2021 · 3 comments
Closed
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@Loque-
Copy link

Loque- commented Nov 1, 2021

Hi there, I am implementing this library but am curious why these lines exists:

react-ga4/src/ga4.js

Lines 473 to 488 in 0e2e3a6

_appendCustomMap(options) {
if (!options.custom_map) {
options.custom_map = {};
}
for (let i = 1; i <= 200; i++) {
if (!options.custom_map[`dimension${i}`]) {
options.custom_map[`dimension${i}`] = `dimension${i}`;
}
if (!options.custom_map[`metric${i}`]) {
options.custom_map[`metric${i}`] = `metric${i}`;
}
}
return options;
}

It creates 10.5kb of JSON that is then sent, and yea, not sure why, or how to stop it from doing so.

Many thanks.

@codler
Copy link
Contributor

codler commented Nov 1, 2021

It is to be backward compatible with how you used before with analytics.js(now are gtag.js). But yeah this can be optimised for new users who dosen't use the old way of custom dimensions or custom metrics.

Ref.
https://developers.google.com/analytics/devguides/collection/analyticsjs/custom-dims-mets
https://developers.google.com/analytics/devguides/collection/gtagjs/custom-dims-mets

@Loque-
Copy link
Author

Loque- commented Nov 1, 2021

Thank you for getting back to me.

I understand custom metrics and dimensions (that you might want to define them and send them), but I don't understand why you would want to create 200 dimensions and metrics that just have their own name as their value regardless of whether the implementation defines a custom_map or not.

It would be awesome, that if an entry is defined, it passes that on, but if not, that it doesn't add these 200 entries - at least in my use case.

Screenshot 2021-11-01 at 16 12 43

hope this ticket helps - appreciate the lib.

@codler
Copy link
Contributor

codler commented Nov 1, 2021

I understand custom metrics and dimensions (that you might want to define them and send them), but I don't understand why you would want to create 200 dimensions and metrics that just have their own name as their value regardless of whether the implementation defines a custom_map or not.

It is because the library doesn't know what dimensions/metrics are used until the consumer send an event. and custom_map can only be set during initialisation so thats why they are pre set.

From version 1.4.0
I added an option now legacyDimensionMetric where you can switch off these extra mapping in custom_map.

ReactGA.initialize("your GA measurement id", { legacyDimensionMetric : false });

alternative you can now also override or extend part of react-ga4 implementation

import { ReactGAImplementation } from "react-ga4";

class MyCustomOverriddenClass extends ReactGAImplementation {}

export default new MyCustomOverriddenClass();

@codler codler closed this as completed Nov 1, 2021
@codler codler added documentation Improvements or additions to documentation enhancement New feature or request labels Nov 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants