docusaurus-plugin-generate-schema-docs 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/README.md +28 -0
  2. package/__tests__/ExampleDataLayer.test.js +13 -0
  3. package/__tests__/__fixtures__/static/schemas/anchor/parent-event-anchor.json +29 -0
  4. package/__tests__/__snapshots__/generateEventDocs.anchor.test.js.snap +79 -0
  5. package/__tests__/__snapshots__/generateEventDocs.nested.test.js.snap +8 -2
  6. package/__tests__/__snapshots__/generateEventDocs.test.js.snap +20 -5
  7. package/__tests__/__snapshots__/generateEventDocs.versioned.test.js.snap +8 -2
  8. package/__tests__/components/PropertiesTable.test.js +34 -1
  9. package/__tests__/components/PropertyRow.test.js +5 -5
  10. package/__tests__/generateEventDocs.anchor.test.js +71 -0
  11. package/__tests__/helpers/example-helper.test.js +71 -0
  12. package/__tests__/helpers/getConstraints.test.js +72 -27
  13. package/__tests__/helpers/schemaToTableData.test.js +28 -33
  14. package/components/ExampleDataLayer.js +14 -5
  15. package/components/PropertiesTable.js +22 -7
  16. package/components/PropertiesTable.module.css +27 -0
  17. package/components/PropertyRow.js +24 -25
  18. package/components/SchemaRows.css +6 -0
  19. package/components/SchemaViewer.js +2 -2
  20. package/components/WordWrapButton.js +31 -0
  21. package/components/wordWrapButton.module.css +8 -0
  22. package/generateEventDocs.js +2 -1
  23. package/helpers/buildExampleFromSchema.js +6 -4
  24. package/helpers/example-helper.js +41 -0
  25. package/helpers/getConstraints.js +1 -0
  26. package/helpers/schema-doc-template.js +8 -1
  27. package/helpers/schema-processing.js +2 -0
  28. package/helpers/schemaToTableData.js +4 -3
  29. package/index.js +18 -9
  30. package/package.json +1 -1
  31. package/validateSchemas.js +2 -0
package/README.md CHANGED
@@ -29,6 +29,7 @@ npm install --save docusaurus-plugin-generate-schema-docs
29
29
  'docusaurus-plugin-generate-schema-docs',
30
30
  {
31
31
  // Options if any
32
+ dataLayerName: 'customDataLayer',
32
33
  },
33
34
  ],
34
35
  ],
@@ -36,6 +37,8 @@ npm install --save docusaurus-plugin-generate-schema-docs
36
37
  };
