Skip to content

Commit c05a0f7

Browse files
committed
add docs for customer privacy API
1 parent 929fbe5 commit c05a0f7

File tree

9 files changed

+675
-0
lines changed

9 files changed

+675
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import type {ReferenceEntityTemplateSchema} from '@shopify/generate-docs';
2+
import {
3+
CUSTOMER_ACCOUNT_STANDARD_API_DEFINITION,
4+
REQUIRES_PROTECTED_CUSTOMER_DATA,
5+
} from '../helper.docs';
6+
7+
const data: ReferenceEntityTemplateSchema = {
8+
name: 'Customer Privacy',
9+
description:
10+
"The API for interacting with a customer's privacy consent. It is similar to the [Customer Privacy API in storefront](/docs/api/customer-privacy).",
11+
isVisualComponent: false,
12+
requires: REQUIRES_PROTECTED_CUSTOMER_DATA,
13+
category: 'APIs',
14+
type: 'API',
15+
definitions: [
16+
{
17+
title: CUSTOMER_ACCOUNT_STANDARD_API_DEFINITION.title,
18+
description: CUSTOMER_ACCOUNT_STANDARD_API_DEFINITION.description,
19+
type: 'Docs_Standard_CustomerPrivacyApi',
20+
},
21+
{
22+
title: 'useCustomerPrivacy',
23+
description:
24+
'Returns the current customer privacy settings and metadata and re-renders your component if the customer privacy settings change.',
25+
type: 'UseCustomerPrivacyGeneratedType',
26+
},
27+
],
28+
defaultExample: {
29+
codeblock: {
30+
title: 'Read Customer Privacy',
31+
tabs: [
32+
{
33+
code: '../examples/apis/customer-privacy.example.tsx',
34+
language: 'jsx',
35+
title: 'React',
36+
},
37+
{
38+
code: '../examples/apis/customer-privacy.example.ts',
39+
language: 'js',
40+
title: 'JavaScript',
41+
},
42+
],
43+
},
44+
},
45+
examples: {
46+
description: '',
47+
examples: [
48+
{
49+
description: `
50+
You can apply changes to customer consent by using the \`applyTrackingConsentChanges\` API.
51+
52+
> Note: Requires the [\`customer_privacy\` capability](/docs/api/customer-account-ui-extensions/configuration#collect-buyer-consent) to be set to \`true\`.`,
53+
codeblock: {
54+
title: 'Use a Sheet to manage customer privacy consent',
55+
tabs: [
56+
{
57+
code: '../examples/apis/sheet-consent-banner-with-form.example.tsx',
58+
language: 'jsx',
59+
title: 'React',
60+
},
61+
{
62+
code: '../examples/apis/sheet-consent-banner-with-form.example.ts',
63+
language: 'js',
64+
title: 'JavaScript',
65+
},
66+
],
67+
},
68+
},
69+
],
70+
},
71+
related: [],
72+
};
73+
74+
export default data;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import {extension} from '@shopify/ui-extensions/customer-account';
2+
3+
// 1. Choose an extension target
4+
export default extension(
5+
'customer-account.order-status.block.render',
6+
(root, {customerPrivacy}) => {
7+
const {
8+
visitorConsent: {
9+
analytics,
10+
marketing,
11+
preferences,
12+
saleOfData,
13+
},
14+
} = customerPrivacy.current;
15+
16+
// 2. Use consent values
17+
console.log('initialValues');
18+
console.log('analytics', analytics);
19+
console.log('marketing', marketing);
20+
console.log('preferences', preferences);
21+
console.log('saleOfData', saleOfData);
22+
23+
// 3. Update component state when customerPrivacy changes
24+
customerPrivacy.subscribe((value) => {
25+
if (!value) {
26+
return;
27+
}
28+
29+
const {
30+
visitorConsent: {
31+
analytics,
32+
marketing,
33+
preferences,
34+
saleOfData,
35+
},
36+
} = value;
37+
38+
console.log('updatedValues');
39+
console.log('analytics', analytics);
40+
console.log('marketing', marketing);
41+
console.log('preferences', preferences);
42+
console.log('saleOfData', saleOfData);
43+
});
44+
},
45+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import {useState} from 'react';
2+
import {
3+
reactExtension,
4+
useCustomerPrivacy,
5+
} from '@shopify/ui-extensions-react/customer-account';
6+
7+
// 1. Choose an extension target
8+
export default reactExtension(
9+
'customer-account.order-status.block.render',
10+
() => <Extension />,
11+
);
12+
13+
function Extension() {
14+
// 2. Subscribe to customer privacy consent values
15+
const {
16+
visitorConsent: {
17+
analytics,
18+
marketing,
19+
preferences,
20+
saleOfData,
21+
},
22+
} = useCustomerPrivacy();
23+
24+
// 3. Use consent values
25+
console.log('analytics', analytics);
26+
console.log('marketing', marketing);
27+
console.log('preferences', preferences);
28+
console.log('saleOfData', saleOfData);
29+
}

0 commit comments

Comments
 (0)