Activity Log

Audit trail of all account and site activities

Overview

The Activity Log provides a complete audit trail of all actions performed on your Zero Trust Analytics account. Track who did what, when they did it, and from where. Essential for security, compliance, and debugging.

Logged activities:

  • User logins and logouts
  • Site creation, updates, and deletion
  • Team member invitations and removals
  • API key creation and revocation
  • Goal and funnel changes
  • Alert triggers
  • Settings modifications
  • Data exports

Endpoint

GET /api/activity-log

Requires authentication. See Authentication.

Get Activity Log

Retrieve the activity log for your account or a specific site.

Request

curl "https://ztas.io/api/activity-log?siteId=site_abc123&period=7d&limit=50" \
  -H "Authorization: Bearer YOUR_TOKEN"

Parameters

ParameterTypeRequiredDescription
siteIdstringNoFilter by site ID (omit for account-wide log)
periodstringNoTime period: 24h, 7d, 30d, 90d (default: 7d)
startDatestringNoCustom start date (ISO 8601)
endDatestringNoCustom end date (ISO 8601)
typestringNoFilter by activity type (see below)
userIdstringNoFilter by user ID
limitnumberNoMaximum number of entries (default: 50, max: 100)
offsetnumberNoOffset for pagination (default: 0)

Activity Types

Filter by specific activity types:

TypeDescription
authLogin, logout, password changes
siteSite creation, updates, deletion
teamTeam member invitations, removals, role changes
api_keyAPI key creation, usage, revocation
goalGoal creation, updates, deletion
funnelFunnel creation, updates, deletion
alertAlert creation, triggers, deletion
webhookWebhook creation, delivery, deletion
exportData export requests
settingsSettings changes

Response

{
  "activities": [
    {
      "id": "activity_abc123",
      "timestamp": "2024-12-12T16:30:00.000Z",
      "type": "site",
      "action": "site.created",
      "actor": {
        "id": "user_abc123",
        "email": "user@example.com",
        "name": "Alice Johnson"
      },
      "target": {
        "type": "site",
        "id": "site_abc123",
        "name": "example.com"
      },
      "metadata": {
        "domain": "example.com",
        "timezone": "America/New_York"
      },
      "ipAddress": "192.168.1.1",
      "userAgent": "Mozilla/5.0..."
    },
    {
      "id": "activity_def456",
      "timestamp": "2024-12-12T15:45:00.000Z",
      "type": "team",
      "action": "team.member_invited",
      "actor": {
        "id": "user_abc123",
        "email": "user@example.com",
        "name": "Alice Johnson"
      },
      "target": {
        "type": "user",
        "email": "newmember@example.com"
      },
      "metadata": {
        "role": "admin",
        "siteId": "site_abc123"
      },
      "ipAddress": "192.168.1.1",
      "userAgent": "Mozilla/5.0..."
    },
    {
      "id": "activity_xyz789",
      "timestamp": "2024-12-12T14:20:00.000Z",
      "type": "alert",
      "action": "alert.triggered",
      "target": {
        "type": "alert",
        "id": "alert_abc123",
        "name": "Traffic Spike"
      },
      "metadata": {
        "metric": "pageviews",
        "currentValue": 1543,
        "threshold": 1000,
        "siteId": "site_abc123"
      }
    }
  ],
  "pagination": {
    "total": 234,
    "limit": 50,
    "offset": 0,
    "hasMore": true
  }
}

Activity Actions

Authentication Actions

ActionDescription
auth.loginUser logged in
auth.logoutUser logged out
auth.password_changedPassword was changed
auth.password_resetPassword was reset via email
auth.failed_loginFailed login attempt
auth.2fa_enabledTwo-factor authentication enabled
auth.2fa_disabledTwo-factor authentication disabled

Site Actions

ActionDescription
site.createdNew site created
site.updatedSite settings updated
site.deletedSite deleted
site.verifiedDomain ownership verified

Team Actions

ActionDescription
team.member_invitedTeam member invitation sent
team.member_acceptedInvitation accepted
team.member_removedTeam member removed
team.role_changedMember role changed

API Key Actions

ActionDescription
api_key.createdAPI key created
api_key.usedAPI key used for authentication
api_key.revokedAPI key revoked

Goal Actions

ActionDescription
goal.createdGoal created
goal.updatedGoal settings updated
goal.deletedGoal deleted

Funnel Actions

ActionDescription
funnel.createdFunnel created
funnel.updatedFunnel settings updated
funnel.deletedFunnel deleted

Alert Actions

ActionDescription
alert.createdAlert created
alert.triggeredAlert triggered
alert.acknowledgedAlert acknowledged
alert.deletedAlert deleted

Webhook Actions

