Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions basics/angular/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,7 @@ posthogService.posthog.capture('burrito_considered', {
### Error tracking (pages/profile/profile.component.ts)

```typescript
posthogService.posthog.capture('$exception', {
$exception_message: error.message,
$exception_type: error.name,
$exception_stack_trace_raw: error.stack,
});
posthogService.posthog.captureException(error);
```

## Angular-specific details
Expand Down
6 changes: 1 addition & 5 deletions basics/angular/src/app/pages/profile/profile.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,7 @@ export class ProfileComponent {
throw new Error('Test error for PostHog error tracking');
} catch (err) {
const error = err as Error;
this.posthogService.posthog.capture('$exception', {
$exception_message: error.message,
$exception_type: error.name,
$exception_stack_trace_raw: error.stack,
});
this.posthogService.posthog.captureException(error);
console.error('Captured error:', err);
alert('Error captured and sent to PostHog!');
}
Expand Down
8 changes: 2 additions & 6 deletions basics/expo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ A React Native Expo app demonstrating PostHog product analytics integration with

- **Product Analytics**: Full PostHog integration with event tracking
- **Autocapture**: Touch events and screen tracking
- **Error Tracking**: Manual exception capture with `$exception` events
- **Error Tracking**: Manual exception capture with `captureException`
- **User Authentication**: Demo login with PostHog user identification
- **Session Persistence**: AsyncStorage for session management
- **Modern React**: React 19 with React Compiler for automatic memoization
Expand Down Expand Up @@ -147,11 +147,7 @@ useEffect(() => {
Manual exception capture:

```typescript
posthog.capture('$exception', {
$exception_type: error.name,
$exception_message: error.message,
$exception_stack_trace_raw: error.stack,
})
posthog.captureException(error)
```

## Modern React Features
Expand Down
17 changes: 2 additions & 15 deletions basics/expo/app/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function ProfileScreen() {
/**
* Triggers a test error and captures it in PostHog
*
* This demonstrates manual exception capture using the $exception event.
* This demonstrates manual exception capture via captureException.
* In production, you would typically set up automatic exception capture
* or use the before_send callback for customization.
*
Expand All @@ -44,21 +44,8 @@ export default function ProfileScreen() {
} catch (err) {
const error = err as Error

// Capture exception in PostHog
// @see https://posthog.com/docs/error-tracking
posthog.capture('$exception', {
$exception_list: [
{
type: error.name,
value: error.message,
stacktrace: {
type: 'raw',
frames: error.stack ?? '',
},
},
],
$exception_source: 'react-native',
// Additional context
posthog.captureException(error, {
username: user.username,
screen: 'Profile',
})
Expand Down
7 changes: 1 addition & 6 deletions basics/laravel/app/Services/PostHogService.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,8 @@ public function captureException(\Throwable $exception, ?string $distinctId = nu

$eventId = uniqid('error_', true);

$this->capture($distinctId, '$exception', [
PostHog::captureException($exception, $distinctId, [
'error_id' => $eventId,
'exception_type' => get_class($exception),
'exception_message' => $exception->getMessage(),
'exception_file' => $exception->getFile(),
'exception_line' => $exception->getLine(),
'stack_trace' => $exception->getTraceAsString(),
]);

return $eventId;
Expand Down
2 changes: 1 addition & 1 deletion basics/laravel/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"php": "^8.2",
"laravel/framework": "^11.0",
"livewire/livewire": "^4.0",
"posthog/posthog-php": "^4.0"
"posthog/posthog-php": "^4.2"
},
"autoload": {
"psr-4": {
Expand Down
14 changes: 7 additions & 7 deletions basics/laravel/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 2 additions & 7 deletions basics/react-native/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ posthog.capture('burrito_considered', {

### Error tracking (screens/ProfileScreen.tsx)

Capture exceptions using the `$exception` event:
Capture exceptions using `captureException`:

```typescript
import { usePostHog } from 'posthog-react-native'
Expand All @@ -336,12 +336,7 @@ const posthog = usePostHog()
try {
throw new Error('Test error for PostHog error tracking')
} catch (err) {
posthog.capture('$exception', {
$exception_type: err.name,
$exception_message: err.message,
$exception_source: 'ProfileScreen',
$exception_stack_trace_raw: err.stack,
})
posthog.captureException(err)
}
```

Expand Down
11 changes: 2 additions & 9 deletions basics/react-native/src/screens/ProfileScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default function ProfileScreen() {
/**
* Triggers a test error and captures it in PostHog
*
* This demonstrates manual exception capture using the $exception event.
* This demonstrates manual exception capture via captureException.
* In production, you would typically set up automatic exception capture
* or use the before_send callback for customization.
*
Expand All @@ -57,14 +57,7 @@ export default function ProfileScreen() {
} catch (err) {
const error = err as Error

// Capture exception in PostHog using the $exception event
// This follows PostHog's error tracking format
posthog.capture('$exception', {
$exception_type: error.name,
$exception_message: error.message,
$exception_source: 'ProfileScreen.triggerTestError',
$exception_stack_trace_raw: error.stack,
// Additional context
posthog.captureException(error, {
username: user.username,
screen: 'Profile',
})
Expand Down
2 changes: 1 addition & 1 deletion basics/ruby/Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source 'https://rubygems.org'

gem 'posthog-ruby', '~> 3.0'
gem 'posthog-ruby', '~> 3.3'
gem 'dotenv', '~> 3.0'
14 changes: 1 addition & 13 deletions basics/ruby/todo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,19 +252,7 @@ def print_usage
puts "ERROR: #{e.message}"

# Manually capture handled errors
posthog&.capture(
distinct_id: get_user_id,
event: '$exception',
properties: {
'$exception_type' => e.class.name,
'$exception_message' => e.message,
'$exception_list' => [{
'type' => e.class.name,
'value' => e.message,
'stacktrace' => { 'frames' => (e.backtrace || []).first(10).map { |line| { 'filename' => line } } }
}]
}
)
posthog&.capture_exception(e, get_user_id)

exit 1
ensure
Expand Down
Loading