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

Analytics feedbacks #2025

Merged
merged 15 commits into from May 2, 2024
Merged

Analytics feedbacks #2025

merged 15 commits into from May 2, 2024

Conversation

wizardlyhel
Copy link
Contributor

@wizardlyhel wizardlyhel commented Apr 19, 2024

WHY are these changes introduced?

  • Fixes the case when we are using the customer privacy api without the banner (for integrating with 3P consent management tools), the <Analytics.Provider> will not send any events.
  • Make sure consent.checkoutDomain and consent.storefrontAccessToken is required
  • Fixes product_added_to_cart and product_removed_from_cart not firing #2026
  • Make sure customer privacy is not using legacy functions

Introduce onReady callback for useCustomerPrivacy hook.

WHAT is this pull request doing?

HOW to test your changes?

Use analytics example:

  1. Test errors
    • Remove consent.checkoutDomain from root loader --> site should generate error about missing props
    • Remove consent.storefrontAccessToken from root loader --> site should generate error about missing props
  2. Test working analytics
    • Add consent.withPrivacybanner: false in the root loader --> You should see CustomAnalytics logging page views in the console log

Post-merge steps

Checklist

  • I've read the Contributing Guidelines
  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've added a changeset if this PR contains user-facing or noteworthy changes
  • I've added tests to cover my changes
  • I've added or updated the documentation

Copy link
Contributor

shopify bot commented Apr 19, 2024

Oxygen deployed a preview of your hl-update-analytics-components branch. Details:

Storefront Status Preview link Deployment details Last update (UTC)
vite ✅ Successful (Logs) Preview deployment Inspect deployment May 2, 2024 9:15 PM
third-party-queries-caching ✅ Successful (Logs) Preview deployment Inspect deployment May 2, 2024 9:15 PM
skeleton ✅ Successful (Logs) Preview deployment Inspect deployment May 2, 2024 9:15 PM
optimistic-cart-ui ✅ Successful (Logs) Preview deployment Inspect deployment May 2, 2024 9:15 PM
subscriptions ✅ Successful (Logs) Preview deployment Inspect deployment May 2, 2024 9:15 PM
custom-cart-method ✅ Successful (Logs) Preview deployment Inspect deployment May 2, 2024 9:15 PM

Learn more about Hydrogen's GitHub integration.

@jamalsoueidan
Copy link
Contributor

Fixes #0000 👯

@wizardlyhel wizardlyhel marked this pull request as ready for review April 19, 2024 21:49

This comment has been minimized.

return window.Shopify.customerPrivacy.analyticsProcessingAllowed();
}
return false;
} catch (error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit picky, but worth printing the error? Or maybe just killing the param altogether?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ts doesn't like catch() {}. End with catch(e) {}

Comment on lines 262 to 264
typeof window?.Shopify?.customerPrivacy?.analyticsProcessingAllowed ===
'function'
) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit picky, but could this whole if statement just be typeof window?.Shopify?.customerPrivacy?.analyticsProcessingAllowed === 'function'? If any property along the way is undefined, typeof undefined will not be function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good call .. in fact, since the whole thing is in a try-catch, the if statement is not needed

The try catch is needed because this function may be run at server side

@wizardlyhel wizardlyhel merged commit 58ea9bb into main May 2, 2024
13 checks passed
@wizardlyhel wizardlyhel deleted the hl-update-analytics-components branch May 2, 2024 21:54
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.

product_added_to_cart and product_removed_from_cart not firing
4 participants