Fetching Session Users
Ductape allows you to retrieve users associated with a specific session in your product. This is useful for analytics, auditing, or managing user access and activity within sessions.
Fetch All Users for a Session
To fetch all users associated with a particular session, use ductape.sessions.fetchUsers(). It returns paginated results.
Example
import Ductape from '@ductape/sdk';
const ductape = new Ductape({
accessKey: 'your-access-key',
env_type: 'prd',
});
const result = await ductape.sessions.fetchUsers({
product: 'my-product',
session: 'user-session',
env: 'prd', // Optional: filter by environment
page: 1,
limit: 20,
});
console.log('Total users:', result.total);
console.log('Total pages:', result.totalPages);
for (const user of result.users) {
console.log('User ID:', user.ductape_user_id);
console.log('Identifier:', user.identifier);
console.log('Last seen:', user.last_seen);
}
Parameters
| Field | Type | Required | Description |
|---|---|---|---|
product | string | Yes | The tag of your product. |
session | string | Yes | The tag of the session to query users from. |
env | string | No | Filter by environment (e.g., 'production'). |
page | number | No | The page number for pagination (default: 1). |
limit | number | No | The number of users per page (default: 20). |
Response
Returns a paginated result object:
{
users: ISessionUser[]; // Array of user objects
total: number; // Total number of users
page: number; // Current page
limit: number; // Users per page
totalPages: number; // Total number of pages
}
Each user object includes:
_id- MongoDB document IDductape_user_id- Unique Ductape user identifierproduct_tag- The product tagsession_tag- The session tagidentifier- User identifier (from session selector)env- Environmentfirst_seen- First session timestamplast_seen- Most recent activity timestampcreatedAt- Record creation timestampupdatedAt- Record update timestamp
Fetch a Specific User's Details
Get detailed information about a specific session user, including their session history:
const userDetails = await ductape.sessions.fetchUserDetails({
product: 'my-product',
session: 'user-session',
identifier: 'user@example.com',
env: 'prd', // Optional
});
console.log('User ID:', userDetails.ductape_user_id);
console.log('Total sessions:', userDetails.totalSessions);
console.log('Active sessions:', userDetails.activeSessionsCount);
// View session history
for (const session of userDetails.sessions) {
console.log('Session ID:', session.session_id);
console.log('Started:', session.start_at);
console.log('Expires:', session.end_at);
console.log('Active:', session.active);
}
Parameters
| Field | Type | Required | Description |
|---|---|---|---|
product | string | Yes | The tag of your product. |
session | string | Yes | The tag of the session. |
identifier | string | Yes | The user's unique identifier. |
env | string | No | Filter by environment. |
Response
Returns the user object with additional session information:
{
// All ISessionUser fields plus:
sessions: IUserSessionInfo[]; // Array of session records
totalSessions: number; // Total number of sessions
activeSessionsCount: number; // Currently active sessions
}
Each session info object includes:
session_id- Unique session identifierstart_at- Session start timestampend_at- Session expiry timestampactive- Whether the session is currently active
All of these methods are on ductape.sessions after initializing Ductape with your access key:
// Fetch paginated users
const users = await ductape.sessions.fetchUsers({
product: 'my-product',
session: 'user-session',
env: 'prd',
page: 1,
limit: 20,
});
// Fetch specific user details
const userDetails = await ductape.sessions.fetchUserDetails({
product: 'my-product',
session: 'user-session',
identifier: 'user@example.com',
env: 'prd',
});
// Fetch dashboard metrics
const dashboard = await ductape.sessions.fetchDashboard({
product: 'my-product',
session: 'user-session',
env: 'prd',
});