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

ShopifyCustomerPrivacy fixes and improvements #2103

Merged
merged 6 commits into from
May 14, 2024

Conversation

juanpprieto
Copy link
Contributor

These are some fixes and optimizations based on a 3P consent implementation.

[x] Add validation and error logging to ensure conset.storefrontAccessToken is a valid public token and not a server token
[x] Add an explicit return type of CustomerPrivacy | null to getCustomerPrivacy
[x] Add a type of (data: {error: string} | undefined) => void to the setTrackingConsent callback
[x] Fix the VisitorConsent type to expect Boolean values instead of "true", "false" strings. While implementing a 3P consent sync with Shopify, we noticed that sale_of_data must be a boolean or setTrackingConsent would error. @alejandro-shopify could you confirm that these can be booleans? CC @wizardlyhel

Copy link
Contributor

shopify bot commented May 10, 2024

Oxygen deployed a preview of your juanpprieto/fix-analytics branch. Details:

Storefront Status Preview link Deployment details Last update (UTC)
custom-cart-method ✅ Successful (Logs) Preview deployment Inspect deployment May 14, 2024 6:49 PM
vite ✅ Successful (Logs) Preview deployment Inspect deployment May 14, 2024 6:49 PM
third-party-queries-caching ✅ Successful (Logs) Preview deployment Inspect deployment May 14, 2024 6:49 PM
optimistic-cart-ui ✅ Successful (Logs) Preview deployment Inspect deployment May 14, 2024 6:50 PM
subscriptions ✅ Successful (Logs) Preview deployment Inspect deployment May 14, 2024 6:50 PM
Skeleton (skeleton.hydrogen.shop) ✅ Successful (Logs) Preview deployment Inspect deployment May 14, 2024 6:49 PM

Learn more about Hydrogen's GitHub integration.

@alejandro-shopify
Copy link

Yes, the args to setTrackingConsent are booleans. Full types:

export interface SetGranularConsentParameter {
  [ConsentDisplayKeys.MARKETING]?: boolean;
  [ConsentDisplayKeys.ANALYTICS]?: boolean;
  [ConsentDisplayKeys.PREFERENCES]?: boolean;
  [ConsentDisplayKeys.SALE_OF_DATA]?: boolean;
  [ConsentDisplayKeys.EMAIL]?: String;
  [StorefrontApiConsentMetadata.HEADLESS_STOREFRONT]?: boolean;
  [StorefrontApiConsentMetadata.ROOT_DOMAIN]?: string;
  [StorefrontApiConsentMetadata.CHECKOUT_ROOT_DOMAIN]?: string;
  [StorefrontApiConsentMetadata.STOREFRONT_ROOT_DOMAIN]?: string;
  [StorefrontApiConsentMetadata.STOREFRONT_ACCESS_TOKEN]?: string;
  [StorefrontApiConsentMetadata.IS_EXTENSION_TOKEN]?: boolean;
  [StorefrontApiConsentMetadata.METAFIELDS]?: Metafield[];
}
export function setTrackingConsent(
  consent: boolean | SetGranularConsentParameter,
  callback?: (err?: null | {}, success?: {}) => {} | void,
): setTrackingConsentPromise 

Do not use the shorthard (setTrackingConsent(false, () => console.log("everything declined")) as that is deprecated, it's legacy from where consent was binary and not per purpose.

@juanpprieto juanpprieto marked this pull request as ready for review May 14, 2024 17:01

This comment has been minimized.

console.error(
`[h2:error:useCustomerPrivacy] It looks like you passed a private access token, make sure to use the public token`,
);
console;
Copy link
Contributor

@wizardlyhel wizardlyhel May 14, 2024

Choose a reason for hiding this comment

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

Is this Line 159: console; an accidental commit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ohhh no, merged too early. will open another PR

@juanpprieto juanpprieto merged commit 7def3e9 into main May 14, 2024
13 checks passed
@juanpprieto juanpprieto deleted the juanpprieto/fix-analytics branch May 14, 2024 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants