### Basic Usage of start() Source: https://docs.usertour.io/developers/usertourjs-reference/content/start This snippet shows the basic usage of the start() method to display Usertour content using its unique ID. ```javascript usertour.start('cmaw8v1ch013s147h0uw8aha5'); ``` -------------------------------- ### Start Usertour with Docker Compose Source: https://docs.usertour.io/open-source/self-hosting Command to start Usertour using Docker Compose. Ensure you are in the directory with your docker-compose.yml file. ```bash docker-compose -f docker-compose.yml up -d ``` ```bash docker compose -f docker-compose.yml up -d ``` -------------------------------- ### Install Project Dependencies Source: https://docs.usertour.io/open-source/local-development Install all necessary project dependencies using pnpm. This command should be run from the root of the cloned repository. ```bash pnpm install ``` -------------------------------- ### Start Usertour Development Servers Source: https://docs.usertour.io/open-source/local-development Start the backend API server, the frontend web application, and the SDK development server independently. The web application will be accessible at http://localhost:5174. ```bash # Start the backend API server pnpm dev:server # Start the web application pnpm dev:web # Start the SDK development server pnpm dev:sdk ``` -------------------------------- ### Example Flows Source: https://docs.usertour.io/use-cases/close-button-follow-up Illustrates the content of an original onboarding flow and a subsequent follow-up tooltip. ```text Original flow: Welcome onboarding Follow-up flow: You can restart onboarding from the help menu at any time. ``` -------------------------------- ### Resume Previous Session with start() Source: https://docs.usertour.io/developers/usertourjs-reference/content/start Use the 'continue' option set to true with the start() method to allow users to resume Usertour content from where they left off in their last session. ```javascript usertour.start('cmaw8v1ch013s147h0uw8aha5', { continue: true }); ``` -------------------------------- ### Install Usertour.js via NPM or Yarn Source: https://docs.usertour.io/developers/usertourjs-reference/overview Install the Usertour.js package using npm or Yarn for the recommended development experience. ```bash # Using npm npm install usertour.js # Or using Yarn yarn add usertour.js ``` -------------------------------- ### List Users Response Example Source: https://docs.usertour.io/api-reference/users/list Example of a successful response when listing users, including user data and pagination information. ```json { "results": [ { "id": "usr_123456789", "object": "user", "attributes": { "name": "John Doe", "email": "john.doe@example.com", "role": "admin", "department": "engineering", "last_login_at": "2024-03-20T08:30:00.000Z" }, "createdAt": "2024-03-20T08:30:00.000Z", "companies": null, "memberships": null }, { "id": "usr_987654321", "object": "user", "attributes": { "name": "Jane Smith", "email": "jane.smith@example.com", "role": "user", "department": "marketing", "last_login_at": "2024-03-19T15:45:00.000Z" }, "createdAt": "2024-03-19T15:45:00.000Z", "companies": null, "memberships": null } ], "next": "/v1/users?limit=2&cursor=usr_987654321", "previous": null } ``` -------------------------------- ### Install Usertour.js via NPM Source: https://docs.usertour.io/developers/usertourjs-reference/installation Use this command to install the usertour.js npm package. This is recommended for modern web applications using module bundlers. ```bash npm install usertour.js ``` -------------------------------- ### Example .env File Configuration Source: https://docs.usertour.io/open-source/env This is a comprehensive example of a .env file for a UserTour project. It includes configurations for database, server, email, Redis, application settings, AWS S3, analytics, OpenTelemetry, encryption, and authentication. Remember to replace placeholder values with your actual environment-specific credentials and keys, especially for production. ```env # Database Configuration DATABASE_URL=postgresql://user:password@localhost:5432/dbname DATABASE_DIRECT_URL=postgresql://user:password@localhost:5432/dbname # Server Configuration NEST_SERVER_PORT=3000 NODE_ENV=production # Email Service Configuration EMAIL_HOST=smtp.example.com EMAIL_PORT=587 EMAIL_USER=your_email@example.com EMAIL_PASS=your_email_password # Redis Configuration Redis_HOST=localhost Redis_PORT=6379 Redis_PASS= # Application Configuration APP_HOMEPAGE_URL=http://localhost:8011 API_URL= DOC_URL=https://docs.usertour.com USERTOUR_TOKEN=your_token # AWS S3 Configuration AWS_S3_REGION=your_region AWS_S3_ENDPOINT=your_endpoint AWS_S3_ACCESS_KEY_ID=your_access_key AWS_S3_SECRET_ACCESS_KEY=your_secret_key AWS_S3_BUCKET=your_bucket AWS_S3_DOMAIN=your_domain # Analytics Configuration POSTHOG_KEY=your_posthog_key POSTHOG_HOST=your_posthog_host # OpenTelemetry Configuration OTLP_TRACES_ENDPOINT= OTLP_METRICS_ENDPOINT= # Encryption (run `openssl rand -hex 32` to generate) ENCRYPTION_KEY=replace_with_64_hex_chars # JWT Configuration JWT_SECRET=your_jwt_secret JWT_EXPIRATION_TIME=1h JWT_REFRESH_EXPIRATION_TIME=7d # Email Authentication EMAIL_AUTH_ENABLED=true EMAIL_SENDER=Your App # GitHub Authentication GITHUB_AUTH_ENABLED=true GITHUB_CLIENT_ID=your_github_client_id GITHUB_CLIENT_SECRET=your_github_client_secret GITHUB_CALLBACK_URL=http://localhost:8011/api/auth/github/callback # Google Authentication GOOGLE_AUTH_ENABLED=true GOOGLE_CLIENT_ID=your_google_client_id GOOGLE_CLIENT_SECRET=your_google_client_secret GOOGLE_CALLBACK_URL=http://localhost:8011/api/auth/google/callback ``` -------------------------------- ### Usertour Company Group Setup Source: https://docs.usertour.io/how-to-guides/companies Use this snippet to group users into a company, optionally providing company and membership attributes. Ensure Usertour.js is installed before use. ```javascript usertour.group(companyId, { // Optional company attributes name: "Acme Corp", plan: "enterprise", // Optional membership attributes role: "admin" }); ``` -------------------------------- ### Start Flow From Beginning Source: https://docs.usertour.io/use-cases/restart-onboarding-from-button Use `usertour.start()` without additional options to restart an onboarding flow from its initial step. This is suitable for a standard replay button. ```javascript usertour.start("your_flow_id"); ``` -------------------------------- ### Show Content Only Once with start() Source: https://docs.usertour.io/developers/usertourjs-reference/content/start Configure the start() method to display content only to users who haven't seen it before by setting the 'once' option to true. The 'continue' option is ignored when 'once' is true. ```javascript usertour.start('cmaw8v1ch013s147h0uw8aha5', { once: true }); ``` -------------------------------- ### start() Source: https://docs.usertour.io/developers/usertourjs-reference/content/start Programmatically trigger and display Usertour content for authenticated users. This method allows for custom triggers for onboarding and feature discovery flows. ```APIDOC ## start(contentId, options) ### Description Programmatically trigger and display Usertour content (such as flows, checklists, or other interactive guides) for your authenticated users. When called, the specified content will be rendered immediately in your application. ### Method `start` ### Parameters #### Path Parameters - **contentId** (string) - Required - The unique identifier of the content you want to display. You can find this ID in the content detail page URL: `/env/{envId}/{contentType}/{contentId}/detail` #### Query Parameters - **options** (object) - Optional - Configuration object to customize the content display behavior. - **once** (boolean) - Optional - When set to true, the content will only be shown to users who haven't seen it before. If the user has already viewed the content, nothing will happen. Defaults to false. - **continue** (boolean) - Optional - When set to true, the content will resume from where the user left off in their previous session. If false, the content will start from the beginning. Defaults to false. ### Note When `once: true` is set, the `continue` option will not take effect since the content will only be shown once to the user. ### Return Returns a `Promise` that resolves when the content has been successfully initialized and displayed. ### Example #### Basic Usage ```javascript usertour.start('cmaw8v1ch013s147h0uw8aha5'); ``` #### Show Content Only Once ```javascript usertour.start('cmaw8v1ch013s147h0uw8aha5', { once: true }); ``` #### Resume Previous Session ```javascript usertour.start('cmaw8v1ch013s147h0uw8aha5', { continue: true }); ``` ### Note Make sure to call `init()` before using any other Usertour.js methods ``` -------------------------------- ### Example Scenario Steps Source: https://docs.usertour.io/use-cases/continue-after-text-input Illustrates a two-step scenario where the first step prompts for user input and the second step relates to that input. ```text Step 1: Tell us about your setup. Step 2: Select this checkbox if you want to enable the option. ``` -------------------------------- ### start() Source: https://docs.usertour.io/llms.txt Programmatically trigger and display Usertour content for authenticated users. This method is part of the Usertour JavaScript SDK. ```APIDOC ## start(contentId, options) ### Description Programmatically initiates and displays a specific Usertour content item (e.g., a flow or tooltip) to the current user. You can provide optional configurations for how the content should be displayed. ### Method JavaScript SDK Function ### Parameters - **contentId** (string) - Required - The unique identifier of the Usertour content to start. - **options** (object) - Optional - Configuration options for displaying the content. - **force** (boolean) - If true, restarts the content even if it has been completed. ### Usage ```javascript Usertour.start('onboarding_checklist', { force: true }); ``` ``` -------------------------------- ### Page Rule Example Source: https://docs.usertour.io/use-cases/start-flow-when-element-appears This rule confirms the user is on the correct page but doesn't guarantee the target UI is ready. ```text Current page is /settings/team ``` -------------------------------- ### Response Example for Listing Attribute Definitions Source: https://docs.usertour.io/api-reference/attribute-definitions/list This is an example JSON response when listing attribute definitions. It includes a list of attribute definition objects and pagination details. ```json { "results": [ { "id": "cm9e922or000jmjaox6ynbld2", "object": "attributeDefinition", "createdAt": "2025-04-12T13:26:30.939Z", "dataType": "string", "description": "Usertour flow id", "displayName": "Flow ID", "codeName": "flow_id", "scope": "eventDefinition" }, { "id": "cm9e922or000kmjao3nhw7w74", "object": "attributeDefinition", "createdAt": "2025-04-12T13:26:30.939Z", "dataType": "string", "description": "Usertour flow name", "displayName": "Flow Name", "codeName": "flow_name", "scope": "eventDefinition" }, { "id": "cm9e922or000lmjao49o5mwwf", "object": "attributeDefinition", "createdAt": "2025-04-12T13:26:30.939Z", "dataType": "string", "description": "A session of a specific user viewing a specific flow", "displayName": "Flow Session ID", "codeName": "flow_session_id", "scope": "eventDefinition" } ], "next": "/v1/attribute-definitions?scope=eventDefinition&eventName%5B%5D=page_viewed&eventName%5B%5D=flow_started&limit=3&cursor=cm9e922or000lmjao49o5mwwf", "previous": null } ``` -------------------------------- ### Content Session Object Example Source: https://docs.usertour.io/api-reference/content-sessions/model This example shows the structure of a content session object, including its ID, type, completion status, associated content, user, and version details. It is useful for understanding the data returned when retrieving or creating a content session. ```json { "id": "cm9l86wtk000zvy5q38v42053", "object": "contentSession", "answers": null, "completedAt": "2025-04-17T10:36:45.933Z", "completed": true, "contentId": "cm9f6vwed0002iejc4vg2zu3t", "content": { "id": "cm9f6vwed0002iejc4vg2zu3t", "object": "content", "name": "fff", "type": "flow", "editedVersionId": "cm9mkru2c000mlhmajx3l0146", "publishedVersionId": "cm9mjsv7d001bvfe8qe8tgzv9", "updatedAt": "2025-04-18T09:16:37.989Z", "createdAt": "2025-04-13T05:13:29.797Z" }, "createdAt": "2025-04-17T10:36:40.232Z", "companyId": null, "company": null, "isPreview": false, "lastActivityAt": "2025-04-17T10:36:45.933Z", "progress": 0, "userId": "1744886199938", "user": null, "versionId": "cm9l5txup007lv0gkyphk5l2j", "version": { "id": "cm9l5txup007lv0gkyphk5l2j", "object": "contentVersion", "number": 4, "updatedAt": "2025-04-17T09:30:35.794Z", "createdAt": "2025-04-17T09:30:35.794Z" } } ``` -------------------------------- ### Example Repository URL for Coolify Source: https://docs.usertour.io/open-source/coolify-deployment Use this repository URL when configuring your deployment in Coolify. It's recommended to clone this to your own repository for better control. ```text https://github.com/usertour/examples ``` -------------------------------- ### URL Path Example Source: https://docs.usertour.io/how-to-guides/urls Illustrates the path component of a URL. The path is the part after the domain and before query parameters or fragments. ```html https://my.app.com/acme-inc/dashboard?tab=analytics#charts \ | path ``` -------------------------------- ### URL Query Example Source: https://docs.usertour.io/how-to-guides/urls Highlights the query component of a URL. The query follows the path and is separated by '?', containing key-value pairs. ```html https://my.app.com/acme-inc/dashboard?tab=analytics#charts \___________/ | query ``` -------------------------------- ### Expand Memberships and Companies Source: https://docs.usertour.io/api-reference/expanding-objects This example demonstrates how to expand memberships, companies, and nested memberships.company in a single API request. It requires an API key for authentication. ```bash curl https://api.usertour.io/v1/users/1744521292871a?expand[]=memberships&expand[]=companies&expand[]=memberships.company \ -H 'Authorization: Bearer ' ``` -------------------------------- ### Local Development Environment Variables Source: https://docs.usertour.io/open-source/self-hosting Configure these environment variables in your .env file for the local development setup. ```env # Redis Configuration REDIS_HOST=redis REDIS_PORT=6379 REDIS_PASS= # PostgreSQL Configuration DATABASE_URL=postgresql://postgres:postgres@postgres:5432/usertour?schema=usertour&sslmode=prefer ``` -------------------------------- ### Simple Tour Button Actions Source: https://docs.usertour.io/use-cases/choose-between-two-tours Configure the 'Simple tour' button to dismiss the current chooser flow and start the 'Simple tour' flow. ```text Dismiss flow Start new flow/checklist: Simple tour ``` -------------------------------- ### Start Flow via URL Source: https://docs.usertour.io/how-to-guides/starting-flows Initiate a flow or checklist by constructing a URL with the flow ID. This is useful for creating links or buttons that trigger specific tours. ```text https://www.usertour.io/flows/?usertour=your_flow_id ``` ```text https://www.usertour.io/flows/?usertour=cmaw8v1ch013s147h0uw8aha5 ``` -------------------------------- ### Query Parameter Matching Source: https://docs.usertour.io/how-to-guides/urls Illustrates matching query parameters. Shows how to match specific values, values starting with certain text, or any value using wildcards. ```js // 1. Match values starting with specific text: // ?param=a* matches: // - ?param=apple // - ?param=admin // // But won't match: // - ?param=banana (doesn't start with 'a') // - ?param (no value) // - ?param2=apple (wrong parameter name) // 2. Match any value: // ?param=* matches: // - ?param=anything // - ?param (empty value is OK) // // But won't match: // - ?param2=value (wrong parameter) ``` -------------------------------- ### Production Setup Docker Compose Configuration Source: https://docs.usertour.io/open-source/self-hosting Simplified Docker Compose configuration for production. Assumes Redis and PostgreSQL are managed externally. ```yaml services: app: image: usertour/usertour:latest ports: - "8011:80" env_file: - .env restart: always ``` -------------------------------- ### User Creation Response Source: https://docs.usertour.io/api-reference/users/create This is an example of a successful response when creating a user. It includes the user's ID, object type, attributes, and creation timestamp. ```json { "id": "usr_123456789", "object": "user", "attributes": { "name": "John Doe", "email": "john.doe@example.com" }, "created_at": "2024-03-20T08:30:00.000Z" } ``` -------------------------------- ### Example Company Object Source: https://docs.usertour.io/api-reference/companies/model Illustrates the structure of a company object, including its ID, type, custom attributes, creation timestamp, associated users, and memberships. ```json { "id": "comp_123456789", "object": "company", "attributes": { "name": "Acme Corporation", "industry": "Technology", "employee_count": 500, "founded_at": "2020-01-01T00:00:00.000Z", "subscription_tier": "enterprise", "billing_country": "US" }, "createdAt": "2024-03-20T08:30:00.000Z", "users": [ { "id": "usr_987654321", "object": "user", "attributes": { "name": "John Doe", "email": "john.doe@acme.com", "role": "admin", "department": "engineering", "last_login_at": "2024-03-20T08:30:00.000Z" }, "createdAt": "2024-03-19T15:45:00.000Z" } ], "memberships": null } ``` -------------------------------- ### isStarted() Source: https://docs.usertour.io/developers/usertourjs-reference/content/is-started Checks if a specific Usertour content (flow or checklist) has been started. Returns true if started, false otherwise. ```APIDOC ## isStarted() ### Description Checks if a specific Usertour content has been started. Currently supports checking the status of flows and checklists. Returns a boolean value indicating the content's start status. ### Parameters #### Path Parameters - **contentId** (string) - Required - The unique identifier of the content. You can find this ID in the content detail page URL: `/env/{envId}/{contentType}/{contentId}/detail` ### Return `boolean` - Returns `true` if the content has been started, `false` if it hasn't been started yet. ### Example #### Basic Usage ```javascript const isContentStarted = usertour.isStarted('cmaw8v1ch013s147h0uw8aha5'); if (isContentStarted) { console.log('Content has been started'); } else { console.log('Content has not been started yet'); } ``` Make sure to call `init()` before using any other Usertour.js methods ``` -------------------------------- ### init() Source: https://docs.usertour.io/llms.txt Initializes the Usertour SDK with your environment token. ```APIDOC ## init(environmentToken) ### Description Initialize the Usertour SDK with your environment token. ### Method Not specified (SDK method) ### Endpoint Not applicable (SDK method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None #### SDK Parameters - **environmentToken** (string) - Required - Your Usertour environment token. ### Request Example ```javascript Usertour.init('YOUR_ENVIRONMENT_TOKEN'); ``` ### Response None ``` -------------------------------- ### init() Source: https://docs.usertour.io/developers/usertourjs-reference/setup/init Initializes the Usertour SDK with your environment token. This method must be called once per page load before making any other Usertour.js calls. ```APIDOC ## init() ### Description Initializes the Usertour SDK with your environment token. This method must be called once per page load before making any other Usertour.js calls. ### Parameters #### Path Parameters * **token** (string) - Required - Your Usertour environment token. You can find this token under [Settings → Environments](https://app.usertour.io/project/1/settings/environments). Each environment (e.g., Production, Staging) has its own unique token. ### Example ```javascript // Initialize the Usertour SDK with your environment token usertour.init('USERTOUR_TOKEN'); ``` ### Notes * The `init()` method must be called before any other Usertour.js methods * Each environment (Production, Staging, etc.) requires its own unique token * The token is used to identify your environment and load the correct configuration ``` -------------------------------- ### Check if Content is Started Source: https://docs.usertour.io/developers/usertourjs-reference/content/is-started Use this snippet to determine if a specific Usertour flow or checklist has been started by the user. Ensure Usertour.js has been initialized with `init()` before calling this method. ```javascript const isContentStarted = usertour.isStarted('cmaw8v1ch013s147h0uw8aha5'); if (isContentStarted) { console.log('Content has been started'); } else { console.log('Content has not been started yet'); } ``` -------------------------------- ### Configure Environment Variables Source: https://docs.usertour.io/open-source/local-development Copy example environment files and configure them for the web application, API server, and SDK. Update database and cache settings for the API server. ```bash # Web application cp apps/web/.env.example apps/web/.env # API server cp apps/server/.env.example apps/server/.env # Update Redis and PostgreSQL configuration in apps/server/.env # SDK cp apps/sdk/.env.example apps/sdk/.env ``` -------------------------------- ### Continue Flow From Last Seen Step Source: https://docs.usertour.io/use-cases/restart-onboarding-from-button To allow users to resume an onboarding flow from where they left off, use `usertour.start()` with the `continue: true` option. This is useful for providing a seamless continuation experience. ```javascript usertour.start("your_flow_id", { continue: true, }); ``` -------------------------------- ### Get a content Source: https://docs.usertour.io/llms.txt Retrieves a single content object by its ID. ```APIDOC ## GET /content/{content_id} ### Description Retrieves a single content object by its ID. ### Method GET ### Endpoint /content/{content_id} ``` -------------------------------- ### Get User Source: https://docs.usertour.io/llms.txt Retrieves a specific user by their ID, including all their attributes and relationships. ```APIDOC ## GET /users/{userId} ### Description Retrieves a specific user by their ID, including all their attributes and relationships. ### Method GET ### Endpoint /users/{userId} ### Parameters #### Path Parameters - **userId** (string) - Required - The ID of the user to retrieve. ### Response #### Success Response (200) - **id** (string) - The ID of the user. - **attributes** (object) - The attributes of the user. #### Response Example { "id": "user_123", "attributes": { "email": "test@example.com", "name": "Test User" } } ``` -------------------------------- ### Initialize and Identify User with Usertour.js (NPM) Source: https://docs.usertour.io/developers/usertourjs-reference/installation Import and initialize the Usertour SDK with your environment token, then identify the current user with their attributes. This snippet is used after installing via NPM. ```javascript import usertour from 'usertour.js'; // Initialize the Usertour SDK with your environment token usertour.init('USERTOUR_TOKEN'); // Identify the current user with their attributes usertour.identify('USER_ID', { name: 'USER_NAME', email: 'USER_EMAIL', signed_up_at: 'USER_SIGNED_UP_AT', }); ``` -------------------------------- ### Get a content version Source: https://docs.usertour.io/llms.txt Retrieves a specific version of a content object by its version ID. ```APIDOC ## GET /content-versions/{version_id} ### Description Retrieves a specific version of a content object by its version ID. ### Method GET ### Endpoint /content-versions/{version_id} ``` -------------------------------- ### Get a content session Source: https://docs.usertour.io/llms.txt Retrieves a specific content session by its ID, including all its attributes and relationships. ```APIDOC ## GET /content-sessions/{session_id} ### Description Retrieves a specific content session by its ID, including all its attributes and relationships. ### Method GET ### Endpoint /content-sessions/{session_id} ``` -------------------------------- ### Initialize and Identify User with Usertour.js Source: https://docs.usertour.io/developers/usertourjs-reference/overview Initialize the SDK with your Usertour.js token and identify the current user with their details. Replace placeholders with actual values. ```javascript import usertour from 'usertour.js'; // Initialize with your Usertour.js Token usertour.init(''); // Identify the current user usertour.identify('', { name: '', email: '', signed_up_at: '2023-06-14T16:25:49Z', }); ``` -------------------------------- ### User Object with Expanded Memberships and Companies Source: https://docs.usertour.io/api-reference/expanding-objects This example demonstrates how to fetch a user object and expand its associated memberships and companies, including nested expansion of the company within each membership. ```APIDOC ## GET /v1/users/{id} ### Description Retrieves a user object and allows for expansion of related objects like memberships and companies. ### Method GET ### Endpoint /v1/users/{id} ### Parameters #### Query Parameters - **expand** (array) - Optional - Specifies which related objects to expand. Can include nested paths using dot notation (e.g., `memberships.company`). ### Request Example ```bash curl https://api.usertour.io/v1/users/1744521292871a?expand[]=memberships&expand[]=companies&expand[]=memberships.company \ -H 'Authorization: Bearer ' ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier of the user. - **object** (string) - The type of object, 'user'. - **attributes** (object) - Additional attributes for the user. - **createdAt** (string) - The timestamp when the user was created. - **companies** (array) - An array of expanded company objects associated with the user. - **memberships** (array) - An array of expanded membership objects associated with the user. Each membership object may contain a nested 'company' object. #### Response Example ```json { "id": "1744521292871a", "object": "user", "attributes": {}, "createdAt": "2025-04-27T13:39:47.024Z", "companies": [ { "id": "1744521292871a", "object": "company", "attributes": {}, "createdAt": "2025-04-27T13:39:47.024Z" } ], "memberships": [ { "id": "cma9nhdis0002108kpmr9vfrl", "object": "companyMembership", "attributes": { "role": "admin" }, "createdAt": "2025-05-04T12:51:10.881Z", "companyId": "cm9zp4wyh00116pt4o5v5vg5t", "userId": "cm9zp4wyb000z6pt484wnbzs7", "company": { "id": "1744521292871a", "object": "company", "attributes": {}, "createdAt": "2025-04-27T13:39:47.024Z" } } ] } ``` ``` -------------------------------- ### URL Fragment Example Source: https://docs.usertour.io/how-to-guides/urls Identifies the fragment component of a URL, which comes after the '#' symbol and is often used in SPAs for client-side routing. ```html https://my.app.com/acme-inc/dashboard?tab=analytics#charts \____/ | fragment ``` -------------------------------- ### Install Usertour.js via HTML Snippet Source: https://docs.usertour.io/developers/usertourjs-reference/installation Add this script to your HTML file just before the closing tag for traditional web applications or Google Tag Manager integration. ```html !function(){var e="undefined"==typeof window?{}:window,r=e.usertour;if(!r){var t="https://js.usertour.io/",n=null;r=e.usertour={_stubbed:!0,load:function(){return n||(n=new Promise((function(r,o){var s=document.createElement("script");s.async=!0;var i=e.USERTOURJS_ENV_VARS||{};"es2020"===(i.USERTOURJS_BROWSER_TARGET||function(e){for(var r=[[/Edg\/|,Edg\/(\d+)/,80],[/OPR\/|,OPR\/(\d+)/,67],[/Chrome\/|,Chrome\/(\d+)/,80],[/CriOS\/|,CriOS\/(\d+)/,100],[/Safari\/|,Version\/(\d+)/,14],[/Firefox\/|,Firefox\/(\d+)/,74]],t=0;t=i)return"es2020";break}}return"legacy"}(navigator.userAgent))?(s.type="module",s.src=i.USERTOURJS_ES2020_URL||t+"es2020/usertour.js"):(s.src=i.USERTOURJS_LEGACY_URL||t+"legacy/usertour.iife.js"),s.onload=function(){r()},s.onerror=function(){document.head.removeChild(s),n=null;var e=new Error("Could not load Usertour.js");console.warn(e.message),o(e)},document.head.appendChild(s)}))),n}};var o=e.USERTOURJS_QUEUE=e.USERTOURJS_QUEUE||[],s=function(e){r[e]=function(){var t=Array.prototype.slice.call(arguments);r.load(),o.push([e,null,t])}},i=function(e){r[e]=function(){var t,n=Array.prototype.slice.call(arguments);r.load();var s=new Promise((function(e,r){t={resolve:e,reject:r}}));return o.push([e,t,n]),s}},u=function(e,t){r[e]=function(){return t}};s("disableEvalJs"),s("init"),s("off"),s("on"),s("registerCustomInput"),s("reset"),s("setBaseZIndex"),s("setSessionTimeout"),s("setTargetMissingSeconds"),s("setCustomInputSelector"),s("setCustomNavigate"),s("setCustomScrollIntoView"),s("setInferenceAttributeFilter"),s("setInferenceAttributeNames"),s("setInferenceClassNameFilter"),s("setScrollPadding"),s("setServerEndpoint"),s("setShadowDomEnabled"),s("setPageTrackingDisabled"),s("setUrlFilter"),s("setLinkUrlDecorator"),s("openResourceCenter"),s("closeResourceCenter"),s("toggleResourceCenter"),s("showResourceCenterLauncher"),s("hideResourceCenterLauncher"),i("endAll"),i("group"),i("identify"),i("identifyAnonymous"),i("start"),i("track"),i("updateGroup"),i("updateUser"),u("isIdentified",!1),u("isResourceCenterOpen",!1),u("isStarted",!1)}}(); // Initialize the Usertour SDK with your environment token usertour.init('USERTOUR_TOKEN'); // Identify the current user with their attributes usertour.identify('USER_ID', { name: 'USER_NAME', email: 'USER_EMAIL', signed_up_at: 'USER_SIGNED_UP_AT', }); ``` -------------------------------- ### Initialize Usertour SDK Source: https://docs.usertour.io/developers/usertourjs-reference/setup/init Call this method once per page load before any other Usertour.js calls. Ensure you use your specific environment token. ```javascript usertour.init('USERTOUR_TOKEN'); ``` -------------------------------- ### List Companies Response Source: https://docs.usertour.io/api-reference/companies/list Example JSON response when listing companies. It includes a list of company objects and pagination details. ```json { "results": [ { "id": "comp_123456789", "object": "company", "attributes": { "name": "Acme Corp", "domain": "acme.com", "industry": "Technology", "size": "100-500", "created_at": "2024-03-20T08:30:00.000Z" }, "createdAt": "2024-03-20T08:30:00.000Z", "updatedAt": "2024-03-20T08:30:00.000Z" }, { "id": "comp_987654321", "object": "company", "attributes": { "name": "TechStart Inc", "domain": "techstart.io", "industry": "Software", "size": "50-100", "created_at": "2024-03-19T15:45:00.000Z" }, "createdAt": "2024-03-19T15:45:00.000Z", "updatedAt": "2024-03-19T15:45:00.000Z" } ], "next": "/v1/companies?limit=2&cursor=comp_987654321", "previous": null } ``` -------------------------------- ### Get a user by ID Source: https://docs.usertour.io/api-reference/users/get Retrieves a specific user by their ID. You can optionally expand related data such as memberships and company details. ```APIDOC ## GET /v1/users/{id} ### Description Retrieves a specific user by their ID, including all their attributes and relationships. Supports expanding related objects. ### Method GET ### Endpoint /v1/users/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the user to retrieve. This ID should match the user's identifier in your system. #### Query Parameters - **expand** (string | string[]) - Optional - Specifies related objects to include in the response. Available options include `memberships`, `memberships.company`, and `companies`. Multiple expansions can be requested using array notation (e.g., `expand[]=memberships&expand[]=companies`). ### Request Example ```bash curl https://api.usertour.io/v1/users/usr_123456789?expand[]=memberships&expand[]=memberships.company&expand[]=companies \ -H 'Authorization: Bearer ak_123456789' \ -H 'Content-Type: application/json' ``` ### Response #### Success Response (200) Returns a user object if found. The user object includes `id`, `object`, `attributes`, `createdAt`, `companies`, and `memberships`. #### Response Example ```json { "id": "usr_123456789", "object": "user", "attributes": { "name": "John Doe", "email": "john.doe@example.com", "role": "admin", "department": "engineering", "signed_up_at": "2024-03-20T08:30:00.000Z" }, "createdAt": "2024-03-20T08:30:00.000Z", "companies": [ { "id": "comp_123456789", "object": "company", "attributes": { "name": "Acme Corp", "domain": "acme.com" }, "createdAt": "2024-03-20T08:30:00.000Z" } ], "memberships": [ { "id": "cma9nhdis0002108kpmr9vfrl", "object": "companyMembership", "attributes": { "role": "admin", "department": "engineering" }, "createdAt": "2024-03-20T08:30:00.000Z", "companyId": "comp_123456789", "userId": "usr_123456789", "company": { "id": "comp_123456789", "object": "company", "attributes": { "name": "Acme Corp", "domain": "acme.com" }, "createdAt": "2024-03-20T08:30:00.000Z" } } ] } ``` ``` -------------------------------- ### Restart Onboarding Button Click Handler Source: https://docs.usertour.io/use-cases/restart-onboarding-from-button Add a click event listener to a button to call `usertour.start()` with the flow ID when clicked. Ensure Usertour is initialized and the user is identified before this function is called. ```javascript document.querySelector("#restart-onboarding").addEventListener("click", () => { usertour.start("your_flow_id"); }); ``` -------------------------------- ### Get a company Source: https://docs.usertour.io/api-reference/companies/get Retrieve detailed information about a specific company. The endpoint returns a 404 Not Found response if the company does not exist. ```APIDOC ## GET /v1/companies/{id} ### Description Retrieve detailed information about a specific company. The endpoint returns a 404 Not Found response if the company does not exist. ### Method GET ### Endpoint /v1/companies/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the company to retrieve. This should match the ID format used in your system (e.g., `comp_123456789`). #### Query Parameters - **expand** (string) - Optional - Use this parameter to include related objects such as memberships and users in the response. ### Response #### Success Response (200) - **id** (string) - The unique identifier of the company. - **object** (string) - The type of object, which is 'company'. - **attributes** (object) - Company metadata and attributes. - **name** (string) - The name of the company. - **industry** (string) - The industry the company operates in. - **employee_count** (integer) - The number of employees in the company. - **subscription_tier** (string) - The subscription tier of the company. - **billing_country** (string) - The billing country of the company. - **founded_at** (string) - The founding date of the company in ISO 8601 format. - **createdAt** (string) - The creation timestamp of the company in ISO 8601 format. - **users** (array) - An array of user objects associated with the company (if expanded). - **memberships** (array) - An array of membership objects associated with the company (if expanded). #### Response Example ```json { "id": "comp_123456789", "object": "company", "attributes": { "name": "Acme Corporation", "industry": "Technology", "employee_count": 500, "subscription_tier": "enterprise", "billing_country": "US", "founded_at": "2020-01-01T00:00:00.000Z" }, "createdAt": "2024-03-20T08:30:00.000Z", "users": null, "memberships": null } ``` ```