> For the complete documentation index, see [llms.txt](https://docs.contextsdk.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.contextsdk.com/advanced/capturing-context-in-key-moments.md).

# Capturing Context In Key Moments

Learn how your app’s screens and user actions correlate with real-world user contexts.

Our SDK provides event tracking APIs to capture user interactions within your app, enabling insights into usage across real-world contexts.

Logging these events is optional and for informational purposes only. It will not influence your app's behavior.

### Page Views

Track when users navigate between different screens. This data helps you understand which screens users interact with most frequently in various real-world contexts.

{% tabs %}
{% tab title="Swift" %}

```swift
ContextManager.trackPageView("page_identifier")
```

{% endtab %}

{% tab title="Android" %}

```kotlin
ContextSDK.trackPageView("page_identifier");
```

{% endtab %}

{% tab title="Flutter" %}

```dart
_contextSdkPlugin.trackPageView("page_identifier");
```

{% endtab %}

{% tab title="Unity" %}

```csharp
ContextSDKBinding.TrackPageView("page_identifier");
```

{% endtab %}

{% tab title="React Native" %}

```javascript
import { trackPageView } from 'react-native-context-sdk';

trackPageView("page_identifier");
```

{% endtab %}
{% endtabs %}

### User Actions

Record specific user actions, such as enabling a feature, tapping buttons, creating accounts, or sharing content. Capturing these events helps you gain insights into how user interactions correlate with different real-world scenarios.

{% tabs %}
{% tab title="Swift" %}

```swift
ContextManager.trackUserAction("user_tapped_share_button")
```

{% endtab %}

{% tab title="Android" %}

```kotlin
ContextSDK.trackUserAction("user_tapped_share_button");
```

{% endtab %}

{% tab title="Flutter" %}

```dart
_contextSdkPlugin.trackUserAction("user_tapped_share_button");
```

{% endtab %}

{% tab title="Unity" %}

```csharp
ContextSDKBinding.TrackUserAction("user_tapped_share_button");
```

{% endtab %}

{% tab title="React Native" %}

```javascript
import { trackUserAction } from 'react-native-context-sdk';

trackUserAction("user_tapped_share_button");
```

{% endtab %}
{% endtabs %}

### Generic Events

Track custom events that don't fall under the other categories. Alternatively, add this to your existing analytics code to easily log all your existing events into ContextSDK, allowing us to provide you insights without much effort.

{% tabs %}
{% tab title="Swift" %}

```swift
ContextManager.trackEvent("custom_event")
```

{% endtab %}

{% tab title="Android" %}

```kotlin
ContextSDK.trackEvent("custom_event");
```

{% endtab %}

{% tab title="Flutter" %}

```dart
_contextSdkPlugin.trackEvent("custom_event");
```

{% endtab %}

{% tab title="Unity" %}

```csharp
ContextSDKBinding.TrackEvent("custom_event");
```

{% endtab %}

{% tab title="React Native" %}

```javascript
import { trackEvent } from 'react-native-context-sdk';

trackEvent("custom_event");
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.contextsdk.com/advanced/capturing-context-in-key-moments.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