ActionDescription
webhook.createdWebhook created
webhook.deliveredWebhook successfully delivered
webhook.failedWebhook delivery failed
webhook.deletedWebhook deleted

Export Actions

ActionDescription
export.requestedData export requested
export.completedExport ready for download
export.downloadedExport file downloaded

Settings Actions

ActionDescription
settings.updatedAccount or site settings updated
settings.integration_connectedThird-party integration connected
settings.integration_disconnectedThird-party integration disconnected

Filtering Examples

Recent Logins

curl "https://ztas.io/api/activity-log?type=auth&action=auth.login&period=30d" \
  -H "Authorization: Bearer YOUR_TOKEN"

Failed Login Attempts

curl "https://ztas.io/api/activity-log?type=auth&action=auth.failed_login&period=7d" \
  -H "Authorization: Bearer YOUR_TOKEN"

API Key Usage

curl "https://ztas.io/api/activity-log?type=api_key&period=24h" \
  -H "Authorization: Bearer YOUR_TOKEN"

Team Changes

curl "https://ztas.io/api/activity-log?type=team&period=30d" \
  -H "Authorization: Bearer YOUR_TOKEN"

Alert Triggers

curl "https://ztas.io/api/activity-log?type=alert&action=alert.triggered&period=7d" \
  -H "Authorization: Bearer YOUR_TOKEN"

Site-Specific Activity

curl "https://ztas.io/api/activity-log?siteId=site_abc123&period=30d" \
  -H "Authorization: Bearer YOUR_TOKEN"

User-Specific Activity

curl "https://ztas.io/api/activity-log?userId=user_abc123&period=30d" \
  -H "Authorization: Bearer YOUR_TOKEN"

Pagination

For large result sets, use pagination:

# First page (50 results)
curl "https://ztas.io/api/activity-log?limit=50&offset=0" \
  -H "Authorization: Bearer YOUR_TOKEN"

# Second page (next 50 results)
curl "https://ztas.io/api/activity-log?limit=50&offset=50" \
  -H "Authorization: Bearer YOUR_TOKEN"

# Third page
curl "https://ztas.io/api/activity-log?limit=50&offset=100" \
  -H "Authorization: Bearer YOUR_TOKEN"

Export Activity Log

Export the entire activity log to CSV:

curl "https://ztas.io/api/activity-log/export?period=90d&format=csv" \
  -H "Authorization: Bearer YOUR_TOKEN"

Returns a download URL for a CSV file containing all activity log entries.

CSV Format

Timestamp,Type,Action,Actor Email,Actor Name,Target Type,Target ID,IP Address,User Agent
2024-12-12T16:30:00.000Z,site,site.created,user@example.com,Alice Johnson,site,site_abc123,192.168.1.1,Mozilla/5.0...
2024-12-12T15:45:00.000Z,team,team.member_invited,user@example.com,Alice Johnson,user,newmember@example.com,192.168.1.1,Mozilla/5.0...

Real-time Activity Feed

Subscribe to real-time activity updates via webhooks:

curl -X POST "https://ztas.io/api/webhooks" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "siteId": "site_abc123",
    "url": "https://your-server.com/webhook",
    "events": ["activity"]
  }'

Webhook payload:

{
  "event": "activity",
  "timestamp": "2024-12-12T16:30:00.000Z",
  "data": {
    "id": "activity_abc123",
    "type": "team",
    "action": "team.member_invited",
    "actor": {
      "id": "user_abc123",
      "email": "user@example.com"
    },
    "target": {
      "type": "user",
      "email": "newmember@example.com"
    }
  }
}

Retention

Activity logs are retained based on your plan:

PlanRetention Period
Free30 days
Pro90 days
Business1 year
Enterprise2 years

Use Cases

1. Security Monitoring

Monitor for suspicious activity:

# Failed login attempts
curl "https://ztas.io/api/activity-log?type=auth&action=auth.failed_login" \
  -H "Authorization: Bearer YOUR_TOKEN"

# API key usage from unexpected IPs
curl "https://ztas.io/api/activity-log?type=api_key&action=api_key.used" \
  -H "Authorization: Bearer YOUR_TOKEN"

2. Compliance Auditing

Generate compliance reports:

# All team changes in the last 90 days
curl "https://ztas.io/api/activity-log?type=team&period=90d" \
  -H "Authorization: Bearer YOUR_TOKEN"

# All data exports
curl "https://ztas.io/api/activity-log?type=export&period=365d" \
  -H "Authorization: Bearer YOUR_TOKEN"

3. Debugging

Troubleshoot issues:

# Recent webhook failures
curl "https://ztas.io/api/activity-log?type=webhook&action=webhook.failed&period=7d" \
  -H "Authorization: Bearer YOUR_TOKEN"

