Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import type { CreatorPostSort } from '../../../../components/analytics/creator/C
import { CreatorPostPerformanceTable } from '../../../../components/analytics/creator/CreatorPostPerformanceTable';
import { CreatorDashboardError } from '../../../../components/analytics/creator/CreatorDashboardError';
import { AgentViewsSection } from '../../../../components/analytics/AgentViewsSection';
import { StartupsAgentAnalyticsPromo } from '../promos/StartupsAgentAnalyticsPromo';
import { CreatorAnalyticsAudience } from '../../../../components/analytics/creator/common';
import {
CreatorPerformancePeriod,
Expand Down Expand Up @@ -86,10 +87,12 @@ export const SquadManageAnalytics = (): ReactElement => {
...squadAnalyticsQueryOptions({ sourceId: squad?.id }),
enabled: !!squad?.id && canViewAnalytics,
});
const { data: agentAnalytics } = useQuery({
...squadAgentAnalyticsQueryOptions({ sourceId: squad?.id }),
enabled: !!squad?.id && canViewAnalytics,
});
const { data: agentAnalytics, isSuccess: isAgentAnalyticsFetched } = useQuery(
{
...squadAgentAnalyticsQueryOptions({ sourceId: squad?.id }),
enabled: !!squad?.id && canViewAnalytics,
},
);
const canViewAgentViews = typeof agentAnalytics?.agentViews === 'number';
const { data: agentHistory } = useQuery({
...squadAgentAnalyticsHistoryQueryOptions({ sourceId: squad?.id }),
Expand Down Expand Up @@ -228,6 +231,18 @@ export const SquadManageAnalytics = (): ReactElement => {
</Section>
</>
)}
{isAgentAnalyticsFetched && !canViewAgentViews && (
<StartupsAgentAnalyticsPromo
sourceId={squad?.id}
isSquadAnalytics
wrapper={(promo) => (
<>
<HorizontalSeparator />
<Section title="AI agents">{promo}</Section>
</>
)}
/>
)}
<HorizontalSeparator />
<Section title="Post performance">
{isPostsError && (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import type { ReactElement, ReactNode } from 'react';
import React, { useMemo } from 'react';
import dynamic from 'next/dynamic';
import subDays from 'date-fns/subDays';
import {
Button,
ButtonSize,
ButtonVariant,
} from '../../../../components/buttons/Button';
import { DataTile } from '../../../../components/DataTile';
import { LockIcon } from '../../../../components/icons';
import { IconSize } from '../../../../components/Icon';
import {
Typography,
TypographyColor,
TypographyTag,
TypographyType,
} from '../../../../components/typography/Typography';
import type { AgentViewsHistoryItem } from '../../../../components/analytics/agentViews';
import {
AgentViewsSeries,
agentViewsVendorSeries,
} from '../../../../components/analytics/agentViews';
import { postAnalyticsHistoryLimit } from '../../../../graphql/posts';
import {
StartupsPromoSpot,
useStartupsPromo,
} from '../../hooks/useStartupsPromo';
import { MonthlyCredits } from './StartupsPromo';

const AgentViewsChart = dynamic(
() =>
import('../../../../components/analytics/AgentViewsChart').then(
(mod) => mod.AgentViewsChart,
),
{
loading: () => <div className="h-40 w-full" />,
},
);

const previewVeil =
'radial-gradient(70% 70% at 50% 50%, color-mix(in srgb, var(--theme-background-default) 85%, transparent) 0%, color-mix(in srgb, var(--theme-background-default) 40%, transparent) 100%)';

const previewSeries = [
AgentViewsSeries.Chatgpt,
AgentViewsSeries.Claude,
AgentViewsSeries.Perplexity,
];

// Made-up numbers: the chart only shows blurred, behind the plan
const getPreviewHistory = (): AgentViewsHistoryItem[] =>
Array.from({ length: postAnalyticsHistoryLimit }, (_, index) => {
const wave = (offset: number, scale: number) =>
Math.round(scale * (2 + Math.sin(index / 4 + offset) + index / 30));

return {
date: subDays(new Date(), postAnalyticsHistoryLimit - 1 - index),
[AgentViewsSeries.Chatgpt]: wave(0, 6),
[AgentViewsSeries.Claude]: wave(2, 4),
[AgentViewsSeries.Perplexity]: wave(4, 2),
agentViewsChatgptBot: wave(1, 14),
agentViewsClaudeBot: wave(3, 10),
agentViewsPerplexityBot: wave(5, 5),
};
});

const agentNames = agentViewsVendorSeries
.slice(0, 4)
.map(({ label }) => label)
.join(', ');

/**
* Stands in for the AI agents section of post and squad analytics when the
* squad has no daily.dev for Startups plan: a blurred preview and the pitch.
*/
export const StartupsAgentAnalyticsPromo = ({
sourceId,
isSquadAnalytics = false,
wrapper,
}: {
/** The squad the analytics are for, or the post's squad */
sourceId?: string;
isSquadAnalytics?: boolean;
/** The page's section around it, so nothing renders when it doesn't show */
wrapper: (promo: ReactNode) => ReactElement;
}): ReactElement | null => {
const promo = useStartupsPromo({
spot: isSquadAnalytics
? StartupsPromoSpot.SquadAnalytics
: StartupsPromoSpot.PostAnalytics,
sourceId,
isPersonalAllowed: !isSquadAnalytics,
isDismissible: false,
});
const history = useMemo(getPreviewHistory, []);

if (!promo.isShown) {
return null;
}

const name = promo.squad?.name;

return wrapper(
<div className="grid overflow-hidden rounded-16 border border-border-subtlest-tertiary">
<div
aria-hidden
className="pointer-events-none col-start-1 row-start-1 flex select-none flex-col gap-4 p-4 blur-sm"
>
<div className="flex gap-4">
<DataTile
label="AI agent reads"
value={1240}
className={{ container: 'flex-1' }}
/>
<DataTile
label="AI crawler visits"
value={3870}
className={{ container: 'flex-1' }}
/>
</div>
<AgentViewsChart history={history} visibleSeries={previewSeries} />
</div>
<div
className="col-start-1 row-start-1 flex flex-col items-center justify-center gap-3 p-6 text-center"
style={{ background: previewVeil }}
>
<span className="flex size-10 items-center justify-center rounded-12 bg-overlay-float-cabbage text-accent-cabbage-default">
<LockIcon size={IconSize.Medium} />
</span>
<Typography type={TypographyType.Body} bold tag={TypographyTag.H3}>
{isSquadAnalytics
? 'See which AI agents read this squad'
: 'See which AI agents read your post'}
</Typography>
<Typography
tag={TypographyTag.P}
type={TypographyType.Callout}
color={TypographyColor.Secondary}
className="max-w-md"
>
{`${agentNames} read posts on daily.dev when someone asks them about a topic. `}
{name
? `Make ${name} your company page for ${promo.starterPrice} a month to see every read and crawl, day by day, with `
: `Get a company page for ${promo.starterPrice} a month to see every read and crawl, day by day, with `}
<MonthlyCredits promo={promo} /> every month.
</Typography>
<Button
tag="a"
href={promo.checkoutUrl}
variant={ButtonVariant.Primary}
size={ButtonSize.Small}
onClick={promo.onClick}
>
See plans
</Button>
</div>
</div>,
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export enum StartupsPromoSpot {
Wallet = 'wallet promo',
AdsDashboard = 'ads dashboard promo',
NewSquadModal = 'new squad modal promo',
SquadAnalytics = 'squad analytics promo',
PostAnalytics = 'post analytics promo',
}

interface UseStartupsPromoProps {
Expand All @@ -42,6 +44,8 @@ interface UseStartupsPromoProps {
isVisible?: boolean;
/** Pitches the squad about to be created, not one the viewer runs */
isNewSquad?: boolean;
/** False for a locked feature, which shows even after a dismissed promo */
isDismissible?: boolean;
}

/** What Starter gives back each month, the launch promo's while it is on */
Expand Down Expand Up @@ -101,6 +105,7 @@ export const useStartupsPromo = ({
isPersonalAllowed = true,
isVisible = true,
isNewSquad = false,
isDismissible = true,
}: UseStartupsPromoProps): StartupsPromo => {
const { user, squads } = useAuthContext();
const { checkHasCompleted, completeAction, isActionsFetched } = useActions();
Expand Down Expand Up @@ -154,7 +159,7 @@ export const useStartupsPromo = ({
const isShown =
isCandidate &&
isActionsFetched &&
!isDismissed &&
(!isDismissible || !isDismissed) &&
(!squad || (!isPending && !!subscription && !subscription.plan));
const extra = useMemo(
() => ({ source_id: squad?.id, has_squad: !!squad }),
Expand Down
1 change: 1 addition & 0 deletions packages/shared/src/features/squads/lib/plans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export const squadPlanDetails: Record<SquadPlan, SquadPlanDetails> = {
'Company page with a link to your site',
'In developers’ feeds, by topic',
'On Google and in AI answers',
'See which AI agents read your posts',
'Weekly intel on up to 5 topics',
'Reach notes when a post needs work',
'Skills for Claude Code and any agent',
Expand Down
17 changes: 16 additions & 1 deletion packages/webapp/pages/posts/[id]/analytics/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ import { BoostIcon } from '@dailydotdev/shared/src/components/icons/Boost';
import { useCampaignEstimation } from '@dailydotdev/shared/src/features/boost/useCampaignEstimation';
import { useCampaigns } from '@dailydotdev/shared/src/features/boost/useCampaigns';
import { AgentViewsSection } from '@dailydotdev/shared/src/components/analytics/AgentViewsSection';
import { StartupsAgentAnalyticsPromo } from '@dailydotdev/shared/src/features/squads/components/promos/StartupsAgentAnalyticsPromo';
import { LegendToggle } from '@dailydotdev/shared/src/components/analytics/LegendToggle';
import { getSeoDescription } from '../../../../components/PostSEOSchema';
import type { Props } from '../index';
Expand Down Expand Up @@ -221,7 +222,7 @@ const PostAnalyticsPage = ({
});
const isAuthor = !!user?.id && user.id === post?.author?.id;

const { data: postAnalytics } = useQuery({
const { data: postAnalytics, isSuccess: isPostAnalyticsFetched } = useQuery({
...postAnalyticsQueryOptions({ id: post?.id }),
enabled: canViewPostAnalytics({ post, user }),
});
Expand Down Expand Up @@ -583,6 +584,20 @@ const PostAnalyticsPage = ({
</SectionContainer>
</>
)}
{isPostAnalyticsFetched && !canViewAgentViews && (
<StartupsAgentAnalyticsPromo
sourceId={post?.source?.id}
wrapper={(promo) => (
<>
<Divider className={dividerClassName} />
<SectionContainer>
<SectionHeader>AI agents</SectionHeader>
{promo}
</SectionContainer>
</>
)}
/>
)}
<Divider className={dividerClassName} />
{canBoost && !campaign && (
<>
Expand Down
Loading