-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Added new top referrers endpoint for post analytics #23149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
cmraible
merged 16 commits into
main
from
chris-prod-1542-adjust-conversion-attribution-to-reflect-free-members-paid
May 6, 2025
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
bb1cc72
Added updated attribution endpoint and hooked it up to Post Analytics…
cmraible 7b0b5b5
Moved new endpoint into PostsStatsService and updated endpoint
cmraible 672fee0
Fixed endpoint response fields
cmraible 6150315
Renamed the method and added referrer_source to tests
cmraible d71a6ca
Fixed linter error
cmraible eaa4211
Added tests and implementation for getReferrersForPost method
cmraible 7231348
Added test for date filtering
cmraible 1697141
Added test for the limit option
cmraible 5474b6f
Replaced hardcoded postId with parameter
cmraible a2ea7a5
Moved endpoint from /stats/referrers/posts/:id/alpha to /stats/posts/…
cmraible e8f700f
Added an e2e smoke test
cmraible de69358
fixup! Added an e2e smoke test
cmraible 9c50a45
Added validation for post id
cmraible f21ab8c
Reset totals on post analytics to static values
cmraible 2f06379
fixup! Reset totals on post analytics to static values
cmraible 83bb760
fixup! fixup! Reset totals on post analytics to static values
cmraible File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {useMemo} from 'react'; | ||
import {usePostReferrers as usePostReferrersAPI} from '@tryghost/admin-x-framework/api/stats'; | ||
|
||
export const usePostReferrers = (postId: string) => { | ||
const {data: postReferrerResponse, isLoading} = usePostReferrersAPI(postId); | ||
const stats = useMemo(() => postReferrerResponse?.stats || [], [postReferrerResponse]); | ||
|
||
return { | ||
isLoading, | ||
stats | ||
}; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,26 +4,18 @@ import PostAnalyticsContent from './components/PostAnalyticsContent'; | |
import PostAnalyticsHeader from './components/PostAnalyticsHeader'; | ||
import PostAnalyticsLayout from './layout/PostAnalyticsLayout'; | ||
import {Card, CardContent, CardDescription, CardHeader, CardTitle, LucideIcon, Separator, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, ViewHeader, ViewHeaderActions, formatNumber} from '@tryghost/shade'; | ||
|
||
import {useParams} from '@tryghost/admin-x-framework'; | ||
import {usePostReferrers} from '../../hooks/usePostReferrers'; | ||
const STATS_DEFAULT_SOURCE_ICON_URL = 'https://static.ghost.org/v5.0.0/images/globe-icon.svg'; | ||
|
||
interface postAnalyticsProps {} | ||
|
||
const Growth: React.FC<postAnalyticsProps> = () => { | ||
// const {isLoading: isConfigLoading} = useGlobalData(); | ||
const {postId} = useParams(); | ||
const {stats: postReferrers, isLoading} = usePostReferrers(postId || ''); | ||
// const {range} = useGlobalData(); | ||
|
||
const isLoading = false; | ||
|
||
const mockTopSources = [ | ||
{id: 'source-001', title: 'google.com', freeMembers: 17, paidMembers: 7, mrr: 8}, | ||
{id: 'source-002', title: 'twitter.com', freeMembers: 12, paidMembers: 5, mrr: 6}, | ||
{id: 'source-003', title: 'facebook.com', freeMembers: 9, paidMembers: 4, mrr: 5}, | ||
{id: 'source-004', title: 'linkedin.com', freeMembers: 8, paidMembers: 3, mrr: 4}, | ||
{id: 'source-005', title: 'reddit.com', freeMembers: 7, paidMembers: 2, mrr: 3}, | ||
{id: 'source-006', title: 'medium.com', freeMembers: 6, paidMembers: 2, mrr: 3} | ||
]; | ||
|
||
return ( | ||
<PostAnalyticsLayout> | ||
<ViewHeader className='items-end pb-4'> | ||
|
@@ -55,7 +47,7 @@ const Growth: React.FC<postAnalyticsProps> = () => { | |
<LucideIcon.CircleDollarSign strokeWidth={1.5} /> | ||
</KpiCardIcon> | ||
<KpiCardLabel>MRR</KpiCardLabel> | ||
<KpiCardValue>+$180</KpiCardValue> | ||
<KpiCardValue>+${formatNumber(180)}</KpiCardValue> | ||
</KpiCard> | ||
</div> | ||
<Card> | ||
|
@@ -75,22 +67,22 @@ const Growth: React.FC<postAnalyticsProps> = () => { | |
</TableRow> | ||
</TableHeader> | ||
<TableBody> | ||
{mockTopSources.map(source => ( | ||
<TableRow key={source.id}> | ||
{postReferrers?.map(row => ( | ||
<TableRow key={row.source}> | ||
<TableCell> | ||
<a className='inline-flex items-center gap-2 font-medium' href={`https://${source.title}`} rel="noreferrer" target='_blank'> | ||
<a className='inline-flex items-center gap-2 font-medium' href={`https://${row.source}`} rel="noreferrer" target='_blank'> | ||
<img | ||
className="size-4" | ||
src={`https://www.faviconextractor.com/favicon/${source.title || 'direct'}?larger=true`} | ||
src={`https://www.faviconextractor.com/favicon/${row.source || 'direct'}?larger=true`} | ||
onError={(e: React.SyntheticEvent<HTMLImageElement>) => { | ||
e.currentTarget.src = STATS_DEFAULT_SOURCE_ICON_URL; | ||
}} /> | ||
<span>{source.title || 'Direct'}</span> | ||
<span>{row.source || 'Direct'}</span> | ||
</a> | ||
Comment on lines
+70
to
81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Invalid URL & favicon fetch when
-<a ... href={`https://${row.source}`} ...>
+<a
+ ...
+ href={row.source ? `https://${row.source}` : undefined}
+ rel="noopener noreferrer"
+ target={row.source ? '_blank' : undefined}
+> Also add |
||
</TableCell> | ||
<TableCell className='text-right font-mono text-sm'>+{formatNumber(source.freeMembers)}</TableCell> | ||
<TableCell className='text-right font-mono text-sm'>+{formatNumber(source.paidMembers)}</TableCell> | ||
<TableCell className='text-right font-mono text-sm'>+${source.mrr}</TableCell> | ||
<TableCell className='text-right font-mono text-sm'>+{formatNumber(row.free_members)}</TableCell> | ||
<TableCell className='text-right font-mono text-sm'>+{formatNumber(row.paid_members)}</TableCell> | ||
<TableCell className='text-right font-mono text-sm'>+${formatNumber(row.mrr)}</TableCell> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.