# Recent alert triggers
curl "https://ztas.io/api/activity-log?type=alert&action=alert.triggered&period=24h" \
  -H "Authorization: Bearer YOUR_TOKEN"

4. User Activity Tracking

Track what team members are doing:

# Activity by specific user
curl "https://ztas.io/api/activity-log?userId=user_abc123&period=30d" \
  -H "Authorization: Bearer YOUR_TOKEN"

Error Responses

400 Bad Request

{
  "error": "Invalid time period"
}
{
  "error": "Invalid activity type"
}
{
  "error": "Limit must be between 1 and 100"
}

403 Forbidden

{
  "error": "Access denied. Only account owners can view the activity log."
}

404 Not Found

{
  "error": "Site not found"
}

Best Practices

1. Regular Reviews

Review activity logs regularly:

# Weekly security review
curl "https://ztas.io/api/activity-log?type=auth&period=7d" \
  -H "Authorization: Bearer YOUR_TOKEN"

2. Monitor Failed Logins

Set up alerts for failed login attempts:

# Alert on 5+ failed logins in 1 hour
curl -X POST "https://ztas.io/api/alerts" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Multiple Failed Logins",
    "type": "threshold",
    "metric": "activity.auth.failed_login.count",
    "operator": ">",
    "threshold": 5,
    "period": "1h"
  }'

3. Export for Long-term Storage

Export logs before they’re deleted:

# Export logs quarterly for compliance
curl "https://ztas.io/api/activity-log/export?period=90d&format=csv" \
  -H "Authorization: Bearer YOUR_TOKEN"

4. Correlate with Other Data

Cross-reference activity with analytics:

# Check if a site deletion corresponded with a traffic drop
curl "https://ztas.io/api/activity-log?type=site&action=site.deleted" \
  -H "Authorization: Bearer YOUR_TOKEN"

curl "https://ztas.io/api/stats?siteId=site_abc123&period=30d" \
  -H "Authorization: Bearer YOUR_TOKEN"

5. Track Team Productivity

Monitor team member contributions:

# Goals created by each team member
curl "https://ztas.io/api/activity-log?type=goal&action=goal.created&period=30d" \
  -H "Authorization: Bearer YOUR_TOKEN"

Example: Security Dashboard

Build a security monitoring dashboard:

const API_KEY = 'zta_live_abc123...';

async function getSecurityMetrics() {
  // Failed logins
  const failedLogins = await fetch(
    'https://ztas.io/api/activity-log?type=auth&action=auth.failed_login&period=24h',
    { headers: { 'Authorization': `Bearer ${API_KEY}` } }
  ).then(r => r.json());

  // API key usage
  const apiKeyUsage = await fetch(
    'https://ztas.io/api/activity-log?type=api_key&period=24h',
    { headers: { 'Authorization': `Bearer ${API_KEY}` } }
  ).then(r => r.json());

  // Team changes
  const teamChanges = await fetch(
    'https://ztas.io/api/activity-log?type=team&period=7d',
    { headers: { 'Authorization': `Bearer ${API_KEY}` } }
  ).then(r => r.json());

  return {
    failedLogins: failedLogins.activities.length,
    apiKeyRequests: apiKeyUsage.activities.length,
    teamChanges: teamChanges.activities.length
  };
}

// Display on dashboard
getSecurityMetrics().then(metrics => {
  console.log('Security Metrics (24h):');
  console.log(`- Failed logins: ${metrics.failedLogins}`);
  console.log(`- API requests: ${metrics.apiKeyRequests}`);
  console.log(`- Team changes: ${metrics.teamChanges}`);
});

Example: Compliance Report

Generate a monthly compliance report:

import requests
from datetime import datetime, timedelta

API_KEY = 'zta_live_abc123...'

# Get last month's activity
end_date = datetime.now().replace(day=1) - timedelta(days=1)
start_date = end_date.replace(day=1)

response = requests.get(
    'https://ztas.io/api/activity-log',
    params={
        'startDate': start_date.isoformat(),
        'endDate': end_date.isoformat()
    },
    headers={'Authorization': f'Bearer {API_KEY}'}
)

activities = response.json()['activities']

# Generate report
report = {
    'period': f"{start_date.strftime('%B %Y')}",
    'total_activities': len(activities),
    'by_type': {}
}

for activity in activities:
    activity_type = activity['type']
    report['by_type'][activity_type] = report['by_type'].get(activity_type, 0) + 1

print(f"Compliance Report - {report['period']}")
print(f"Total Activities: {report['total_activities']}")
print("\nBreakdown by Type:")
for activity_type, count in report['by_type'].items():
    print(f"  {activity_type}: {count}")