37
38
  ```
38
39
 
40
+ The `dataLayerName` option allows you to customize the name of the data layer variable in the generated examples. If not provided, it defaults to `dataLayer`.
41
+
39
42
  2. Place your JSON schemas in the `schemas` directory at the root of your project.
40
43
 
41
44
  ## CLI Commands
@@ -76,6 +79,31 @@ The plugin reads your JSON schemas, dereferences any `$ref` properties, and merg
76
79
 
77
80
  The validation script builds an example from each schema and validates it against the schema itself, ensuring your examples are always in sync with your schemas.
78
81
 
82
+ ## Schema Composition (anyOf, oneOf)
83
+
84
+ The plugin has special handling for `anyOf` and `oneOf` keywords in your JSON schemas.
85
+
86
+ ### `anyOf`
87
+
88
+ When `anyOf` is used, the plugin will render a dropdown menu in the documentation that allows users to switch between the different sub-schemas. This is useful for representing properties that can have multiple different structures.
89
+
90
+ ### `oneOf`
91
+
92
+ Similar to `anyOf`, `oneOf` will also render a dropdown menu.
93
+
94
+ #### `oneOf` at the Root Level
95
+
96
+ A special behavior is triggered when `oneOf` is used at the root level of a schema file. If a schema's top-level definition is a `oneOf` array, the plugin will generate a directory structure that reflects the choices.
97
+
98
+ For example, given a schema `my-event.json` with a `oneOf` at the root, where each item in the `oneOf` array is a reference to another schema file (e.g., `option-a.json`, `option-b.json`), the plugin will generate the following structure:
99
+
100
+ - `docs/events/my-event/`: A directory for the parent schema.
101
+ - `docs/events/my-event/index.mdx`: An index page for `my-event`.
102
+ - `docs/events/my-event/option-a.mdx`: A page for the first option.
103
+ - `docs/events/my-event/option-b.mdx`: A page for the second option.
104
+
105
+ This creates a nested navigation structure in Docusaurus, which is useful for grouping related events or entities under a single menu item.
106
+
79
107
  ## Versioning
80
108
 
81
109
  This plugin supports documentation and schema versioning, integrated with Docusaurus's native versioning system.
@@ -68,6 +68,19 @@ describe('ExampleDataLayer', () => {
68
68
  // Let snapshot testing verify the complex content of each tab
69
69
  expect(container).toMatchSnapshot();
70
70
  });
71
+
72
+ it('should use the provided dataLayerName', () => {
73
+ const schema = {
74
+ type: 'object',
75
+ properties: {
76
+ event: { type: 'string', examples: ['test_event'] },
77
+ },
78
+ };
79
+ const { getByText } = render(
80
+ <ExampleDataLayer schema={schema} dataLayerName="customDataLayer" />,
81
+ );
82
+ expect(getByText(/window.customDataLayer.push/)).toBeInTheDocument();
83
+ });
71
84
  });
72
85
 
73
86
  describe('findClearableProperties', () => {
@@ -0,0 +1,29 @@
1
+ {
2
+ "$id": "https://example.com/parent-event-anchor.json",
3
+ "title": "Parent Event Anchor",
4
+ "description": "This is a parent event with oneOf.",
5
+ "type": "object",
6
+ "oneOf": [
7
+ {
8
+ "title": "Child Event Anchor",
9
+ "description": "This is a child event with an anchor.",
10
+ "$anchor": "child-event-with-anchor",
11
+ "type": "object",
12
+ "properties": {
13
+ "property_a": {
14
+ "type": "string"
15
+ }
16
+ }
17
+ },
18
+ {
19
+ "title": "Child Event Title",
20
+ "description": "This is a child event with only a title.",
21
+ "type": "object",
22
+ "properties": {
23
+ "property_b": {
24
+ "type": "string"
25
+ }
26
+ }
27
+ }
28
+ ]
29
+ }
@@ -0,0 +1,79 @@
1
+ // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2
+
3
+ exports[`generateEventDocs (oneOf with $anchor) should generate documentation using $anchor for slug 1`] = `
4
+ "---
5
+ title: Parent Event Anchor
6
+ description: "This is a parent event with oneOf."
7
+ ---
8
+ import SchemaJsonViewer from '@theme/SchemaJsonViewer';
9
+
10
+ # Parent Event Anchor
11
+
12
+ This is a parent event with oneOf.
13
+
14
+ Please select one of the following options:
15
+
16
+ - [Child Event Anchor](./child-event-with-anchor)
17
+ - [Child Event Title](./child-event-title)
18
+
19
+ <SchemaJsonViewer schema={{"$id":"https://example.com/parent-event-anchor.json","title":"Parent Event Anchor","description":"This is a parent event with oneOf.","type":"object","oneOf":[{"title":"Child Event Anchor","description":"This is a child event with an anchor.","$anchor":"child-event-with-anchor","type":"object","properties":{"property_a":{"type":"string"}}},{"title":"Child Event Title","description":"This is a child event with only a title.","type":"object","properties":{"property_b":{"type":"string"}}}]}} />
20
+ "
21
+ `;
22
+
23
+ exports[`generateEventDocs (oneOf with $anchor) should generate documentation using $anchor for slug 2`] = `
24
+ "---
25
+ title: Child Event Anchor
26
+ description: "This is a child event with an anchor."
27
+ sidebar_label: Child Event Anchor
28
+ custom_edit_url: https://github.com/test-org/test-project/edit/main/__fixtures_anchor__/docs/parent-event-anchor/01-child-event-with-anchor.json
29
+ ---
30
+
31
+ import SchemaViewer from '@theme/SchemaViewer';
32
+ import SchemaJsonViewer from '@theme/SchemaJsonViewer';
33
+
34
+
35
+
36
+ # Child Event Anchor
37
+
38
+ This is a child event with an anchor.
39
+
40
+
41
+
42
+ <SchemaViewer
43
+ schema={{"$id":"https://example.com/parent-event-anchor.json#child-event-with-anchor","title":"Child Event Anchor","description":"This is a child event with an anchor.","type":"object","$anchor":"child-event-with-anchor","properties":{"property_a":{"type":"string"}}}}
44
+
45
+ />
46
+ <SchemaJsonViewer schema={{"$id":"https://example.com/parent-event-anchor.json#child-event-with-anchor","title":"Child Event Anchor","description":"This is a child event with an anchor.","type":"object","$anchor":"child-event-with-anchor","properties":{"property_a":{"type":"string"}}}} />
47
+
48
+
49
+ "
50
+ `;
51
+
52
+ exports[`generateEventDocs (oneOf with $anchor) should generate documentation using $anchor for slug 3`] = `
53
+ "---
54
+ title: Child Event Title
55
+ description: "This is a child event with only a title."
56
+ sidebar_label: Child Event Title
57
+ custom_edit_url: https://github.com/test-org/test-project/edit/main/__fixtures_anchor__/docs/parent-event-anchor/02-child-event-title.json
58
+ ---
59
+
60
+ import SchemaViewer from '@theme/SchemaViewer';
61
+ import SchemaJsonViewer from '@theme/SchemaJsonViewer';
62
+
63
+
64
+
65
+ # Child Event Title
66
+
67
+ This is a child event with only a title.
68
+
69
+
70
+
71
+ <SchemaViewer
72
+ schema={{"$id":"https://example.com/parent-event-anchor.json#child-event-title","title":"Child Event Title","description":"This is a child event with only a title.","type":"object","properties":{"property_b":{"type":"string"}}}}
73
+
74
+ />
75
+ <SchemaJsonViewer schema={{"$id":"https://example.com/parent-event-anchor.json#child-event-title","title":"Child Event Title","description":"This is a child event with only a title.","type":"object","properties":{"property_b":{"type":"string"}}}} />
76
+
77
+
78
+ "
79
+ `;
@@ -58,7 +58,10 @@ undefined
58
58
 
59
59
 
60
60
 
61
- <SchemaViewer schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://example.com/schemas/nested/grandchild-a.json","title":"Grandchild A","type":"object","properties":{"prop_a":{"type":"string"}}}} />
61
+ <SchemaViewer
62
+ schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://example.com/schemas/nested/grandchild-a.json","title":"Grandchild A","type":"object","properties":{"prop_a":{"type":"string"}}}}
63
+
64
+ />
62
65
  <SchemaJsonViewer schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://example.com/schemas/nested/grandchild-a.json","title":"Grandchild A","type":"object","properties":{"prop_a":{"type":"string"}}}} />
63
66
 
64
67
 
@@ -84,7 +87,10 @@ undefined
84
87
 
85
88
 
86
89
 
87
- <SchemaViewer schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://example.com/schemas/nested/grandchild-b.json","title":"Grandchild B","type":"object","properties":{"prop_b":{"type":"string"}}}} />
90
+ <SchemaViewer
91
+ schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://example.com/schemas/nested/grandchild-b.json","title":"Grandchild B","type":"object","properties":{"prop_b":{"type":"string"}}}}
92
+
93
+ />
88
94
  <SchemaJsonViewer schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://example.com/schemas/nested/grandchild-b.json","title":"Grandchild B","type":"object","properties":{"prop_b":{"type":"string"}}}} />
89
95
 
90
96
 
@@ -19,7 +19,10 @@ An add_to_cart event fires when a user adds one or more items to their shopping
19
19
 
20
20
 
21
21
 
22
- <SchemaViewer schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/add-to-cart-event.json","title":"Add to Cart Event","description":"An add_to_cart event fires when a user adds one or more items to their shopping cart. Based on Google Analytics 4 ecommerce event specifications.","type":"object","required":["event"],"$defs":{"strictObject":{"type":"object","propertyNames":{"maxLength":40,"pattern":"^[a-z0-9_]+$"},"additionalProperties":{"anyOf":[{"$ref":"#/allOf/0/$defs/strictObject"},{"type":"array","items":{"$ref":"#/allOf/0/$defs/strictObject"}},{"not":{"type":"object"}}]}}},"$ref":"#/allOf/0/$defs/strictObject","properties":{"event":{"type":"string","const":"add_to_cart","description":"The name of the event indicating a add_to_cart has occurred."},"ecommerce":{"type":"object","description":"Ecommerce related data for the purchase event.","required":["currency","items"],"x-gtm-clear":true,"properties":{"value":{"type":"number","description":"The monetary value of the event. Set value to the sum of (price * quantity) for all items in items.","examples":[30.03,99.99,45.5]},"currency":{"type":"string","description":"The currency of the items in ISO 4217 three-letter format. Required when value is set.","examples":["USD","EUR","GBP"]},"items":{"type":"array","description":"The products added to the cart.","minItems":1,"items":{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/components/product.json","title":"A Product","description":"A product object representing an item for use within a purchase event, based on Google Analytics 4 ecommerce event specifications.","type":"object","required":[],"properties":{"item_id":{"type":"string","description":"The ID of the item. Either item_id or item_name is required.","examples":["SKU_12345","PROD_98765"]},"item_name":{"type":"string","description":"The name of the item. Either item_id or item_name is required.","examples":["Stan and Friends Tee","Blue Running Shoes"]},"affiliation":{"type":"string","description":"A product affiliation to indicate a supplier or store. Note: affiliation is only available at the item level.","examples":["Google Merchandise Store","Nike Store"]},"coupon":{"type":"string","description":"The coupon name/code associated with the item. Coupon parameters at event and item levels are independent.","examples":["SUMMER_FUN","WELCOME20","SAVE10"]},"discount":{"type":"number","description":"The monetary value of the discount per unit applied to the item.","examples":[2.22,5,10.5]},"index":{"type":"number","description":"The index or position of the item in a list.","examples":[0,1,2]},"item_brand":{"type":"string","description":"The brand of the item.","examples":["Google","Nike","Adidas"]},"item_category":{"type":"string","description":"The category of the item. If used as part of a category hierarchy or taxonomy, this is the first category.","examples":["Apparel","Footwear","Electronics"]},"item_category2":{"type":"string","description":"The second category hierarchy or additional taxonomy of the item.","examples":["Adult","Women","Men"]},"item_category3":{"type":"string","description":"The third category hierarchy or additional taxonomy of the item.","examples":["Shirts","Shoes","Boots"]},"item_category4":{"type":"string","description":"The fourth category hierarchy or additional taxonomy of the item.","examples":["Crew","Running","Casual"]},"item_category5":{"type":"string","description":"The fifth category hierarchy or additional taxonomy of the item.","examples":["Short sleeve","Long distance","Lightweight"]},"item_list_id":{"type":"string","description":"The ID of the list in which the item was presented to the user. If set, item_list_id at the event level is ignored. If not set, item_list_id at the event level is used if available.","examples":["related_products","search_results","recommendations"]},"item_list_name":{"type":"string","description":"The name of the list in which the item was presented to the user. If set, item_list_name at the event level is ignored. If not set, item_list_name at the event level is used if available.","examples":["Related Products","Search Results","Recommended Items"]},"item_variant":{"type":"string","description":"The item variant or unique code or description for additional item details/options.","examples":["green","Blue Size 10","M-Black"]},"location_id":{"type":"string","description":"The physical location associated with the item, such as the location of a brick-and-mortar store. It is recommended to use the Google Place ID that corresponds to the associated item. A custom location ID can also be used. Note: location_id is only available at the item level.","examples":["ChIJIQBpAG2ahYAR_6128GcTUEo","store_123","location_sf"]},"price":{"type":"number","description":"The price of the item in the specified currency unit. If a discount is applied to the item, set price to the reduced per-unit price and provide the per-unit price discount in the discount parameter.","examples":[10.01,21.01,89.99]},"quantity":{"type":"number","description":"The item quantity. If not set, quantity is set to 1.","examples":[1,2,3]},"promotion_id":{"type":"string","description":"The ID of the promotion associated with the item.","examples":["P_12345","PROMO_001"]},"promotion_name":{"type":"string","description":"The name of the promotion associated with the item.","examples":["Summer Sale","Black Friday","Flash Deal"]},"creative_name":{"type":"string","description":"The name of the promotion creative.","examples":["summer_banner2","holiday_email_v1"]},"creative_slot":{"type":"string","description":"The name of the creative slot associated with the item.","examples":["featured_app_1","top_banner","sidebar"]},"google_business_vertical":{"type":"string","description":"The business vertical for the item (e.g., 'retail').","examples":["retail","ecommerce"]}}}}}},"user_data":{"type":"object","description":"User related data.","x-gtm-clear":true}}}} />
22
+ <SchemaViewer
23
+ schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/add-to-cart-event.json","title":"Add to Cart Event","description":"An add_to_cart event fires when a user adds one or more items to their shopping cart. Based on Google Analytics 4 ecommerce event specifications.","type":"object","required":["event"],"$defs":{"strictObject":{"type":"object","propertyNames":{"maxLength":40,"pattern":"^[a-z0-9_]+$"},"additionalProperties":{"anyOf":[{"$ref":"#/allOf/0/$defs/strictObject"},{"type":"array","items":{"$ref":"#/allOf/0/$defs/strictObject"}},{"not":{"type":"object"}}]}}},"$ref":"#/allOf/0/$defs/strictObject","properties":{"event":{"type":"string","const":"add_to_cart","description":"The name of the event indicating a add_to_cart has occurred."},"ecommerce":{"type":"object","description":"Ecommerce related data for the purchase event.","required":["currency","items"],"x-gtm-clear":true,"properties":{"value":{"type":"number","description":"The monetary value of the event. Set value to the sum of (price * quantity) for all items in items.","examples":[30.03,99.99,45.5]},"currency":{"type":"string","description":"The currency of the items in ISO 4217 three-letter format. Required when value is set.","examples":["USD","EUR","GBP"]},"items":{"type":"array","description":"The products added to the cart.","minItems":1,"items":{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/components/product.json","title":"A Product","description":"A product object representing an item for use within a purchase event, based on Google Analytics 4 ecommerce event specifications.","type":"object","required":[],"properties":{"item_id":{"type":"string","description":"The ID of the item. Either item_id or item_name is required.","examples":["SKU_12345","PROD_98765"]},"item_name":{"type":"string","description":"The name of the item. Either item_id or item_name is required.","examples":["Stan and Friends Tee","Blue Running Shoes"]},"affiliation":{"type":"string","description":"A product affiliation to indicate a supplier or store. Note: affiliation is only available at the item level.","examples":["Google Merchandise Store","Nike Store"]},"coupon":{"type":"string","description":"The coupon name/code associated with the item. Coupon parameters at event and item levels are independent.","examples":["SUMMER_FUN","WELCOME20","SAVE10"]},"discount":{"type":"number","description":"The monetary value of the discount per unit applied to the item.","examples":[2.22,5,10.5]},"index":{"type":"number","description":"The index or position of the item in a list.","examples":[0,1,2]},"item_brand":{"type":"string","description":"The brand of the item.","examples":["Google","Nike","Adidas"]},"item_category":{"type":"string","description":"The category of the item. If used as part of a category hierarchy or taxonomy, this is the first category.","examples":["Apparel","Footwear","Electronics"]},"item_category2":{"type":"string","description":"The second category hierarchy or additional taxonomy of the item.","examples":["Adult","Women","Men"]},"item_category3":{"type":"string","description":"The third category hierarchy or additional taxonomy of the item.","examples":["Shirts","Shoes","Boots"]},"item_category4":{"type":"string","description":"The fourth category hierarchy or additional taxonomy of the item.","examples":["Crew","Running","Casual"]},"item_category5":{"type":"string","description":"The fifth category hierarchy or additional taxonomy of the item.","examples":["Short sleeve","Long distance","Lightweight"]},"item_list_id":{"type":"string","description":"The ID of the list in which the item was presented to the user. If set, item_list_id at the event level is ignored. If not set, item_list_id at the event level is used if available.","examples":["related_products","search_results","recommendations"]},"item_list_name":{"type":"string","description":"The name of the list in which the item was presented to the user. If set, item_list_name at the event level is ignored. If not set, item_list_name at the event level is used if available.","examples":["Related Products","Search Results","Recommended Items"]},"item_variant":{"type":"string","description":"The item variant or unique code or description for additional item details/options.","examples":["green","Blue Size 10","M-Black"]},"location_id":{"type":"string","description":"The physical location associated with the item, such as the location of a brick-and-mortar store. It is recommended to use the Google Place ID that corresponds to the associated item. A custom location ID can also be used. Note: location_id is only available at the item level.","examples":["ChIJIQBpAG2ahYAR_6128GcTUEo","store_123","location_sf"]},"price":{"type":"number","description":"The price of the item in the specified currency unit. If a discount is applied to the item, set price to the reduced per-unit price and provide the per-unit price discount in the discount parameter.","examples":[10.01,21.01,89.99]},"quantity":{"type":"number","description":"The item quantity. If not set, quantity is set to 1.","examples":[1,2,3]},"promotion_id":{"type":"string","description":"The ID of the promotion associated with the item.","examples":["P_12345","PROMO_001"]},"promotion_name":{"type":"string","description":"The name of the promotion associated with the item.","examples":["Summer Sale","Black Friday","Flash Deal"]},"creative_name":{"type":"string","description":"The name of the promotion creative.","examples":["summer_banner2","holiday_email_v1"]},"creative_slot":{"type":"string","description":"The name of the creative slot associated with the item.","examples":["featured_app_1","top_banner","sidebar"]},"google_business_vertical":{"type":"string","description":"The business vertical for the item (e.g., 'retail').","examples":["retail","ecommerce"]}}}}}},"user_data":{"type":"object","description":"User related data.","x-gtm-clear":true}}}}
24
+
25
+ />
23
26
  <SchemaJsonViewer schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/add-to-cart-event.json","title":"Add to Cart Event","description":"An add_to_cart event fires when a user adds one or more items to their shopping cart. Based on Google Analytics 4 ecommerce event specifications.","type":"object","allOf":[{"$ref":"./components/dataLayer.json"}],"properties":{"event":{"type":"string","const":"add_to_cart","description":"The name of the event indicating a add_to_cart has occurred."},"ecommerce":{"type":"object","description":"Ecommerce related data for the purchase event.","properties":{"value":{"type":"number","description":"The monetary value of the event. Set value to the sum of (price * quantity) for all items in items.","examples":[30.03,99.99,45.5]},"currency":{"type":"string","description":"The currency of the items in ISO 4217 three-letter format. Required when value is set.","examples":["USD","EUR","GBP"]},"items":{"type":"array","description":"The products added to the cart.","minItems":1,"items":{"$ref":"./components/product.json"}}},"required":["currency","items"]}}}} />
24
27
 
25
28
 
@@ -45,7 +48,10 @@ An example event that uses oneOf and anyOf.
45
48
 
46
49
 
47
50
 
48
- <SchemaViewer schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/1.2.0/choice-event.json","title":"Choice Event","description":"An example event that uses oneOf and anyOf.","type":"object","required":["event","user_id","payment_method"],"properties":{"event":{"type":"string","const":"one_of_event"},"user_id":{"description":"The user's ID.","oneOf":[{"type":"string","title":"User ID as String","description":"The user's ID as a string.","examples":["user-123"]},{"type":"integer","title":"User ID as Integer","description":"The user's ID as an integer.","examples":[123]}]},"payment_method":{"description":"The user's payment method.","type":"object","anyOf":[{"title":"Credit Card","properties":{"payment_type":{"type":"string","enum":["credit_card","debit_card"],"examples":["credit_card"]},"card_number":{"type":"string","examples":["1234-5678-9012-3456"]},"expiry_date":{"type":"string","examples":["12/26"]}},"required":["card_number","expiry_date"]},{"title":"PayPal","type":"object","properties":{"payment_type":{"type":"string","const":"paypal"},"email":{"type":"string","format":"email","examples":["test@example.com"]}},"required":["email"]}]}}}} />
51
+ <SchemaViewer
52
+ schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/1.2.0/choice-event.json","title":"Choice Event","description":"An example event that uses oneOf and anyOf.","type":"object","required":["event","user_id","payment_method"],"properties":{"event":{"type":"string","const":"one_of_event"},"user_id":{"description":"The user's ID.","oneOf":[{"type":"string","title":"User ID as String","description":"The user's ID as a string.","examples":["user-123"]},{"type":"integer","title":"User ID as Integer","description":"The user's ID as an integer.","examples":[123]}]},"payment_method":{"description":"The user's payment method.","type":"object","anyOf":[{"title":"Credit Card","properties":{"payment_type":{"type":"string","enum":["credit_card","debit_card"],"examples":["credit_card"]},"card_number":{"type":"string","examples":["1234-5678-9012-3456"]},"expiry_date":{"type":"string","examples":["12/26"]}},"required":["card_number","expiry_date"]},{"title":"PayPal","type":"object","properties":{"payment_type":{"type":"string","const":"paypal"},"email":{"type":"string","format":"email","examples":["test@example.com"]}},"required":["email"]}]}}}}
53
+
54
+ />
49
55
  <SchemaJsonViewer schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/1.2.0/choice-event.json","title":"Choice Event","description":"An example event that uses oneOf and anyOf.","type":"object","properties":{"event":{"type":"string","const":"one_of_event"},"user_id":{"description":"The user's ID.","oneOf":[{"type":"string","title":"User ID as String","description":"The user's ID as a string.","examples":["user-123"]},{"type":"integer","title":"User ID as Integer","description":"The user's ID as an integer.","examples":[123]}]},"payment_method":{"description":"The user's payment method.","type":"object","anyOf":[{"title":"Credit Card","properties":{"payment_type":{"type":"string","enum":["credit_card","debit_card"],"examples":["credit_card"]},"card_number":{"type":"string","examples":["1234-5678-9012-3456"]},"expiry_date":{"type":"string","examples":["12/26"]}},"required":["card_number","expiry_date"]},{"title":"PayPal","type":"object","properties":{"payment_type":{"type":"string","const":"paypal"},"email":{"type":"string","format":"email","examples":["test@example.com"]}},"required":["email"]}]}},"required":["event","user_id","payment_method"]}} />
50
56
 
51
57
 
@@ -71,7 +77,10 @@ An example event that has anyOf at the root level.
71
77
 
72
78
 
73
79
 
74
- <SchemaViewer schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/1.2.0/root-any-of-event.json","title":"Root AnyOf Event","description":"An example event that has anyOf at the root level.","type":"object","anyOf":[{"title":"Has Param C","properties":{"param_c":{"type":"string","examples":["example_c"],"description":"This is the description for Param C."}}},{"title":"Has Param D","properties":{"param_d":{"type":"boolean","examples":[true]}}}],"properties":{"event":{"type":"string","const":"any_of_event"}}}} />
80
+ <SchemaViewer
81
+ schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/1.2.0/root-any-of-event.json","title":"Root AnyOf Event","description":"An example event that has anyOf at the root level.","type":"object","anyOf":[{"title":"Has Param C","properties":{"param_c":{"type":"string","examples":["example_c"],"description":"This is the description for Param C."}}},{"title":"Has Param D","properties":{"param_d":{"type":"boolean","examples":[true]}}}],"properties":{"event":{"type":"string","const":"any_of_event"}}}}
82
+
83
+ />
75
84
  <SchemaJsonViewer schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/1.2.0/root-any-of-event.json","title":"Root AnyOf Event","description":"An example event that has anyOf at the root level.","type":"object","properties":{"event":{"type":"string","const":"any_of_event"}},"anyOf":[{"title":"Has Param C","properties":{"param_c":{"type":"string","examples":["example_c"],"description":"This is the description for Param C."}}},{"title":"Has Param D","properties":{"param_d":{"type":"boolean","examples":[true]}}}]}} />
76
85
 
77
86
 
@@ -117,7 +126,10 @@ An example event that has oneOf at the root level.
117
126
 
118
127
 
119
128
 
120
- <SchemaViewer schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://example.com/root-choice-event.schema.json#option-a","title":"Option A","description":"An example event that has oneOf at the root level.","type":"object","properties":{"event":{"type":"string","const":"option_a"},"param_a":{"type":"string","examples":["example_a"]}}}} />
129
+ <SchemaViewer
130
+ schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://example.com/root-choice-event.schema.json#option-a","title":"Option A","description":"An example event that has oneOf at the root level.","type":"object","properties":{"event":{"type":"string","const":"option_a"},"param_a":{"type":"string","examples":["example_a"]}}}}
131
+
132
+ />
121
133
  <SchemaJsonViewer schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://example.com/root-choice-event.schema.json#option-a","title":"Option A","description":"An example event that has oneOf at the root level.","type":"object","properties":{"event":{"type":"string","const":"option_a"},"param_a":{"type":"string","examples":["example_a"]}}}} />
122
134
 
123
135
 
@@ -143,7 +155,10 @@ An example event that has oneOf at the root level.
143
155
 
144
156
 
145
157
 
146
- <SchemaViewer schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://example.com/root-choice-event.schema.json#option-b","title":"Option B","description":"An example event that has oneOf at the root level.","type":"object","properties":{"event":{"type":"string","const":"option_b"},"param_b":{"type":"integer","examples":[123]}}}} />
158
+ <SchemaViewer
159
+ schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://example.com/root-choice-event.schema.json#option-b","title":"Option B","description":"An example event that has oneOf at the root level.","type":"object","properties":{"event":{"type":"string","const":"option_b"},"param_b":{"type":"integer","examples":[123]}}}}
160
+
161
+ />
147
162
  <SchemaJsonViewer schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://example.com/root-choice-event.schema.json#option-b","title":"Option B","description":"An example event that has oneOf at the root level.","type":"object","properties":{"event":{"type":"string","const":"option_b"},"param_b":{"type":"integer","examples":[123]}}}} />
148
163
 
149
164
 
@@ -19,7 +19,10 @@ An add_to_cart event fires when a user adds one or more items to their shopping
19
19
 
20
20
 
21
21
 
22
- <SchemaViewer schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/add-to-cart-event.json","title":"Add to Cart Event","description":"An add_to_cart event fires when a user adds one or more items to their shopping cart. Based on Google Analytics 4 ecommerce event specifications.","type":"object","required":["event"],"$defs":{"strictObject":{"type":"object","propertyNames":{"maxLength":40,"pattern":"^[a-z0-9_]+$"},"additionalProperties":{"anyOf":[{"$ref":"#/allOf/0/$defs/strictObject"},{"type":"array","items":{"$ref":"#/allOf/0/$defs/strictObject"}},{"not":{"type":"object"}}]}}},"$ref":"#/allOf/0/$defs/strictObject","properties":{"event":{"type":"string","const":"add_to_cart","description":"The name of the event indicating a add_to_cart has occurred."},"ecommerce":{"type":"object","description":"Ecommerce related data for the purchase event.","required":["currency","items"],"x-gtm-clear":true,"properties":{"value":{"type":"number","description":"The monetary value of the event. Set value to the sum of (price * quantity) for all items in items.","examples":[30.03,99.99,45.5]},"currency":{"type":"string","description":"The currency of the items in ISO 4217 three-letter format. Required when value is set.","examples":["USD","EUR","GBP"]},"items":{"type":"array","description":"The products added to the cart.","minItems":1,"items":{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/components/product.json","title":"A Product","description":"A product object representing an item for use within a purchase event, based on Google Analytics 4 ecommerce event specifications.","type":"object","required":[],"properties":{"item_id":{"type":"string","description":"The ID of the item. Either item_id or item_name is required.","examples":["SKU_12345","PROD_98765"]},"item_name":{"type":"string","description":"The name of the item. Either item_id or item_name is required.","examples":["Stan and Friends Tee","Blue Running Shoes"]},"affiliation":{"type":"string","description":"A product affiliation to indicate a supplier or store. Note: affiliation is only available at the item level.","examples":["Google Merchandise Store","Nike Store"]},"coupon":{"type":"string","description":"The coupon name/code associated with the item. Coupon parameters at event and item levels are independent.","examples":["SUMMER_FUN","WELCOME20","SAVE10"]},"discount":{"type":"number","description":"The monetary value of the discount per unit applied to the item.","examples":[2.22,5,10.5]},"index":{"type":"number","description":"The index or position of the item in a list.","examples":[0,1,2]},"item_brand":{"type":"string","description":"The brand of the item.","examples":["Google","Nike","Adidas"]},"item_category":{"type":"string","description":"The category of the item. If used as part of a category hierarchy or taxonomy, this is the first category.","examples":["Apparel","Footwear","Electronics"]},"item_category2":{"type":"string","description":"The second category hierarchy or additional taxonomy of the item.","examples":["Adult","Women","Men"]},"item_category3":{"type":"string","description":"The third category hierarchy or additional taxonomy of the item.","examples":["Shirts","Shoes","Boots"]},"item_category4":{"type":"string","description":"The fourth category hierarchy or additional taxonomy of the item.","examples":["Crew","Running","Casual"]},"item_category5":{"type":"string","description":"The fifth category hierarchy or additional taxonomy of the item.","examples":["Short sleeve","Long distance","Lightweight"]},"item_list_id":{"type":"string","description":"The ID of the list in which the item was presented to the user. If set, item_list_id at the event level is ignored. If not set, item_list_id at the event level is used if available.","examples":["related_products","search_results","recommendations"]},"item_list_name":{"type":"string","description":"The name of the list in which the item was presented to the user. If set, item_list_name at the event level is ignored. If not set, item_list_name at the event level is used if available.","examples":["Related Products","Search Results","Recommended Items"]},"item_variant":{"type":"string","description":"The item variant or unique code or description for additional item details/options.","examples":["green","Blue Size 10","M-Black"]},"location_id":{"type":"string","description":"The physical location associated with the item, such as the location of a brick-and-mortar store. It is recommended to use the Google Place ID that corresponds to the associated item. A custom location ID can also be used. Note: location_id is only available at the item level.","examples":["ChIJIQBpAG2ahYAR_6128GcTUEo","store_123","location_sf"]},"price":{"type":"number","description":"The price of the item in the specified currency unit. If a discount is applied to the item, set price to the reduced per-unit price and provide the per-unit price discount in the discount parameter.","examples":[10.01,21.01,89.99]},"quantity":{"type":"number","description":"The item quantity. If not set, quantity is set to 1.","examples":[1,2,3]},"promotion_id":{"type":"string","description":"The ID of the promotion associated with the item.","examples":["P_12345","PROMO_001"]},"promotion_name":{"type":"string","description":"The name of the promotion associated with the item.","examples":["Summer Sale","Black Friday","Flash Deal"]},"creative_name":{"type":"string","description":"The name of the promotion creative.","examples":["summer_banner2","holiday_email_v1"]},"creative_slot":{"type":"string","description":"The name of the creative slot associated with the item.","examples":["featured_app_1","top_banner","sidebar"]},"google_business_vertical":{"type":"string","description":"The business vertical for the item (e.g., 'retail').","examples":["retail","ecommerce"]}}}}}},"user_data":{"type":"object","description":"User related data.","x-gtm-clear":true}}}} />
22
+ <SchemaViewer
23
+ schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/add-to-cart-event.json","title":"Add to Cart Event","description":"An add_to_cart event fires when a user adds one or more items to their shopping cart. Based on Google Analytics 4 ecommerce event specifications.","type":"object","required":["event"],"$defs":{"strictObject":{"type":"object","propertyNames":{"maxLength":40,"pattern":"^[a-z0-9_]+$"},"additionalProperties":{"anyOf":[{"$ref":"#/allOf/0/$defs/strictObject"},{"type":"array","items":{"$ref":"#/allOf/0/$defs/strictObject"}},{"not":{"type":"object"}}]}}},"$ref":"#/allOf/0/$defs/strictObject","properties":{"event":{"type":"string","const":"add_to_cart","description":"The name of the event indicating a add_to_cart has occurred."},"ecommerce":{"type":"object","description":"Ecommerce related data for the purchase event.","required":["currency","items"],"x-gtm-clear":true,"properties":{"value":{"type":"number","description":"The monetary value of the event. Set value to the sum of (price * quantity) for all items in items.","examples":[30.03,99.99,45.5]},"currency":{"type":"string","description":"The currency of the items in ISO 4217 three-letter format. Required when value is set.","examples":["USD","EUR","GBP"]},"items":{"type":"array","description":"The products added to the cart.","minItems":1,"items":{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/components/product.json","title":"A Product","description":"A product object representing an item for use within a purchase event, based on Google Analytics 4 ecommerce event specifications.","type":"object","required":[],"properties":{"item_id":{"type":"string","description":"The ID of the item. Either item_id or item_name is required.","examples":["SKU_12345","PROD_98765"]},"item_name":{"type":"string","description":"The name of the item. Either item_id or item_name is required.","examples":["Stan and Friends Tee","Blue Running Shoes"]},"affiliation":{"type":"string","description":"A product affiliation to indicate a supplier or store. Note: affiliation is only available at the item level.","examples":["Google Merchandise Store","Nike Store"]},"coupon":{"type":"string","description":"The coupon name/code associated with the item. Coupon parameters at event and item levels are independent.","examples":["SUMMER_FUN","WELCOME20","SAVE10"]},"discount":{"type":"number","description":"The monetary value of the discount per unit applied to the item.","examples":[2.22,5,10.5]},"index":{"type":"number","description":"The index or position of the item in a list.","examples":[0,1,2]},"item_brand":{"type":"string","description":"The brand of the item.","examples":["Google","Nike","Adidas"]},"item_category":{"type":"string","description":"The category of the item. If used as part of a category hierarchy or taxonomy, this is the first category.","examples":["Apparel","Footwear","Electronics"]},"item_category2":{"type":"string","description":"The second category hierarchy or additional taxonomy of the item.","examples":["Adult","Women","Men"]},"item_category3":{"type":"string","description":"The third category hierarchy or additional taxonomy of the item.","examples":["Shirts","Shoes","Boots"]},"item_category4":{"type":"string","description":"The fourth category hierarchy or additional taxonomy of the item.","examples":["Crew","Running","Casual"]},"item_category5":{"type":"string","description":"The fifth category hierarchy or additional taxonomy of the item.","examples":["Short sleeve","Long distance","Lightweight"]},"item_list_id":{"type":"string","description":"The ID of the list in which the item was presented to the user. If set, item_list_id at the event level is ignored. If not set, item_list_id at the event level is used if available.","examples":["related_products","search_results","recommendations"]},"item_list_name":{"type":"string","description":"The name of the list in which the item was presented to the user. If set, item_list_name at the event level is ignored. If not set, item_list_name at the event level is used if available.","examples":["Related Products","Search Results","Recommended Items"]},"item_variant":{"type":"string","description":"The item variant or unique code or description for additional item details/options.","examples":["green","Blue Size 10","M-Black"]},"location_id":{"type":"string","description":"The physical location associated with the item, such as the location of a brick-and-mortar store. It is recommended to use the Google Place ID that corresponds to the associated item. A custom location ID can also be used. Note: location_id is only available at the item level.","examples":["ChIJIQBpAG2ahYAR_6128GcTUEo","store_123","location_sf"]},"price":{"type":"number","description":"The price of the item in the specified currency unit. If a discount is applied to the item, set price to the reduced per-unit price and provide the per-unit price discount in the discount parameter.","examples":[10.01,21.01,89.99]},"quantity":{"type":"number","description":"The item quantity. If not set, quantity is set to 1.","examples":[1,2,3]},"promotion_id":{"type":"string","description":"The ID of the promotion associated with the item.","examples":["P_12345","PROMO_001"]},"promotion_name":{"type":"string","description":"The name of the promotion associated with the item.","examples":["Summer Sale","Black Friday","Flash Deal"]},"creative_name":{"type":"string","description":"The name of the promotion creative.","examples":["summer_banner2","holiday_email_v1"]},"creative_slot":{"type":"string","description":"The name of the creative slot associated with the item.","examples":["featured_app_1","top_banner","sidebar"]},"google_business_vertical":{"type":"string","description":"The business vertical for the item (e.g., 'retail').","examples":["retail","ecommerce"]}}}}}},"user_data":{"type":"object","description":"User related data.","x-gtm-clear":true}}}}
24
+
25
+ />
23
26
  <SchemaJsonViewer schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/next/add-to-cart-event.json","title":"Add to Cart Event","description":"An add_to_cart event fires when a user adds one or more items to their shopping cart. Based on Google Analytics 4 ecommerce event specifications.","type":"object","allOf":[{"$ref":"./components/dataLayer.json"}],"properties":{"event":{"type":"string","const":"add_to_cart","description":"The name of the event indicating a add_to_cart has occurred."},"ecommerce":{"type":"object","description":"Ecommerce related data for the purchase event.","properties":{"value":{"type":"number","description":"The monetary value of the event. Set value to the sum of (price * quantity) for all items in items.","examples":[30.03,99.99,45.5]},"currency":{"type":"string","description":"The currency of the items in ISO 4217 three-letter format. Required when value is set.","examples":["USD","EUR","GBP"]},"items":{"type":"array","description":"The products added to the cart.","minItems":1,"items":{"$ref":"./components/product.json"}}},"required":["currency","items"]}}}} />
24
27
 
25
28
 
@@ -45,7 +48,10 @@ An add_to_cart event fires when a user adds one or more items to their shopping
45
48
 
46
49
 
47
50
 
48
- <SchemaViewer schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/add-to-cart-event.json","title":"Add to Cart Event","description":"An add_to_cart event fires when a user adds one or more items to their shopping cart. Based on Google Analytics 4 ecommerce event specifications.","type":"object","required":["event"],"$defs":{"strictObject":{"type":"object","propertyNames":{"maxLength":40,"pattern":"^[a-z0-9_]+$"},"additionalProperties":{"anyOf":[{"$ref":"#/allOf/0/$defs/strictObject"},{"type":"array","items":{"$ref":"#/allOf/0/$defs/strictObject"}},{"not":{"type":"object"}}]}}},"$ref":"#/allOf/0/$defs/strictObject","properties":{"event":{"type":"string","const":"add_to_cart","description":"The name of the event indicating a add_to_cart has occurred."},"ecommerce":{"type":"object","description":"Ecommerce related data for the purchase event.","required":["currency","items"],"x-gtm-clear":true,"properties":{"value":{"type":"number","description":"The monetary value of the event. Set value to the sum of (price * quantity) for all items in items.","examples":[30.03,99.99,45.5]},"currency":{"type":"string","description":"The currency of the items in ISO 4217 three-letter format. Required when value is set.","examples":["USD","EUR","GBP"]},"items":{"type":"array","description":"The products added to the cart.","minItems":1,"items":{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/components/product.json","title":"A Product","description":"A product object representing an item for use within a purchase event, based on Google Analytics 4 ecommerce event specifications.","type":"object","required":[],"properties":{"item_id":{"type":"string","description":"The ID of the item. Either item_id or item_name is required.","examples":["SKU_12345","PROD_98765"]},"item_name":{"type":"string","description":"The name of the item. Either item_id or item_name is required.","examples":["Stan and Friends Tee","Blue Running Shoes"]},"affiliation":{"type":"string","description":"A product affiliation to indicate a supplier or store. Note: affiliation is only available at the item level.","examples":["Google Merchandise Store","Nike Store"]},"coupon":{"type":"string","description":"The coupon name/code associated with the item. Coupon parameters at event and item levels are independent.","examples":["SUMMER_FUN","WELCOME20","SAVE10"]},"discount":{"type":"number","description":"The monetary value of the discount per unit applied to the item.","examples":[2.22,5,10.5]},"index":{"type":"number","description":"The index or position of the item in a list.","examples":[0,1,2]},"item_brand":{"type":"string","description":"The brand of the item.","examples":["Google","Nike","Adidas"]},"item_category":{"type":"string","description":"The category of the item. If used as part of a category hierarchy or taxonomy, this is the first category.","examples":["Apparel","Footwear","Electronics"]},"item_category2":{"type":"string","description":"The second category hierarchy or additional taxonomy of the item.","examples":["Adult","Women","Men"]},"item_category3":{"type":"string","description":"The third category hierarchy or additional taxonomy of the item.","examples":["Shirts","Shoes","Boots"]},"item_category4":{"type":"string","description":"The fourth category hierarchy or additional taxonomy of the item.","examples":["Crew","Running","Casual"]},"item_category5":{"type":"string","description":"The fifth category hierarchy or additional taxonomy of the item.","examples":["Short sleeve","Long distance","Lightweight"]},"item_list_id":{"type":"string","description":"The ID of the list in which the item was presented to the user. If set, item_list_id at the event level is ignored. If not set, item_list_id at the event level is used if available.","examples":["related_products","search_results","recommendations"]},"item_list_name":{"type":"string","description":"The name of the list in which the item was presented to the user. If set, item_list_name at the event level is ignored. If not set, item_list_name at the event level is used if available.","examples":["Related Products","Search Results","Recommended Items"]},"item_variant":{"type":"string","description":"The item variant or unique code or description for additional item details/options.","examples":["green","Blue Size 10","M-Black"]},"location_id":{"type":"string","description":"The physical location associated with the item, such as the location of a brick-and-mortar store. It is recommended to use the Google Place ID that corresponds to the associated item. A custom location ID can also be used. Note: location_id is only available at the item level.","examples":["ChIJIQBpAG2ahYAR_6128GcTUEo","store_123","location_sf"]},"price":{"type":"number","description":"The price of the item in the specified currency unit. If a discount is applied to the item, set price to the reduced per-unit price and provide the per-unit price discount in the discount parameter.","examples":[10.01,21.01,89.99]},"quantity":{"type":"number","description":"The item quantity. If not set, quantity is set to 1.","examples":[1,2,3]},"promotion_id":{"type":"string","description":"The ID of the promotion associated with the item.","examples":["P_12345","PROMO_001"]},"promotion_name":{"type":"string","description":"The name of the promotion associated with the item.","examples":["Summer Sale","Black Friday","Flash Deal"]},"creative_name":{"type":"string","description":"The name of the promotion creative.","examples":["summer_banner2","holiday_email_v1"]},"creative_slot":{"type":"string","description":"The name of the creative slot associated with the item.","examples":["featured_app_1","top_banner","sidebar"]},"google_business_vertical":{"type":"string","description":"The business vertical for the item (e.g., 'retail').","examples":["retail","ecommerce"]}}}}}},"user_data":{"type":"object","description":"User related data.","x-gtm-clear":true}}}} />
51
+ <SchemaViewer
52
+ schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/add-to-cart-event.json","title":"Add to Cart Event","description":"An add_to_cart event fires when a user adds one or more items to their shopping cart. Based on Google Analytics 4 ecommerce event specifications.","type":"object","required":["event"],"$defs":{"strictObject":{"type":"object","propertyNames":{"maxLength":40,"pattern":"^[a-z0-9_]+$"},"additionalProperties":{"anyOf":[{"$ref":"#/allOf/0/$defs/strictObject"},{"type":"array","items":{"$ref":"#/allOf/0/$defs/strictObject"}},{"not":{"type":"object"}}]}}},"$ref":"#/allOf/0/$defs/strictObject","properties":{"event":{"type":"string","const":"add_to_cart","description":"The name of the event indicating a add_to_cart has occurred."},"ecommerce":{"type":"object","description":"Ecommerce related data for the purchase event.","required":["currency","items"],"x-gtm-clear":true,"properties":{"value":{"type":"number","description":"The monetary value of the event. Set value to the sum of (price * quantity) for all items in items.","examples":[30.03,99.99,45.5]},"currency":{"type":"string","description":"The currency of the items in ISO 4217 three-letter format. Required when value is set.","examples":["USD","EUR","GBP"]},"items":{"type":"array","description":"The products added to the cart.","minItems":1,"items":{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/components/product.json","title":"A Product","description":"A product object representing an item for use within a purchase event, based on Google Analytics 4 ecommerce event specifications.","type":"object","required":[],"properties":{"item_id":{"type":"string","description":"The ID of the item. Either item_id or item_name is required.","examples":["SKU_12345","PROD_98765"]},"item_name":{"type":"string","description":"The name of the item. Either item_id or item_name is required.","examples":["Stan and Friends Tee","Blue Running Shoes"]},"affiliation":{"type":"string","description":"A product affiliation to indicate a supplier or store. Note: affiliation is only available at the item level.","examples":["Google Merchandise Store","Nike Store"]},"coupon":{"type":"string","description":"The coupon name/code associated with the item. Coupon parameters at event and item levels are independent.","examples":["SUMMER_FUN","WELCOME20","SAVE10"]},"discount":{"type":"number","description":"The monetary value of the discount per unit applied to the item.","examples":[2.22,5,10.5]},"index":{"type":"number","description":"The index or position of the item in a list.","examples":[0,1,2]},"item_brand":{"type":"string","description":"The brand of the item.","examples":["Google","Nike","Adidas"]},"item_category":{"type":"string","description":"The category of the item. If used as part of a category hierarchy or taxonomy, this is the first category.","examples":["Apparel","Footwear","Electronics"]},"item_category2":{"type":"string","description":"The second category hierarchy or additional taxonomy of the item.","examples":["Adult","Women","Men"]},"item_category3":{"type":"string","description":"The third category hierarchy or additional taxonomy of the item.","examples":["Shirts","Shoes","Boots"]},"item_category4":{"type":"string","description":"The fourth category hierarchy or additional taxonomy of the item.","examples":["Crew","Running","Casual"]},"item_category5":{"type":"string","description":"The fifth category hierarchy or additional taxonomy of the item.","examples":["Short sleeve","Long distance","Lightweight"]},"item_list_id":{"type":"string","description":"The ID of the list in which the item was presented to the user. If set, item_list_id at the event level is ignored. If not set, item_list_id at the event level is used if available.","examples":["related_products","search_results","recommendations"]},"item_list_name":{"type":"string","description":"The name of the list in which the item was presented to the user. If set, item_list_name at the event level is ignored. If not set, item_list_name at the event level is used if available.","examples":["Related Products","Search Results","Recommended Items"]},"item_variant":{"type":"string","description":"The item variant or unique code or description for additional item details/options.","examples":["green","Blue Size 10","M-Black"]},"location_id":{"type":"string","description":"The physical location associated with the item, such as the location of a brick-and-mortar store. It is recommended to use the Google Place ID that corresponds to the associated item. A custom location ID can also be used. Note: location_id is only available at the item level.","examples":["ChIJIQBpAG2ahYAR_6128GcTUEo","store_123","location_sf"]},"price":{"type":"number","description":"The price of the item in the specified currency unit. If a discount is applied to the item, set price to the reduced per-unit price and provide the per-unit price discount in the discount parameter.","examples":[10.01,21.01,89.99]},"quantity":{"type":"number","description":"The item quantity. If not set, quantity is set to 1.","examples":[1,2,3]},"promotion_id":{"type":"string","description":"The ID of the promotion associated with the item.","examples":["P_12345","PROMO_001"]},"promotion_name":{"type":"string","description":"The name of the promotion associated with the item.","examples":["Summer Sale","Black Friday","Flash Deal"]},"creative_name":{"type":"string","description":"The name of the promotion creative.","examples":["summer_banner2","holiday_email_v1"]},"creative_slot":{"type":"string","description":"The name of the creative slot associated with the item.","examples":["featured_app_1","top_banner","sidebar"]},"google_business_vertical":{"type":"string","description":"The business vertical for the item (e.g., 'retail').","examples":["retail","ecommerce"]}}}}}},"user_data":{"type":"object","description":"User related data.","x-gtm-clear":true}}}}
53
+
54
+ />
49
55
  <SchemaJsonViewer schema={{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://tracking-docs-demo.buchert.digital/schemas/1.1.1/add-to-cart-event.json","title":"Add to Cart Event","description":"An add_to_cart event fires when a user adds one or more items to their shopping cart. Based on Google Analytics 4 ecommerce event specifications.","type":"object","allOf":[{"$ref":"./components/dataLayer.json"}],"properties":{"event":{"type":"string","const":"add_to_cart","description":"The name of the event indicating a add_to_cart has occurred."},"ecommerce":{"type":"object","description":"Ecommerce related data for the purchase event.","properties":{"value":{"type":"number","description":"The monetary value of the event. Set value to the sum of (price * quantity) for all items in items.","examples":[30.03,99.99,45.5]},"currency":{"type":"string","description":"The currency of the items in ISO 4217 three-letter format. Required when value is set.","examples":["USD","EUR","GBP"]},"items":{"type":"array","description":"The products added to the cart.","minItems":1,"items":{"$ref":"./components/product.json"}}},"required":["currency","items"]}}}} />
50
56
 
51
57
 
@@ -1,6 +1,6 @@
1
1
  import '@testing-library/jest-dom';
2
2
  import React from 'react';
3
- import { render } from '@testing-library/react';
3
+ import { render, fireEvent } from '@testing-library/react';
4
4
  import PropertiesTable from '../../components/PropertiesTable';
5
5
 
6
6
  jest.mock('../../components/TableHeader', () => {
@@ -23,6 +23,13 @@ jest.mock('../../components/SchemaRows', () => {
23
23
  MockSchemaRows.displayName = 'MockSchemaRows';
24
24
  return MockSchemaRows;
25
25
  });
26
+ jest.mock('../../components/WordWrapButton', () => {
27
+ const MockWordWrapButton = ({ onClick }) => (
28
+ <button onClick={onClick}>Toggle word wrap</button>
29
+ );
30
+ MockWordWrapButton.displayName = 'MockWordWrapButton';
31
+ return MockWordWrapButton;
32
+ });
26
33
 
27
34
  describe('PropertiesTable', () => {
28
35
  it('renders the table with header and schema rows', () => {
@@ -38,4 +45,30 @@ describe('PropertiesTable', () => {
38
45
  expect(getByText('Mocked TableHeader')).toBeInTheDocument();
39
46
  expect(getByText('Mocked SchemaRows')).toBeInTheDocument();
40
47
  });
48
+
49
+ it('toggles word wrap when the button is clicked', () => {
50
+ const schema = {
51
+ properties: {
52
+ name: { type: 'string' },
53
+ },
54
+ required: ['name'],
55
+ };
56
+ const { container, getByRole } = render(
57
+ <PropertiesTable schema={schema} />,
58
+ );
59
+
60
+ expect(container.firstChild).not.toHaveClass('noWordWrap');
61
+
62
+ // Find the button
63
+ const toggleButton = getByRole('button', { name: /toggle word wrap/i });
64
+ expect(toggleButton).toBeInTheDocument();
65
+
66
+ // Click the button to disable word wrap
67
+ fireEvent.click(toggleButton);
68
+ expect(container.firstChild).toHaveClass('noWordWrap');
69
+
70
+ // Click the button again to enable word wrap
71
+ fireEvent.click(toggleButton);
72
+ expect(container.firstChild).not.toHaveClass('noWordWrap');
73
+ });
41
74
  });
@@ -11,7 +11,7 @@ describe('PropertyRow', () => {
11
11
  required: false,
12
12
  propertyType: 'string',
13
13
  description: 'The name of the user.',
14
- example: 'John Doe',
14
+ examples: ['John Doe'],
15
15
  constraints: [],
16
16
  path: ['name'],
17
17
  };
@@ -27,7 +27,7 @@ describe('PropertyRow', () => {
27
27
  expect(getByText('name')).toBeInTheDocument();
28
28
  expect(getByText('string')).toBeInTheDocument();
29
29
  expect(getByText('The name of the user.')).toBeInTheDocument();
30
- expect(getByText('John Doe')).toBeInTheDocument();
30
+ expect(getByText('"John Doe"')).toBeInTheDocument();
31
31
  });
32
32
 
33
33
  it('marks required properties', () => {
@@ -37,7 +37,7 @@ describe('PropertyRow', () => {
37
37
  required: true,
38
38
  propertyType: 'string',
39
39
  description: '',
40
- example: '',
40
+ examples: [],
41
41
  constraints: ['required'],
42
42
  path: ['name'],
43
43
  };
@@ -86,7 +86,7 @@ describe('PropertyRow', () => {
86
86
  required: false,
87
87
  propertyType: 'string',
88
88
  description: '',
89
- example: 'foo',
89
+ examples: ['foo'],
90
90
  constraints: [],
91
91
  path: ['name'],
92
92
  };
@@ -98,7 +98,7 @@ describe('PropertyRow', () => {
98
98
  </tbody>
99
99
  </table>,
100
100
  );
101
- expect(getByText('foo')).toBeInTheDocument();
101
+ expect(getByText('"foo"')).toBeInTheDocument();
102
102
  });
103
103
 
104
104
  it('does not render anything for empty constraints', () => {
@@ -0,0 +1,71 @@
1
+ /**
2
+ * @jest-environment node
3
+ */
4
+
5
+ import generateEventDocs from '../generateEventDocs';
6
+ import fs from 'fs';
7
+ import path from 'path';
8
+
9
+ jest.mock('fs', () => {
10
+ const memfs = require('memfs');
11
+ return memfs;
12
+ });
13
+
14
+ describe('generateEventDocs (oneOf with $anchor)', () => {
15
+ const testSiteDir = path.resolve(__dirname, '__fixtures_anchor__');
16
+ const options = {
17
+ organizationName: 'test-org',
18
+ projectName: 'test-project',
19
+ siteDir: testSiteDir,
20
+ url: 'https://tracking-docs-demo.buchert.digital',
21
+ };
22
+ const baseOutputDir = path.join(options.siteDir, 'docs');
23
+
24
+ beforeEach(() => {
25
+ fs.vol.reset();
26
+ const realFs = jest.requireActual('fs');
27
+ const anchorSchemasDir = path.resolve(
28
+ __dirname,
29
+ '__fixtures__/static/schemas/anchor',
30
+ );
31
+ const targetSchemasDir = path.join(testSiteDir, 'static/schemas');
32
+ fs.vol.mkdirSync(targetSchemasDir, { recursive: true });
33
+
34
+ const files = realFs.readdirSync(anchorSchemasDir, { withFileTypes: true });
35
+ for (const file of files) {
36
+ const filePath = path.join(anchorSchemasDir, file.name);
37
+ const content = realFs.readFileSync(filePath);
38
+ fs.vol.writeFileSync(path.join(targetSchemasDir, file.name), content);
39
+ }
40
+ });
41
+
42
+ it('should generate documentation using $anchor for slug', async () => {
43
+ console.log = jest.fn(); // suppress console.log
44
+
45
+ await generateEventDocs(options);
46
+
47
+ const parentDir = path.join(baseOutputDir, 'parent-event-anchor');
48
+
49
+ // Check for directory structure
50
+ expect(fs.existsSync(parentDir)).toBe(true);
51
+
52
+ const parentIndex = fs.readFileSync(
53
+ path.join(parentDir, 'index.mdx'),
54
+ 'utf-8',
55
+ );
56
+ expect(parentIndex).toMatchSnapshot();
57
+
58
+ // Check content of generated files
59
+ const childWithAnchor = fs.readFileSync(
60
+ path.join(parentDir, '01-child-event-with-anchor.mdx'),
61
+ 'utf-8',
62
+ );
63
+ expect(childWithAnchor).toMatchSnapshot();
64
+
65
+ const childWithTitle = fs.readFileSync(
66
+ path.join(parentDir, '02-child-event-title.mdx'),
67
+ 'utf-8',
68
+ );
69
+ expect(childWithTitle).toMatchSnapshot();
70
+ });
71
+ });