> ## Documentation Index
> Fetch the complete documentation index at: https://docs.spendowl.io/llms.txt
> Use this file to discover all available pages before exploring further.

# SpendOwl

> Main SDK class reference

# SpendOwl

The main entry point for the SpendOwl SDK. All methods are static—you don't need to create an instance.

```swift theme={null}
import SpendOwl
```

## Configuration Methods

### configure(apiKey:)

Configures the SDK with your API key.

```swift theme={null}
public static func configure(apiKey: String)
```

<ParamField path="apiKey" type="String" required>
  Your SpendOwl API key from the [dashboard](https://spendowl.io/dashboard).
</ParamField>

**Example:**

```swift theme={null}
SpendOwl.configure(apiKey: "spendowl_live_xxx")
```

<Note>
  Call this once during app launch. Subsequent calls are ignored.
</Note>

***

### configure(\_:)

Configures the SDK with custom options.

```swift theme={null}
public static func configure(_ configuration: SpendOwlConfiguration)
```

<ParamField path="configuration" type="SpendOwlConfiguration" required>
  Configuration options including API key, timeout, and retry settings.
</ParamField>

**Example:**

```swift theme={null}
let config = SpendOwlConfiguration(
    apiKey: "spendowl_live_xxx",
    timeoutInterval: 30,
    maxRetries: 5
)
SpendOwl.configure(config)
```

***

## Attribution Methods

### attribution() async throws

Fetches attribution data asynchronously.

```swift theme={null}
public static func attribution() async throws -> AttributionResult
```

**Returns:** `AttributionResult` containing campaign, ad group, and keyword data.

**Throws:** `SpendOwlError` if attribution fails.

**Example:**

```swift theme={null}
Task {
    do {
        let attribution = try await SpendOwl.attribution()
        print("Campaign: \(attribution.campaignName ?? "organic")")
    } catch {
        print("Error: \(error)")
    }
}
```

***

### attribution(completion:)

Fetches attribution data using a completion handler.

```swift theme={null}
public static func attribution(
    completion: ((Result<AttributionResult, SpendOwlError>) -> Void)? = nil
)
```

<ParamField path="completion" type="Closure" default="nil">
  Called with the attribution result. May be called on any queue.
</ParamField>

**Example:**

```swift theme={null}
SpendOwl.attribution { result in
    switch result {
    case .success(let attribution):
        print("Status: \(attribution.status)")
    case .failure(let error):
        print("Error: \(error)")
    }
}
```

***

## User Identity Methods

### setUserId(\_:)

Sets the user ID for attribution and purchase tracking.

```swift theme={null}
public static func setUserId(_ userId: String)
```

<ParamField path="userId" type="String" required>
  Your internal user identifier (e.g., database ID, UUID).
</ParamField>

**Example:**

```swift theme={null}
SpendOwl.setUserId("user-123")
```

<Note>
  The user ID is included with all subsequent attribution and purchase events.
</Note>

***

### clearUserId()

Clears the current user ID.

```swift theme={null}
public static func clearUserId()
```

**Example:**

```swift theme={null}
SpendOwl.clearUserId()
```

***

## Properties

### enableLogging

Enables or disables debug logging.

```swift theme={null}
public static var enableLogging: Bool { get set }
```

**Default:** `false`

**Example:**

```swift theme={null}
SpendOwl.enableLogging = true
```

<Warning>
  Disable logging in production. Logs may contain sensitive information.
</Warning>

***

### logLevel

The current log level for granular control.

```swift theme={null}
public static var logLevel: Logger.Level { get set }
```

**Values:**

| Level    | Description                       |
| -------- | --------------------------------- |
| `.none`  | No logging (default)              |
| `.error` | Only errors                       |
| `.info`  | Errors and important events       |
| `.debug` | All messages including debug info |

**Example:**

```swift theme={null}
SpendOwl.logLevel = .debug
```

***

### isConfigured

Returns `true` if the SDK is configured and ready.

```swift theme={null}
public static var isConfigured: Bool { get }
```

**Example:**

```swift theme={null}
if SpendOwl.isConfigured {
    let attribution = try await SpendOwl.attribution()
}
```

***

### sdkVersion

The current SDK version string.

```swift theme={null}
public static var sdkVersion: String { get }
```

**Example:**

```swift theme={null}
print(SpendOwl.sdkVersion) // "1.0.0"
```

***

## Platform Availability

```swift theme={null}
@available(iOS 15.0, macOS 12.0, *)
public final class SpendOwl
```

## Thread Safety

The `SpendOwl` class is thread-safe (`Sendable`). All methods can be called from any thread.

## Related Types

<CardGroup cols={2}>
  <Card title="SpendOwlConfiguration" icon="gear" href="/api-reference/configuration">
    Configuration options
  </Card>

  <Card title="AttributionResult" icon="bullseye" href="/api-reference/attribution-result">
    Attribution data structure
  </Card>

  <Card title="SpendOwlError" icon="circle-exclamation" href="/api-reference/errors">
    Error types
  </Card>
</CardGroup>
