From c940402c95a2eb6a4ae26b33e8ba0d0c2c83d857 Mon Sep 17 00:00:00 2001 From: Ashton Huxtable <78318468+ashton-huxtable@users.noreply.github.com> Date: Mon, 23 Jan 2023 09:57:16 -0700 Subject: [PATCH 1/3] Update AJS FAQs to include adding new context fields --- .../website/javascript/troubleshooting.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/connections/sources/catalog/libraries/website/javascript/troubleshooting.md b/src/connections/sources/catalog/libraries/website/javascript/troubleshooting.md index 74972f5d86..e31e5656c7 100644 --- a/src/connections/sources/catalog/libraries/website/javascript/troubleshooting.md +++ b/src/connections/sources/catalog/libraries/website/javascript/troubleshooting.md @@ -131,6 +131,22 @@ analytics.track("Receipt Viewed", {}, { This works for any [context field](/docs/connections/spec/common/#context) that Segment automatically collects. +### Can I add context fields that do not already exist? + +Yes. Similar to overwriting context, you can add context fields by passing them into the options object as the third argument of the event call. For example, the analytics.js library does not automatically collect location information. So, if you wanted to add this into your context object, you would pass it into the third argument as in the example below: + +```js +analytics.track("Order Completed", {}, { + location: { + latitude: '39.7392', + longitude: '104.9903' + } +}) +``` + +It is important to note that if you are not passing in properties, you still need to pass an empty object in it's place as shown in the above example. + + ## Known issues: [Review and contribute to these on GitHub](https://github.com/segmentio/analytics.js/issues) From 382811482571acc878fec598848f28364c7ca0cf Mon Sep 17 00:00:00 2001 From: Ashton Huxtable <78318468+ashton-huxtable@users.noreply.github.com> Date: Mon, 23 Jan 2023 10:25:24 -0700 Subject: [PATCH 2/3] Include note that custom context may not be forwarded to destinations --- .../catalog/libraries/website/javascript/troubleshooting.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/connections/sources/catalog/libraries/website/javascript/troubleshooting.md b/src/connections/sources/catalog/libraries/website/javascript/troubleshooting.md index e31e5656c7..91901d2e13 100644 --- a/src/connections/sources/catalog/libraries/website/javascript/troubleshooting.md +++ b/src/connections/sources/catalog/libraries/website/javascript/troubleshooting.md @@ -146,6 +146,8 @@ analytics.track("Order Completed", {}, { It is important to note that if you are not passing in properties, you still need to pass an empty object in it's place as shown in the above example. +Additionally, custom context fields may not be forwarded to all destinations, as some destinations accept properties only. + ## Known issues: From c19d09551df181a4bccf56f8b8faea6b4f4779ca Mon Sep 17 00:00:00 2001 From: markzegarelli Date: Tue, 24 Jan 2023 09:46:36 -0800 Subject: [PATCH 3/3] Apply suggestions from code review --- .../libraries/website/javascript/troubleshooting.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/connections/sources/catalog/libraries/website/javascript/troubleshooting.md b/src/connections/sources/catalog/libraries/website/javascript/troubleshooting.md index 91901d2e13..4a933d77c2 100644 --- a/src/connections/sources/catalog/libraries/website/javascript/troubleshooting.md +++ b/src/connections/sources/catalog/libraries/website/javascript/troubleshooting.md @@ -133,7 +133,7 @@ This works for any [context field](/docs/connections/spec/common/#context) that ### Can I add context fields that do not already exist? -Yes. Similar to overwriting context, you can add context fields by passing them into the options object as the third argument of the event call. For example, the analytics.js library does not automatically collect location information. So, if you wanted to add this into your context object, you would pass it into the third argument as in the example below: +Yes. Similar to overwriting context, you can add context fields by passing them into the options object as the third argument of the event call. For example, the analytics.js library does not automatically collect location information. To add this into the context object, pass it into the third argument as in the example below: ```js analytics.track("Order Completed", {}, { @@ -144,9 +144,10 @@ analytics.track("Order Completed", {}, { }) ``` -It is important to note that if you are not passing in properties, you still need to pass an empty object in it's place as shown in the above example. +> info "" +> You must pass the context object with the call, event if it's empty, as shown by the empty object in the example above. -Additionally, custom context fields may not be forwarded to all destinations, as some destinations accept properties only. +Some destinations accept properties only. As a result, custom context fields you add may not forward to these destinations. ## Known issues: