@rankcli/agent-runtime 0.0.15 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. package/README.md +5 -4
  2. package/dist/index.d.mts +44 -393
  3. package/dist/index.d.ts +44 -393
  4. package/dist/index.js +22098 -26131
  5. package/dist/index.mjs +11834 -15857
  6. package/package.json +10 -4
  7. package/scripts/build-deno.ts +0 -134
  8. package/src/analyzers/core-web-vitals-analyzer.test.ts +0 -236
  9. package/src/analyzers/core-web-vitals-analyzer.ts +0 -557
  10. package/src/analyzers/geo-analyzer.test.ts +0 -310
  11. package/src/analyzers/geo-analyzer.ts +0 -814
  12. package/src/analyzers/image-optimization-analyzer.test.ts +0 -145
  13. package/src/analyzers/image-optimization-analyzer.ts +0 -348
  14. package/src/analyzers/index.ts +0 -233
  15. package/src/analyzers/internal-linking-analyzer.test.ts +0 -141
  16. package/src/analyzers/internal-linking-analyzer.ts +0 -419
  17. package/src/analyzers/mobile-seo-analyzer.test.ts +0 -140
  18. package/src/analyzers/mobile-seo-analyzer.ts +0 -455
  19. package/src/analyzers/security-headers-analyzer.test.ts +0 -115
  20. package/src/analyzers/security-headers-analyzer.ts +0 -318
  21. package/src/analyzers/structured-data-analyzer.test.ts +0 -210
  22. package/src/analyzers/structured-data-analyzer.ts +0 -590
  23. package/src/audit/ai/analyzer.ts +0 -347
  24. package/src/audit/ai/index.ts +0 -29
  25. package/src/audit/ai/prompts/content-analysis.ts +0 -271
  26. package/src/audit/ai/types.ts +0 -179
  27. package/src/audit/checks/additional-checks.ts +0 -439
  28. package/src/audit/checks/agent-experience.ts +0 -108
  29. package/src/audit/checks/ai-citation-worthiness.ts +0 -399
  30. package/src/audit/checks/ai-content-structure.ts +0 -325
  31. package/src/audit/checks/ai-readiness.ts +0 -406
  32. package/src/audit/checks/anchor-text.ts +0 -179
  33. package/src/audit/checks/answer-conciseness.ts +0 -322
  34. package/src/audit/checks/asset-minification.ts +0 -270
  35. package/src/audit/checks/bing-optimization.ts +0 -206
  36. package/src/audit/checks/brand-mention-optimization.ts +0 -349
  37. package/src/audit/checks/caching-headers.ts +0 -305
  38. package/src/audit/checks/canonical-advanced.ts +0 -150
  39. package/src/audit/checks/canonical-domain.ts +0 -196
  40. package/src/audit/checks/citation-quality.ts +0 -358
  41. package/src/audit/checks/client-rendering.ts +0 -542
  42. package/src/audit/checks/color-contrast.ts +0 -342
  43. package/src/audit/checks/content-freshness.ts +0 -170
  44. package/src/audit/checks/content-science.ts +0 -589
  45. package/src/audit/checks/conversion-elements.ts +0 -526
  46. package/src/audit/checks/crawlability.ts +0 -220
  47. package/src/audit/checks/directory-listing.ts +0 -172
  48. package/src/audit/checks/dom-analysis.ts +0 -191
  49. package/src/audit/checks/dom-size.ts +0 -246
  50. package/src/audit/checks/duplicate-content.ts +0 -194
  51. package/src/audit/checks/eeat-signals.ts +0 -990
  52. package/src/audit/checks/entity-seo.ts +0 -396
  53. package/src/audit/checks/featured-snippet.ts +0 -473
  54. package/src/audit/checks/freshness-signals.ts +0 -443
  55. package/src/audit/checks/funnel-intent.ts +0 -463
  56. package/src/audit/checks/hreflang.ts +0 -174
  57. package/src/audit/checks/html-compliance.ts +0 -302
  58. package/src/audit/checks/image-dimensions.ts +0 -167
  59. package/src/audit/checks/images.ts +0 -160
  60. package/src/audit/checks/indexnow.ts +0 -275
  61. package/src/audit/checks/interactive-tools.ts +0 -475
  62. package/src/audit/checks/internal-link-graph.ts +0 -436
  63. package/src/audit/checks/keyword-analysis.ts +0 -239
  64. package/src/audit/checks/keyword-cannibalization.ts +0 -385
  65. package/src/audit/checks/keyword-placement.ts +0 -471
  66. package/src/audit/checks/links.ts +0 -273
  67. package/src/audit/checks/llms-txt.ts +0 -224
  68. package/src/audit/checks/local-seo.ts +0 -296
  69. package/src/audit/checks/mobile.ts +0 -167
  70. package/src/audit/checks/modern-images.ts +0 -226
  71. package/src/audit/checks/navboost-signals.ts +0 -395
  72. package/src/audit/checks/on-page.ts +0 -209
  73. package/src/audit/checks/page-resources.ts +0 -285
  74. package/src/audit/checks/pagination.ts +0 -180
  75. package/src/audit/checks/performance.ts +0 -153
  76. package/src/audit/checks/platform-presence.ts +0 -580
  77. package/src/audit/checks/rag-chunk-readiness.test.ts +0 -159
  78. package/src/audit/checks/rag-chunk-readiness.ts +0 -163
  79. package/src/audit/checks/redirect-analysis.ts +0 -153
  80. package/src/audit/checks/redirect-chain.ts +0 -389
  81. package/src/audit/checks/resource-hints.ts +0 -420
  82. package/src/audit/checks/responsive-css.ts +0 -247
  83. package/src/audit/checks/responsive-images.ts +0 -396
  84. package/src/audit/checks/review-ecosystem.ts +0 -415
  85. package/src/audit/checks/robots-validation.ts +0 -373
  86. package/src/audit/checks/security-headers.ts +0 -188
  87. package/src/audit/checks/security.ts +0 -144
  88. package/src/audit/checks/serp-preview.ts +0 -251
  89. package/src/audit/checks/site-maturity.ts +0 -453
  90. package/src/audit/checks/social-meta.test.ts +0 -275
  91. package/src/audit/checks/social-meta.ts +0 -134
  92. package/src/audit/checks/soft-404.ts +0 -151
  93. package/src/audit/checks/structured-data.ts +0 -238
  94. package/src/audit/checks/tech-detection.ts +0 -496
  95. package/src/audit/checks/topical-clusters.ts +0 -435
  96. package/src/audit/checks/tracker-bloat.ts +0 -462
  97. package/src/audit/checks/tracking-verification.test.ts +0 -371
  98. package/src/audit/checks/tracking-verification.ts +0 -636
  99. package/src/audit/checks/url-safety.ts +0 -682
  100. package/src/audit/deno-entry.ts +0 -66
  101. package/src/audit/discovery/index.ts +0 -15
  102. package/src/audit/discovery/link-crawler.ts +0 -233
  103. package/src/audit/discovery/repo-routes.ts +0 -347
  104. package/src/audit/engine.ts +0 -633
  105. package/src/audit/fixes/index.ts +0 -209
  106. package/src/audit/fixes/social-meta-fixes.test.ts +0 -329
  107. package/src/audit/fixes/social-meta-fixes.ts +0 -463
  108. package/src/audit/index.ts +0 -74
  109. package/src/audit/runner.test.ts +0 -299
  110. package/src/audit/runner.ts +0 -130
  111. package/src/audit/types.ts +0 -1987
  112. package/src/content/featured-snippet.ts +0 -367
  113. package/src/content/generator.test.ts +0 -534
  114. package/src/content/generator.ts +0 -501
  115. package/src/content/headline.ts +0 -317
  116. package/src/content/index.ts +0 -62
  117. package/src/content/intent.ts +0 -258
  118. package/src/content/keyword-density.ts +0 -349
  119. package/src/content/readability.ts +0 -262
  120. package/src/executor.ts +0 -336
  121. package/src/fixer/framework-fixes.test.ts +0 -489
  122. package/src/fixer/framework-fixes.ts +0 -5287
  123. package/src/fixer/index.ts +0 -6
  124. package/src/fixer/schemas.ts +0 -971
  125. package/src/fixer.ts +0 -642
  126. package/src/frameworks/detector.test.ts +0 -248
  127. package/src/frameworks/detector.ts +0 -899
  128. package/src/frameworks/index.ts +0 -68
  129. package/src/frameworks/recipes/angular.yaml +0 -171
  130. package/src/frameworks/recipes/astro.yaml +0 -206
  131. package/src/frameworks/recipes/django.yaml +0 -180
  132. package/src/frameworks/recipes/laravel.yaml +0 -137
  133. package/src/frameworks/recipes/nextjs.yaml +0 -268
  134. package/src/frameworks/recipes/nuxt.yaml +0 -175
  135. package/src/frameworks/recipes/rails.yaml +0 -188
  136. package/src/frameworks/recipes/react.yaml +0 -202
  137. package/src/frameworks/recipes/sveltekit.yaml +0 -154
  138. package/src/frameworks/recipes/vue.yaml +0 -137
  139. package/src/frameworks/recipes/wordpress.yaml +0 -209
  140. package/src/frameworks/suggestion-engine.ts +0 -357
  141. package/src/geo/geo-content.test.ts +0 -305
  142. package/src/geo/geo-content.ts +0 -266
  143. package/src/geo/geo-history.test.ts +0 -473
  144. package/src/geo/geo-history.ts +0 -433
  145. package/src/geo/geo-tracker.test.ts +0 -359
  146. package/src/geo/geo-tracker.ts +0 -411
  147. package/src/geo/index.ts +0 -11
  148. package/src/geo/llm-citation-checker.ts +0 -188
  149. package/src/git/commit-helper.test.ts +0 -261
  150. package/src/git/commit-helper.ts +0 -329
  151. package/src/git/index.ts +0 -12
  152. package/src/git/pr-helper.test.ts +0 -284
  153. package/src/git/pr-helper.ts +0 -307
  154. package/src/index.ts +0 -76
  155. package/src/keywords/ai-keyword-engine.ts +0 -1062
  156. package/src/keywords/ai-summarizer.ts +0 -387
  157. package/src/keywords/ci-mode.ts +0 -555
  158. package/src/keywords/engine.ts +0 -359
  159. package/src/keywords/index.ts +0 -151
  160. package/src/keywords/llm-judge.ts +0 -357
  161. package/src/keywords/nlp-analysis.ts +0 -706
  162. package/src/keywords/prioritizer.ts +0 -295
  163. package/src/keywords/site-crawler.ts +0 -342
  164. package/src/keywords/sources/autocomplete.ts +0 -139
  165. package/src/keywords/sources/competitive-search.ts +0 -450
  166. package/src/keywords/sources/competitor-analysis.ts +0 -374
  167. package/src/keywords/sources/dataforseo.ts +0 -206
  168. package/src/keywords/sources/free-sources.ts +0 -294
  169. package/src/keywords/sources/gsc.ts +0 -123
  170. package/src/keywords/topic-grouping.ts +0 -327
  171. package/src/keywords/types.ts +0 -144
  172. package/src/keywords/wizard.ts +0 -457
  173. package/src/loader.ts +0 -40
  174. package/src/ranking/index.ts +0 -5
  175. package/src/ranking/serp-client.ts +0 -348
  176. package/src/ranking/tracker.ts +0 -380
  177. package/src/ranking/types.ts +0 -123
  178. package/src/reports/index.ts +0 -7
  179. package/src/reports/report-generator.test.ts +0 -293
  180. package/src/reports/report-generator.ts +0 -713
  181. package/src/scheduler/alerts.test.ts +0 -458
  182. package/src/scheduler/alerts.ts +0 -328
  183. package/src/scheduler/index.ts +0 -8
  184. package/src/scheduler/scheduled-audit.test.ts +0 -377
  185. package/src/scheduler/scheduled-audit.ts +0 -149
  186. package/src/test/integration-test.ts +0 -325
  187. package/src/tools/analyzer.ts +0 -373
  188. package/src/tools/crawl.ts +0 -293
  189. package/src/tools/files.ts +0 -301
  190. package/src/tools/h1-fixer.ts +0 -249
  191. package/src/tools/index.ts +0 -67
  192. package/src/tracking/github-action.ts +0 -326
  193. package/src/tracking/google-analytics.ts +0 -265
  194. package/src/tracking/index.ts +0 -45
  195. package/src/tracking/report-generator.ts +0 -386
  196. package/src/tracking/search-console.ts +0 -335
  197. package/src/types.ts +0 -148
  198. package/src/utils/http.ts +0 -302
  199. package/src/wasm-adapter.ts +0 -297
  200. package/src/wasm-entry.ts +0 -14
  201. package/tsconfig.json +0 -17
  202. package/tsup.wasm.config.ts +0 -26
  203. package/vitest.config.ts +0 -15
@@ -1,463 +0,0 @@
1
- // Search Funnel Intent Analysis
2
- // Reference: "6 Advanced SEO Tips for 2026"
3
- // "Stop relying on top of funnel search terms"
4
- // "TOFU, MOFU, BOFU - focus on middle and bottom of funnel"
5
- // "AI overviews answer informational queries - focus on money keywords"
6
-
7
- import * as cheerio from 'cheerio';
8
- import type { AuditIssue } from '../types.js';
9
-
10
- export type FunnelStage = 'tofu' | 'mofu' | 'bofu' | 'mixed';
11
-
12
- export interface FunnelIntentData {
13
- detectedStage: FunnelStage;
14
- confidence: number; // 0-100
15
- signals: {
16
- tofu: string[];
17
- mofu: string[];
18
- bofu: string[];
19
- };
20
- metrics: {
21
- informationalScore: number;
22
- considerationScore: number;
23
- conversionScore: number;
24
- };
25
- pageType: string;
26
- aiOverviewRisk: 'high' | 'medium' | 'low';
27
- recommendations: string[];
28
- }
29
-
30
- // TOFU (Top of Funnel) - Informational intent patterns
31
- const TOFU_PATTERNS = {
32
- url: [
33
- /\/blog\//i,
34
- /\/article/i,
35
- /\/guide/i,
36
- /\/tutorial/i,
37
- /\/how-to/i,
38
- /\/what-is/i,
39
- /\/learn/i,
40
- /\/tips/i,
41
- /\/explained/i,
42
- /\/introduction/i,
43
- /\/beginners?/i,
44
- ],
45
- title: [
46
- /^how to/i,
47
- /^what is/i,
48
- /^what are/i,
49
- /^why /i,
50
- /^when /i,
51
- /^guide to/i,
52
- /complete guide/i,
53
- /beginner'?s? guide/i,
54
- /ultimate guide/i,
55
- /\d+ tips/i,
56
- /\d+ ways/i,
57
- /\d+ things/i,
58
- /explained/i,
59
- /introduction to/i,
60
- /learn /i,
61
- /understanding/i,
62
- ],
63
- content: [
64
- /in this article/i,
65
- /in this guide/i,
66
- /we'll explain/i,
67
- /we'll cover/i,
68
- /you'll learn/i,
69
- /let's explore/i,
70
- /let's dive/i,
71
- /did you know/i,
72
- /according to/i,
73
- /research shows/i,
74
- /studies show/i,
75
- ],
76
- };
77
-
78
- // MOFU (Middle of Funnel) - Consideration/comparison intent patterns
79
- const MOFU_PATTERNS = {
80
- url: [
81
- /\/compare/i,
82
- /\/comparison/i,
83
- /\/vs/i,
84
- /\/versus/i,
85
- /\/alternative/i,
86
- /\/review/i,
87
- /\/pros-cons/i,
88
- /\/features/i,
89
- /\/solutions/i,
90
- /\/case-stud/i,
91
- ],
92
- title: [
93
- /vs\.?$/i,
94
- /versus/i,
95
- /comparison/i,
96
- /compared/i,
97
- /alternative/i,
98
- /review/i,
99
- /pros and cons/i,
100
- /which is better/i,
101
- /best .* for/i,
102
- /top \d+/i,
103
- /\d+ best/i,
104
- /how .* compares/i,
105
- /should you/i,
106
- ],
107
- content: [
108
- /let'?s compare/i,
109
- /in comparison/i,
110
- /alternative to/i,
111
- /pros:/i,
112
- /cons:/i,
113
- /advantages:/i,
114
- /disadvantages:/i,
115
- /key features/i,
116
- /feature comparison/i,
117
- /case study/i,
118
- /our client/i,
119
- /we helped/i,
120
- ],
121
- };
122
-
123
- // BOFU (Bottom of Funnel) - Conversion/purchase intent patterns
124
- const BOFU_PATTERNS = {
125
- url: [
126
- /\/pricing/i,
127
- /\/buy/i,
128
- /\/purchase/i,
129
- /\/order/i,
130
- /\/sign-?up/i,
131
- /\/register/i,
132
- /\/demo/i,
133
- /\/trial/i,
134
- /\/quote/i,
135
- /\/contact/i,
136
- /\/get-started/i,
137
- /\/checkout/i,
138
- /\/hire/i,
139
- /\/services?$/i,
140
- ],
141
- title: [
142
- /pricing/i,
143
- /buy /i,
144
- /purchase/i,
145
- /order /i,
146
- /sign up/i,
147
- /get started/i,
148
- /free trial/i,
149
- /request .* demo/i,
150
- /book .* call/i,
151
- /schedule/i,
152
- /get .* quote/i,
153
- /contact us/i,
154
- /hire /i,
155
- /\$\d+/,
156
- /per month/i,
157
- /\/mo\b/i,
158
- ],
159
- content: [
160
- /add to cart/i,
161
- /buy now/i,
162
- /purchase now/i,
163
- /sign up now/i,
164
- /get started/i,
165
- /start.*trial/i,
166
- /request.*demo/i,
167
- /book.*call/i,
168
- /schedule.*meeting/i,
169
- /contact.*today/i,
170
- /limited.*offer/i,
171
- /special.*price/i,
172
- /money.*back.*guarantee/i,
173
- /free.*shipping/i,
174
- /plans.*pricing/i,
175
- /per user/i,
176
- /per month/i,
177
- /billed annually/i,
178
- /\$\d+/,
179
- ],
180
- elements: [
181
- 'form[action*="checkout"]',
182
- 'form[action*="purchase"]',
183
- 'form[action*="subscribe"]',
184
- 'button[data-action="buy"]',
185
- '[class*="pricing-table"]',
186
- '[class*="price-card"]',
187
- '[class*="checkout"]',
188
- '[class*="add-to-cart"]',
189
- ],
190
- };
191
-
192
- /**
193
- * Calculate score for a funnel stage based on pattern matches
194
- */
195
- function calculateStageScore(
196
- url: string,
197
- title: string,
198
- content: string,
199
- $: cheerio.CheerioAPI,
200
- patterns: {
201
- url: RegExp[];
202
- title: RegExp[];
203
- content: RegExp[];
204
- elements?: string[];
205
- }
206
- ): { score: number; signals: string[] } {
207
- let score = 0;
208
- const signals: string[] = [];
209
-
210
- // URL patterns (weighted highest)
211
- for (const pattern of patterns.url) {
212
- if (pattern.test(url)) {
213
- score += 15;
214
- signals.push(`URL: ${pattern.source}`);
215
- }
216
- }
217
-
218
- // Title patterns (high weight)
219
- for (const pattern of patterns.title) {
220
- if (pattern.test(title)) {
221
- score += 12;
222
- signals.push(`Title: ${pattern.source}`);
223
- }
224
- }
225
-
226
- // Content patterns (medium weight)
227
- for (const pattern of patterns.content) {
228
- if (pattern.test(content)) {
229
- score += 5;
230
- signals.push(`Content: ${pattern.source}`);
231
- }
232
- }
233
-
234
- // Element patterns (BOFU only)
235
- if (patterns.elements) {
236
- for (const selector of patterns.elements) {
237
- if ($(selector).length > 0) {
238
- score += 10;
239
- signals.push(`Element: ${selector}`);
240
- }
241
- }
242
- }
243
-
244
- return { score, signals: signals.slice(0, 5) }; // Limit signals for readability
245
- }
246
-
247
- /**
248
- * Determine page type based on content
249
- */
250
- function determinePageType($: cheerio.CheerioAPI, url: string): string {
251
- // Check URL first
252
- if (/\/blog\//i.test(url)) return 'blog-post';
253
- if (/\/product/i.test(url)) return 'product-page';
254
- if (/\/services?/i.test(url)) return 'service-page';
255
- if (/\/pricing/i.test(url)) return 'pricing-page';
256
- if (/\/about/i.test(url)) return 'about-page';
257
- if (/\/contact/i.test(url)) return 'contact-page';
258
- if (/\/case-stud/i.test(url)) return 'case-study';
259
-
260
- // Check content
261
- if ($('[class*="pricing"]').length > 0) return 'pricing-page';
262
- if ($('[class*="product"]').length > 0) return 'product-page';
263
- if ($('article').length > 0) return 'article';
264
- if ($('[class*="blog"]').length > 0) return 'blog-post';
265
-
266
- // Check for e-commerce
267
- if ($('[class*="cart"]').length > 0 || $('[class*="checkout"]').length > 0) return 'e-commerce';
268
-
269
- return 'general';
270
- }
271
-
272
- /**
273
- * Calculate AI overview risk (likelihood of being replaced by AI-generated answer)
274
- */
275
- function calculateAIOverviewRisk(stage: FunnelStage, pageType: string): FunnelIntentData['aiOverviewRisk'] {
276
- // TOFU informational content is most at risk
277
- if (stage === 'tofu') {
278
- return 'high';
279
- }
280
-
281
- // Blog posts and articles are at risk
282
- if (pageType === 'blog-post' || pageType === 'article') {
283
- return 'high';
284
- }
285
-
286
- // MOFU comparison content is medium risk
287
- if (stage === 'mofu') {
288
- return 'medium';
289
- }
290
-
291
- // BOFU transactional content is least at risk
292
- return 'low';
293
- }
294
-
295
- /**
296
- * Main function: Analyze search funnel intent
297
- */
298
- export function analyzeFunnelIntent(
299
- html: string,
300
- url: string
301
- ): { issues: AuditIssue[]; data: FunnelIntentData } {
302
- const $ = cheerio.load(html);
303
- const issues: AuditIssue[] = [];
304
-
305
- // Extract text content
306
- const title = $('title').text().trim() + ' ' + $('h1').first().text().trim();
307
- const bodyText = $('body').text().toLowerCase();
308
-
309
- // Calculate scores for each funnel stage
310
- const tofuResult = calculateStageScore(url, title, bodyText, $, TOFU_PATTERNS);
311
- const mofuResult = calculateStageScore(url, title, bodyText, $, MOFU_PATTERNS);
312
- const bofuResult = calculateStageScore(url, title, bodyText, $, BOFU_PATTERNS);
313
-
314
- // Normalize scores
315
- const totalScore = tofuResult.score + mofuResult.score + bofuResult.score || 1;
316
- const informationalScore = Math.round((tofuResult.score / totalScore) * 100);
317
- const considerationScore = Math.round((mofuResult.score / totalScore) * 100);
318
- const conversionScore = Math.round((bofuResult.score / totalScore) * 100);
319
-
320
- // Determine primary funnel stage
321
- let detectedStage: FunnelStage;
322
- let confidence: number;
323
-
324
- if (bofuResult.score > tofuResult.score && bofuResult.score > mofuResult.score) {
325
- detectedStage = 'bofu';
326
- confidence = conversionScore;
327
- } else if (mofuResult.score > tofuResult.score) {
328
- detectedStage = 'mofu';
329
- confidence = considerationScore;
330
- } else if (tofuResult.score > 0) {
331
- detectedStage = 'tofu';
332
- confidence = informationalScore;
333
- } else {
334
- detectedStage = 'mixed';
335
- confidence = 50;
336
- }
337
-
338
- // Determine page type
339
- const pageType = determinePageType($, url);
340
-
341
- // Calculate AI overview risk
342
- const aiOverviewRisk = calculateAIOverviewRisk(detectedStage, pageType);
343
-
344
- // Generate recommendations
345
- const recommendations: string[] = [];
346
-
347
- if (detectedStage === 'tofu') {
348
- recommendations.push('Consider adding conversion elements (CTAs, forms) to capture leads');
349
- recommendations.push('Link to MOFU/BOFU pages (comparisons, pricing) to guide users down the funnel');
350
- if (aiOverviewRisk === 'high') {
351
- recommendations.push('Add unique data, case studies, or expert opinions that AI cannot replicate');
352
- }
353
- }
354
-
355
- if (detectedStage === 'mofu') {
356
- recommendations.push('Add clear CTAs to BOFU pages (pricing, demos, trials)');
357
- recommendations.push('Include social proof (testimonials, case studies) to build trust');
358
- }
359
-
360
- if (detectedStage === 'mixed') {
361
- recommendations.push('Clarify the page\'s primary intent - is this informational, comparison, or conversion focused?');
362
- recommendations.push('Consider splitting into multiple focused pages for better SEO');
363
- }
364
-
365
- // Generate issues
366
-
367
- // High AI overview risk on TOFU content
368
- if (aiOverviewRisk === 'high' && detectedStage === 'tofu') {
369
- issues.push({
370
- code: 'TOFU_AI_OVERVIEW_RISK',
371
- severity: 'notice',
372
- category: 'content',
373
- title: 'Content at risk of AI overview displacement',
374
- description: 'This informational content may be answered directly by AI overviews, reducing click-through.',
375
- impact: 'Google AI overviews are increasingly answering informational queries directly in SERPs.',
376
- howToFix: 'Add unique value: original data, expert opinions, case studies, or interactive tools that AI cannot replicate.',
377
- affectedUrls: [url],
378
- details: {
379
- funnelStage: 'tofu',
380
- aiOverviewRisk,
381
- recommendation: 'Focus on MOFU/BOFU content or add unique differentiating content',
382
- },
383
- });
384
- }
385
-
386
- // TOFU without BOFU links
387
- if (detectedStage === 'tofu') {
388
- const hasConversionLinks = $('a[href*="pricing"], a[href*="demo"], a[href*="trial"], a[href*="contact"], a[href*="buy"]').length > 0;
389
- if (!hasConversionLinks) {
390
- issues.push({
391
- code: 'TOFU_NO_FUNNEL_LINKS',
392
- severity: 'notice',
393
- category: 'content',
394
- title: 'Informational page lacks conversion path',
395
- description: 'This TOFU content has no links to pricing, demo, trial, or contact pages.',
396
- impact: 'Users may leave without entering the sales funnel. Missing revenue opportunity.',
397
- howToFix: 'Add contextual CTAs linking to MOFU/BOFU pages (comparisons, pricing, demos).',
398
- affectedUrls: [url],
399
- });
400
- }
401
- }
402
-
403
- // BOFU page without social proof
404
- if (detectedStage === 'bofu') {
405
- const hasSocialProof = $('[class*="testimonial"], [class*="review"], [class*="case-study"], [class*="trust"]').length > 0 ||
406
- bodyText.includes('testimonial') || bodyText.includes('customer said');
407
-
408
- if (!hasSocialProof) {
409
- issues.push({
410
- code: 'BOFU_NO_SOCIAL_PROOF',
411
- severity: 'warning',
412
- category: 'content',
413
- title: 'Conversion page lacks social proof',
414
- description: 'This pricing/sales page has no visible testimonials, reviews, or case studies.',
415
- impact: '97% of consumers look at reviews before buying. Social proof can increase conversions by 34%.',
416
- howToFix: 'Add customer testimonials, case study results, trust badges, or review ratings.',
417
- affectedUrls: [url],
418
- details: {
419
- funnelStage: 'bofu',
420
- pageType,
421
- },
422
- });
423
- }
424
- }
425
-
426
- // Mixed intent page
427
- if (detectedStage === 'mixed' && confidence < 40) {
428
- issues.push({
429
- code: 'MIXED_FUNNEL_INTENT',
430
- severity: 'notice',
431
- category: 'content',
432
- title: 'Unclear page intent',
433
- description: 'This page has mixed signals - unclear if informational, comparison, or conversion focused.',
434
- impact: 'Mixed intent pages may rank poorly because search engines cannot determine primary purpose.',
435
- howToFix: 'Focus on one primary intent per page. Create separate pages for different funnel stages.',
436
- affectedUrls: [url],
437
- details: {
438
- scores: { tofu: informationalScore, mofu: considerationScore, bofu: conversionScore },
439
- },
440
- });
441
- }
442
-
443
- return {
444
- issues,
445
- data: {
446
- detectedStage,
447
- confidence,
448
- signals: {
449
- tofu: tofuResult.signals,
450
- mofu: mofuResult.signals,
451
- bofu: bofuResult.signals,
452
- },
453
- metrics: {
454
- informationalScore,
455
- considerationScore,
456
- conversionScore,
457
- },
458
- pageType,
459
- aiOverviewRisk,
460
- recommendations,
461
- },
462
- };
463
- }
@@ -1,174 +0,0 @@
1
- import * as cheerio from 'cheerio';
2
- import { httpHead, httpGet } from '../../utils/http.js';
3
- import type { AuditIssue } from '../types.js';
4
- import { ISSUE_DEFINITIONS } from '../types.js';
5
-
6
- export interface HreflangData {
7
- hasHreflang: boolean;
8
- entries: HreflangEntry[];
9
- hasSelfReference: boolean;
10
- hasXDefault: boolean;
11
- }
12
-
13
- export interface HreflangEntry {
14
- lang: string;
15
- href: string;
16
- isValid: boolean;
17
- isSelfReference: boolean;
18
- statusCode?: number;
19
- }
20
-
21
- // Valid ISO 639-1 language codes (subset of most common)
22
- const VALID_LANG_CODES = new Set([
23
- 'en', 'es', 'fr', 'de', 'it', 'pt', 'ru', 'ja', 'zh', 'ko', 'ar', 'hi', 'nl', 'sv',
24
- 'pl', 'tr', 'da', 'fi', 'no', 'cs', 'el', 'he', 'hu', 'id', 'ms', 'th', 'vi', 'uk',
25
- 'ro', 'bg', 'hr', 'sk', 'sl', 'et', 'lv', 'lt', 'sr', 'ca', 'eu', 'gl', 'af', 'sw',
26
- 'x-default'
27
- ]);
28
-
29
- function isValidHreflang(lang: string): boolean {
30
- const parts = lang.toLowerCase().split('-');
31
- if (parts[0] === 'x' && parts[1] === 'default') return true;
32
- if (!VALID_LANG_CODES.has(parts[0])) return false;
33
- // Region codes are optional, just check length if present
34
- if (parts[1] && parts[1].length !== 2) return false;
35
- return true;
36
- }
37
-
38
- export async function analyzeHreflang(
39
- html: string,
40
- url: string,
41
- options: { validateUrls?: boolean } = {}
42
- ): Promise<{ issues: AuditIssue[]; data: HreflangData }> {
43
- const issues: AuditIssue[] = [];
44
- const $ = cheerio.load(html);
45
- const entries: HreflangEntry[] = [];
46
-
47
- // Extract hreflang from link tags
48
- $('link[rel="alternate"][hreflang]').each((_, el) => {
49
- const lang = $(el).attr('hreflang') || '';
50
- const href = $(el).attr('href') || '';
51
- const isValid = isValidHreflang(lang);
52
- const isSelfReference = normalizeUrl(href) === normalizeUrl(url);
53
-
54
- entries.push({ lang, href, isValid, isSelfReference });
55
- });
56
-
57
- // Also check for hreflang in HTTP headers (would need to be passed in)
58
-
59
- const hasHreflang = entries.length > 0;
60
- const hasSelfReference = entries.some(e => e.isSelfReference);
61
- const hasXDefault = entries.some(e => e.lang.toLowerCase() === 'x-default');
62
-
63
- const data: HreflangData = {
64
- hasHreflang,
65
- entries,
66
- hasSelfReference,
67
- hasXDefault,
68
- };
69
-
70
- if (!hasHreflang) {
71
- // No hreflang is not necessarily an issue for single-language sites
72
- return { issues, data };
73
- }
74
-
75
- // Check for invalid hreflang values
76
- const invalidEntries = entries.filter(e => !e.isValid);
77
- if (invalidEntries.length > 0) {
78
- issues.push({
79
- ...ISSUE_DEFINITIONS.HREFLANG_INVALID,
80
- affectedUrls: [url],
81
- details: { invalidLanguages: invalidEntries.map(e => e.lang) },
82
- });
83
- }
84
-
85
- // Check for missing self-reference
86
- if (!hasSelfReference) {
87
- issues.push({
88
- ...ISSUE_DEFINITIONS.HREFLANG_SELF_MISSING,
89
- affectedUrls: [url],
90
- });
91
- }
92
-
93
- // Check for missing x-default
94
- if (!hasXDefault && entries.length > 1) {
95
- issues.push({
96
- ...ISSUE_DEFINITIONS.HREFLANG_X_DEFAULT_MISSING,
97
- affectedUrls: [url],
98
- });
99
- }
100
-
101
- // Validate hreflang URLs if enabled
102
- if (options.validateUrls) {
103
- for (const entry of entries) {
104
- if (!entry.isSelfReference && entry.href) {
105
- try {
106
- const response = await httpHead(entry.href, {
107
- timeout: 5000,
108
- maxRedirects: 0,
109
- validateStatus: () => true,
110
- });
111
- entry.statusCode = response.status;
112
-
113
- if (response.status >= 300) {
114
- issues.push({
115
- ...ISSUE_DEFINITIONS.HREFLANG_TO_NON_200,
116
- affectedUrls: [url],
117
- details: {
118
- targetUrl: entry.href,
119
- lang: entry.lang,
120
- statusCode: response.status
121
- },
122
- });
123
- }
124
- } catch {
125
- entry.statusCode = 0;
126
- issues.push({
127
- ...ISSUE_DEFINITIONS.HREFLANG_TO_NON_200,
128
- affectedUrls: [url],
129
- details: {
130
- targetUrl: entry.href,
131
- lang: entry.lang,
132
- statusCode: 'unreachable'
133
- },
134
- });
135
- }
136
- }
137
- }
138
-
139
- // Check for reciprocal links
140
- for (const entry of entries) {
141
- if (!entry.isSelfReference && entry.href && entry.statusCode === 200) {
142
- try {
143
- const response = await httpGet<string>(entry.href, { timeout: 5000 });
144
- const $target = cheerio.load(response.data);
145
- const hasReturnLink = $target(`link[rel="alternate"][hreflang][href*="${new URL(url).hostname}"]`).length > 0;
146
-
147
- if (!hasReturnLink) {
148
- issues.push({
149
- ...ISSUE_DEFINITIONS.HREFLANG_NO_RETURN,
150
- affectedUrls: [url],
151
- details: {
152
- targetUrl: entry.href,
153
- lang: entry.lang
154
- },
155
- });
156
- }
157
- } catch {
158
- // Skip if can't fetch
159
- }
160
- }
161
- }
162
- }
163
-
164
- return { issues, data };
165
- }
166
-
167
- function normalizeUrl(urlStr: string): string {
168
- try {
169
- const parsed = new URL(urlStr);
170
- return `${parsed.protocol}//${parsed.host}${parsed.pathname}`.replace(/\/$/, '');
171
- } catch {
172
- return urlStr;
173
- }
174
- }