Skip to content

Commit

Permalink
fix: Fix tracking referrer field by making it fillable in Analytics m…
Browse files Browse the repository at this point in the history
…odel
  • Loading branch information
owenconti committed Jul 7, 2022
1 parent b433113 commit 033cbb9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Models/Analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function getTable()
}

protected $fillable = [
'user_id', 'path', 'method', 'status_code', 'duration_ms', 'user_agent', 'query_params', 'ip_address', 'host'
'user_id', 'path', 'method', 'status_code', 'duration_ms', 'user_agent', 'query_params', 'ip_address', 'referrer', 'host'
];

protected $casts = [
Expand All @@ -35,7 +35,7 @@ public function addRelation(Model $entity, ?string $reason = null): AnalyticsRel
]);
$relation->relation()->associate($entity);
$this->relations()->save($relation);

return $relation;
}

Expand Down
5 changes: 3 additions & 2 deletions tests/AnalyticsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AnalyticsTest extends TestCase
public function it_tracks_a_request()
{
// When
$this->get('/analytics');
$this->withHeader('referer', 'https://google.com')->get('/analytics');

// Then
$this->assertDatabaseHas(ServerAnalytics::getAnalyticsDataTable(), [
Expand All @@ -24,6 +24,7 @@ public function it_tracks_a_request()
'status_code' => '200',
'user_agent' => 'Symfony',
'ip_address' => '127.0.0.1',
'referrer' => 'https://google.com',
'query_params' => json_encode([])
]);
}
Expand Down Expand Up @@ -69,7 +70,7 @@ public function it_tracks_authenticated_user_with_request()
{
// Given
$user = factory(User::class)->create();

// When
$this->be($user)->get('/api/analytics');

Expand Down

0 comments on commit 033cbb9

Please sign in to comment.