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

fix:add check and replace warn instead of error for setCustomNameStan… #55

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions packages/GA4Client/src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,15 @@ Common.prototype.standardizeParameters = function (parameters) {
};

Common.prototype.standardizeName = function (name) {
try {
name = window.GoogleAnalytics4Kit.setCustomNameStandardization(name);
} catch (e) {
console.error(
'Error calling setCustomNameStandardization callback. Check your callback. Data will still be sent without user-defined standardization. See our docs for proper use - https://docs.mparticle.com/integrations/google-analytics-4/event/',
e
);
if (window.GoogleAnalytics4Kit.setCustomNameStandardization(name)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're checking if setCustomNameStandardization exists, you might be better off using hasOwnProperty instead of calling the function directly.

If the function does not exist, calling the function would throw an error before the try/catch block. Also, if the function does exist, you're essentially calling it twice.

Suggested change
if (window.GoogleAnalytics4Kit.setCustomNameStandardization(name)) {
if (window.GoogleAnalytics4Kit.hasOwnProperty(setCustomNameStandardization)) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexs-mparticle thanks for correction, applying the change

try {
name = window.GoogleAnalytics4Kit.setCustomNameStandardization(name);
} catch (e) {
console.warn(
'Error calling setCustomNameStandardization callback. Check your callback. Data will still be sent without user-defined standardization. See our docs for proper use - https://docs.mparticle.com/integrations/google-analytics-4/event/',
e
);
}
}

// names of events and parameters have the following requirements:
Expand Down
Loading