Skip to content

Commit 97a58fd

Browse files
committed
insert variable scoping sections to insert functions + source functions
1 parent 91b5d05 commit 97a58fd

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/connections/functions/insert-functions.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ To ensure the Destination processes an event payload modified by the function, r
111111
> info ""
112112
> Functions' runtime includes a `fetch()` polyfill using a `node-fetch` package. Check out the [node-fetch documentation](https://www.npmjs.com/package/node-fetch){:target="_blank"} for usage examples.
113113
114+
### Variable scoping
115+
116+
When declaring settings variables, make sure to declare them in the function handler rather than globally in your Function. This prevents you leaking the settings values across other function instances.
117+
118+
The handler for Insert functions is event-specific, for example, `onTrack()`, `onIdentify()`, etc.
119+
114120
### Errors and error handling
115121

116122
Segment considers a function's execution successful if it finishes without error. You can `throw` an error to create a failure on purpose. Use these errors to validate event data before processing it to ensure the function works as expected.

src/connections/functions/source-functions.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,12 @@ The `Segment.set()` method accepts an object with the following fields:
261261
> warning ""
262262
> When you use the `set()` method, you won't see events in the Source Debugger. Segment only sends events to connected warehouses.
263263
264+
### Variable scoping
265+
266+
Declare settings variables in the function handler, rather than globally in your function. This prevents you from leaking the settings values across other function instances.
267+
268+
The handler for Source functions is `onRequest()`.
269+
264270
### Runtime and dependencies
265271

266272
{% include content/functions/runtime.md %}

0 commit comments

Comments
 (0)