Skip to content

Add _setUserProperties info #819

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions content/collections/guides_and_surveys/en/sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ For additional configuration, supply `InitOptions` to the `plugin` function. See



### Other Amplitude SDK's and third-party analytics providers
### Other Amplitude SDK's and third-party analytics providers

If you don't use the Amplitude Analytics [Browser SDK 2](/docs/sdks/analytics/browser/browser-sdk-2), you can still use Guides and Surveys but you need to configure the SDK to work with your other Amplitude Analytics SDK or third-party analytics provider. First, add the SDK to your project using the script tag, or through npm or Yarn as outlined above.
But, instead of calling `amplitude.add(window.engagement.plugin())`, you need to call `init` and `boot`.
Expand Down Expand Up @@ -450,6 +450,33 @@ engagement.forwardEvent(event: Event): void
| `event` | Event | Required. An [event](/docs/sdks/analytics/browser/browser-sdk-2#track-an-event) object. It triggers a guide or survey if its `event_type` matches. |


## Set user properties
Set user properties for the current session. These properties can be used as variables inside guides and surveys content with the `@{{ properties.propertyName }}` syntax.

If you use `amplitude.identify()` to share user properties, you don't need to use `_setUserProperties()`.

{{partial:admonition type="tip" heading=""}}
Ensure that user properties load during the current client-side session and before the guide or survey displays. Properties shared from prior sessions aren't available.
{{/partial:admonition}}

```js
engagement._setUserProperties(userProperties: Record<string, any>): void
```

| Parameter | Type | Description |
| ---------------- | ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| `userProperties` | `Record<string, any>` | Required. An object that contains user properties as key-value pairs. Reference these properties in guides and surveys content. |
### Example

```js
// Supply user properties manually via engagement SDK
const userProperties = {firstName: 'john'}
engagement._setUserProperties(userProperties)

// For testing, view the current user properties
engagement._.user.user_properties
```

## Close all

Close all active guides and surveys.
Expand Down Expand Up @@ -521,4 +548,4 @@ If you implement Guides and Surveys with `amplitude.add(window.engagement.plugin
Ensure the API key you provide:

- is the same key you use to initialize the Browser SDK
- belongs to the project that contains the Guides and Surveys configuration
- belongs to the project that contains the Guides and Surveys configuration
Loading