@rankcli/agent-runtime 0.0.1

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 (178) hide show
  1. package/README.md +242 -0
  2. package/dist/analyzer-2CSWIQGD.mjs +6 -0
  3. package/dist/chunk-YNZYHEYM.mjs +774 -0
  4. package/dist/index.d.mts +4012 -0
  5. package/dist/index.d.ts +4012 -0
  6. package/dist/index.js +29672 -0
  7. package/dist/index.mjs +28602 -0
  8. package/package.json +53 -0
  9. package/scripts/build-deno.ts +134 -0
  10. package/src/audit/ai/analyzer.ts +347 -0
  11. package/src/audit/ai/index.ts +29 -0
  12. package/src/audit/ai/prompts/content-analysis.ts +271 -0
  13. package/src/audit/ai/types.ts +179 -0
  14. package/src/audit/checks/additional-checks.ts +439 -0
  15. package/src/audit/checks/ai-citation-worthiness.ts +399 -0
  16. package/src/audit/checks/ai-content-structure.ts +325 -0
  17. package/src/audit/checks/ai-readiness.ts +339 -0
  18. package/src/audit/checks/anchor-text.ts +179 -0
  19. package/src/audit/checks/answer-conciseness.ts +322 -0
  20. package/src/audit/checks/asset-minification.ts +270 -0
  21. package/src/audit/checks/bing-optimization.ts +206 -0
  22. package/src/audit/checks/brand-mention-optimization.ts +349 -0
  23. package/src/audit/checks/caching-headers.ts +305 -0
  24. package/src/audit/checks/canonical-advanced.ts +150 -0
  25. package/src/audit/checks/canonical-domain.ts +196 -0
  26. package/src/audit/checks/citation-quality.ts +358 -0
  27. package/src/audit/checks/client-rendering.ts +542 -0
  28. package/src/audit/checks/color-contrast.ts +342 -0
  29. package/src/audit/checks/content-freshness.ts +170 -0
  30. package/src/audit/checks/content-science.ts +589 -0
  31. package/src/audit/checks/conversion-elements.ts +526 -0
  32. package/src/audit/checks/crawlability.ts +220 -0
  33. package/src/audit/checks/directory-listing.ts +172 -0
  34. package/src/audit/checks/dom-analysis.ts +191 -0
  35. package/src/audit/checks/dom-size.ts +246 -0
  36. package/src/audit/checks/duplicate-content.ts +194 -0
  37. package/src/audit/checks/eeat-signals.ts +990 -0
  38. package/src/audit/checks/entity-seo.ts +396 -0
  39. package/src/audit/checks/featured-snippet.ts +473 -0
  40. package/src/audit/checks/freshness-signals.ts +443 -0
  41. package/src/audit/checks/funnel-intent.ts +463 -0
  42. package/src/audit/checks/hreflang.ts +174 -0
  43. package/src/audit/checks/html-compliance.ts +302 -0
  44. package/src/audit/checks/image-dimensions.ts +167 -0
  45. package/src/audit/checks/images.ts +160 -0
  46. package/src/audit/checks/indexnow.ts +275 -0
  47. package/src/audit/checks/interactive-tools.ts +475 -0
  48. package/src/audit/checks/internal-link-graph.ts +436 -0
  49. package/src/audit/checks/keyword-analysis.ts +239 -0
  50. package/src/audit/checks/keyword-cannibalization.ts +385 -0
  51. package/src/audit/checks/keyword-placement.ts +471 -0
  52. package/src/audit/checks/links.ts +203 -0
  53. package/src/audit/checks/llms-txt.ts +224 -0
  54. package/src/audit/checks/local-seo.ts +296 -0
  55. package/src/audit/checks/mobile.ts +167 -0
  56. package/src/audit/checks/modern-images.ts +226 -0
  57. package/src/audit/checks/navboost-signals.ts +395 -0
  58. package/src/audit/checks/on-page.ts +209 -0
  59. package/src/audit/checks/page-resources.ts +285 -0
  60. package/src/audit/checks/pagination.ts +180 -0
  61. package/src/audit/checks/performance.ts +153 -0
  62. package/src/audit/checks/platform-presence.ts +580 -0
  63. package/src/audit/checks/redirect-analysis.ts +153 -0
  64. package/src/audit/checks/redirect-chain.ts +389 -0
  65. package/src/audit/checks/resource-hints.ts +420 -0
  66. package/src/audit/checks/responsive-css.ts +247 -0
  67. package/src/audit/checks/responsive-images.ts +396 -0
  68. package/src/audit/checks/review-ecosystem.ts +415 -0
  69. package/src/audit/checks/robots-validation.ts +373 -0
  70. package/src/audit/checks/security-headers.ts +172 -0
  71. package/src/audit/checks/security.ts +144 -0
  72. package/src/audit/checks/serp-preview.ts +251 -0
  73. package/src/audit/checks/site-maturity.ts +444 -0
  74. package/src/audit/checks/social-meta.test.ts +275 -0
  75. package/src/audit/checks/social-meta.ts +134 -0
  76. package/src/audit/checks/soft-404.ts +151 -0
  77. package/src/audit/checks/structured-data.ts +238 -0
  78. package/src/audit/checks/tech-detection.ts +496 -0
  79. package/src/audit/checks/topical-clusters.ts +435 -0
  80. package/src/audit/checks/tracker-bloat.ts +462 -0
  81. package/src/audit/checks/tracking-verification.test.ts +371 -0
  82. package/src/audit/checks/tracking-verification.ts +636 -0
  83. package/src/audit/checks/url-safety.ts +682 -0
  84. package/src/audit/deno-entry.ts +66 -0
  85. package/src/audit/discovery/index.ts +15 -0
  86. package/src/audit/discovery/link-crawler.ts +232 -0
  87. package/src/audit/discovery/repo-routes.ts +347 -0
  88. package/src/audit/engine.ts +620 -0
  89. package/src/audit/fixes/index.ts +209 -0
  90. package/src/audit/fixes/social-meta-fixes.test.ts +329 -0
  91. package/src/audit/fixes/social-meta-fixes.ts +463 -0
  92. package/src/audit/index.ts +74 -0
  93. package/src/audit/runner.test.ts +299 -0
  94. package/src/audit/runner.ts +130 -0
  95. package/src/audit/types.ts +1953 -0
  96. package/src/content/featured-snippet.ts +367 -0
  97. package/src/content/generator.test.ts +534 -0
  98. package/src/content/generator.ts +501 -0
  99. package/src/content/headline.ts +317 -0
  100. package/src/content/index.ts +62 -0
  101. package/src/content/intent.ts +258 -0
  102. package/src/content/keyword-density.ts +349 -0
  103. package/src/content/readability.ts +262 -0
  104. package/src/executor.ts +336 -0
  105. package/src/fixer.ts +416 -0
  106. package/src/frameworks/detector.test.ts +248 -0
  107. package/src/frameworks/detector.ts +371 -0
  108. package/src/frameworks/index.ts +68 -0
  109. package/src/frameworks/recipes/angular.yaml +171 -0
  110. package/src/frameworks/recipes/astro.yaml +206 -0
  111. package/src/frameworks/recipes/django.yaml +180 -0
  112. package/src/frameworks/recipes/laravel.yaml +137 -0
  113. package/src/frameworks/recipes/nextjs.yaml +268 -0
  114. package/src/frameworks/recipes/nuxt.yaml +175 -0
  115. package/src/frameworks/recipes/rails.yaml +188 -0
  116. package/src/frameworks/recipes/react.yaml +202 -0
  117. package/src/frameworks/recipes/sveltekit.yaml +154 -0
  118. package/src/frameworks/recipes/vue.yaml +137 -0
  119. package/src/frameworks/recipes/wordpress.yaml +209 -0
  120. package/src/frameworks/suggestion-engine.ts +320 -0
  121. package/src/geo/geo-content.test.ts +305 -0
  122. package/src/geo/geo-content.ts +266 -0
  123. package/src/geo/geo-history.test.ts +473 -0
  124. package/src/geo/geo-history.ts +433 -0
  125. package/src/geo/geo-tracker.test.ts +359 -0
  126. package/src/geo/geo-tracker.ts +411 -0
  127. package/src/geo/index.ts +10 -0
  128. package/src/git/commit-helper.test.ts +261 -0
  129. package/src/git/commit-helper.ts +329 -0
  130. package/src/git/index.ts +12 -0
  131. package/src/git/pr-helper.test.ts +284 -0
  132. package/src/git/pr-helper.ts +307 -0
  133. package/src/index.ts +66 -0
  134. package/src/keywords/ai-keyword-engine.ts +1062 -0
  135. package/src/keywords/ai-summarizer.ts +387 -0
  136. package/src/keywords/ci-mode.ts +555 -0
  137. package/src/keywords/engine.ts +359 -0
  138. package/src/keywords/index.ts +151 -0
  139. package/src/keywords/llm-judge.ts +357 -0
  140. package/src/keywords/nlp-analysis.ts +706 -0
  141. package/src/keywords/prioritizer.ts +295 -0
  142. package/src/keywords/site-crawler.ts +342 -0
  143. package/src/keywords/sources/autocomplete.ts +139 -0
  144. package/src/keywords/sources/competitive-search.ts +450 -0
  145. package/src/keywords/sources/competitor-analysis.ts +374 -0
  146. package/src/keywords/sources/dataforseo.ts +206 -0
  147. package/src/keywords/sources/free-sources.ts +294 -0
  148. package/src/keywords/sources/gsc.ts +123 -0
  149. package/src/keywords/topic-grouping.ts +327 -0
  150. package/src/keywords/types.ts +144 -0
  151. package/src/keywords/wizard.ts +457 -0
  152. package/src/loader.ts +40 -0
  153. package/src/reports/index.ts +7 -0
  154. package/src/reports/report-generator.test.ts +293 -0
  155. package/src/reports/report-generator.ts +713 -0
  156. package/src/scheduler/alerts.test.ts +458 -0
  157. package/src/scheduler/alerts.ts +328 -0
  158. package/src/scheduler/index.ts +8 -0
  159. package/src/scheduler/scheduled-audit.test.ts +377 -0
  160. package/src/scheduler/scheduled-audit.ts +149 -0
  161. package/src/test/integration-test.ts +325 -0
  162. package/src/tools/analyzer.ts +373 -0
  163. package/src/tools/crawl.ts +293 -0
  164. package/src/tools/files.ts +301 -0
  165. package/src/tools/h1-fixer.ts +249 -0
  166. package/src/tools/index.ts +67 -0
  167. package/src/tracking/github-action.ts +326 -0
  168. package/src/tracking/google-analytics.ts +265 -0
  169. package/src/tracking/index.ts +45 -0
  170. package/src/tracking/report-generator.ts +386 -0
  171. package/src/tracking/search-console.ts +335 -0
  172. package/src/types.ts +134 -0
  173. package/src/utils/http.ts +302 -0
  174. package/src/wasm-adapter.ts +297 -0
  175. package/src/wasm-entry.ts +14 -0
  176. package/tsconfig.json +17 -0
  177. package/tsup.wasm.config.ts +26 -0
  178. package/vitest.config.ts +15 -0
@@ -0,0 +1,526 @@
1
+ // Conversion Elements & Above-the-Fold Analysis
2
+ // Reference: "4 Steps to Rank #1 in Google (2026 SEO Plan)" by Nathan Gotch
3
+ // "80% of people only read headlines" - above the fold is critical
4
+ // "97% of consumers look at reviews, testimonials can increase conversions by 34%"
5
+
6
+ import * as cheerio from 'cheerio';
7
+ import type { AuditIssue } from '../types.js';
8
+
9
+ export interface AboveFoldAnalysis {
10
+ hasHeadline: boolean;
11
+ headlineText: string | null;
12
+ hasCTA: boolean;
13
+ ctaCount: number;
14
+ ctaTexts: string[];
15
+ hasForm: boolean;
16
+ formType: 'contact' | 'signup' | 'search' | 'calculator' | 'other' | null;
17
+ hasSocialProof: boolean;
18
+ socialProofTypes: string[];
19
+ hasHeroImage: boolean;
20
+ hasVideo: boolean;
21
+ estimatedAboveFoldScore: number; // 0-100
22
+ }
23
+
24
+ export interface SocialProofAnalysis {
25
+ hasTestimonials: boolean;
26
+ testimonialCount: number;
27
+ hasReviews: boolean;
28
+ reviewCount: number;
29
+ hasRatings: boolean;
30
+ averageRating: number | null;
31
+ hasClientLogos: boolean;
32
+ clientLogoCount: number;
33
+ hasCaseStudies: boolean;
34
+ hasAwards: boolean;
35
+ hasCertifications: boolean;
36
+ hasTrustBadges: boolean;
37
+ hasStatistics: boolean;
38
+ statisticsFound: string[];
39
+ socialProofScore: number; // 0-100
40
+ }
41
+
42
+ export interface EngagementTriggers {
43
+ hasCalculator: boolean;
44
+ calculatorTypes: string[];
45
+ hasQuiz: boolean;
46
+ hasInteractiveElement: boolean;
47
+ interactiveTypes: string[];
48
+ hasEmbeddedVideo: boolean;
49
+ videoCount: number;
50
+ hasExpandableContent: boolean;
51
+ hasTabsOrAccordion: boolean;
52
+ hasChatWidget: boolean;
53
+ engagementScore: number; // 0-100
54
+ }
55
+
56
+ export interface ConversionElementsData {
57
+ aboveFold: AboveFoldAnalysis;
58
+ socialProof: SocialProofAnalysis;
59
+ engagementTriggers: EngagementTriggers;
60
+ pageType: 'commercial' | 'informational' | 'mixed' | 'unknown';
61
+ recommendations: string[];
62
+ }
63
+
64
+ // CTA patterns
65
+ const CTA_PATTERNS = [
66
+ /get (started|quote|help|access|now)/i,
67
+ /start (now|free|today|here)/i,
68
+ /sign up/i,
69
+ /subscribe/i,
70
+ /contact us/i,
71
+ /book (a |now|today|call|demo|meeting)/i,
72
+ /schedule/i,
73
+ /request (a |quote|demo|call)/i,
74
+ /free (trial|quote|consultation|estimate)/i,
75
+ /buy now/i,
76
+ /add to cart/i,
77
+ /shop now/i,
78
+ /learn more/i,
79
+ /download/i,
80
+ /try (it |now|free)/i,
81
+ /call (us|now|today)/i,
82
+ /chat (with us|now)/i,
83
+ ];
84
+
85
+ // Social proof selectors and patterns
86
+ const TESTIMONIAL_SELECTORS = [
87
+ '.testimonial', '.testimonials', '[class*="testimonial"]',
88
+ '.review', '.reviews', '[class*="review"]',
89
+ '.quote', '[class*="customer-quote"]',
90
+ '.client-feedback', '[class*="feedback"]',
91
+ 'blockquote[class*="testimonial"]',
92
+ ];
93
+
94
+ const CLIENT_LOGO_SELECTORS = [
95
+ '.client-logos', '.clients', '[class*="client-logo"]',
96
+ '.partner-logos', '.partners', '[class*="partner"]',
97
+ '.trusted-by', '[class*="trusted"]',
98
+ '.as-seen-in', '[class*="featured-in"]',
99
+ '.logo-wall', '.logo-carousel',
100
+ ];
101
+
102
+ /**
103
+ * Analyze above-the-fold content
104
+ */
105
+ export function analyzeAboveFold(html: string): AboveFoldAnalysis {
106
+ const $ = cheerio.load(html);
107
+
108
+ // Get first significant elements (approximating above fold)
109
+ // In a real browser, this would use viewport calculations
110
+ const header = $('header').first();
111
+ const hero = $('.hero, [class*="hero"], .banner, [class*="banner"], .jumbotron, [class*="landing"]').first();
112
+ const firstSection = $('main > section, main > div, body > section').first();
113
+
114
+ // Combine above-fold content
115
+ const headerHtml = header.html() || '';
116
+ const heroOrSectionHtml = hero.length ? (hero.html() || '') : (firstSection.html() || '');
117
+ const aboveFoldHtml = headerHtml + heroOrSectionHtml;
118
+ const $above = cheerio.load(aboveFoldHtml);
119
+
120
+ // Check for headline
121
+ const h1 = $('h1').first();
122
+ const hasHeadline = h1.length > 0;
123
+ const headlineText = h1.text().trim() || null;
124
+
125
+ // Check for CTAs
126
+ const ctaTexts: string[] = [];
127
+ $('a, button').each((_, el) => {
128
+ const text = $(el).text().trim();
129
+ for (const pattern of CTA_PATTERNS) {
130
+ if (pattern.test(text)) {
131
+ ctaTexts.push(text);
132
+ break;
133
+ }
134
+ }
135
+ });
136
+
137
+ // Check for forms
138
+ const forms = $('form');
139
+ let formType: AboveFoldAnalysis['formType'] = null;
140
+ if (forms.length > 0) {
141
+ const formHtml = forms.first().html()?.toLowerCase() || '';
142
+ if (formHtml.includes('calculator') || formHtml.includes('estimate')) {
143
+ formType = 'calculator';
144
+ } else if (formHtml.includes('search') || formHtml.includes('query')) {
145
+ formType = 'search';
146
+ } else if (formHtml.includes('email') && formHtml.includes('subscribe')) {
147
+ formType = 'signup';
148
+ } else if (formHtml.includes('phone') || formHtml.includes('contact') || formHtml.includes('message')) {
149
+ formType = 'contact';
150
+ } else {
151
+ formType = 'other';
152
+ }
153
+ }
154
+
155
+ // Check for social proof in above fold
156
+ const hasSocialProofAbove = $('[class*="testimonial"], [class*="review"], [class*="rating"], [class*="trust"]').length > 0;
157
+ const socialProofTypes: string[] = [];
158
+ if ($('[class*="rating"], [class*="star"]').length > 0) socialProofTypes.push('ratings');
159
+ if ($('[class*="testimonial"]').length > 0) socialProofTypes.push('testimonials');
160
+ if ($('[class*="client-logo"], [class*="trusted"]').length > 0) socialProofTypes.push('client-logos');
161
+
162
+ // Hero image
163
+ const hasHeroImage = hero.find('img').length > 0 || $('header img').length > 0;
164
+
165
+ // Video
166
+ const hasVideo = $('video, iframe[src*="youtube"], iframe[src*="vimeo"]').length > 0;
167
+
168
+ // Calculate score
169
+ let score = 0;
170
+ if (hasHeadline) score += 25;
171
+ if (ctaTexts.length > 0) score += 25;
172
+ if (forms.length > 0) score += 20;
173
+ if (hasSocialProofAbove) score += 15;
174
+ if (hasHeroImage || hasVideo) score += 15;
175
+
176
+ return {
177
+ hasHeadline,
178
+ headlineText,
179
+ hasCTA: ctaTexts.length > 0,
180
+ ctaCount: ctaTexts.length,
181
+ ctaTexts: [...new Set(ctaTexts)].slice(0, 5),
182
+ hasForm: forms.length > 0,
183
+ formType,
184
+ hasSocialProof: hasSocialProofAbove,
185
+ socialProofTypes,
186
+ hasHeroImage,
187
+ hasVideo,
188
+ estimatedAboveFoldScore: score,
189
+ };
190
+ }
191
+
192
+ /**
193
+ * Analyze social proof elements
194
+ */
195
+ export function analyzeSocialProof(html: string): SocialProofAnalysis {
196
+ const $ = cheerio.load(html);
197
+ const text = $('body').text().toLowerCase();
198
+
199
+ // Testimonials
200
+ let testimonialCount = 0;
201
+ for (const selector of TESTIMONIAL_SELECTORS) {
202
+ testimonialCount += $(selector).length;
203
+ }
204
+ const hasTestimonials = testimonialCount > 0;
205
+
206
+ // Reviews
207
+ const reviewElements = $('[class*="review"], [itemtype*="Review"]');
208
+ const hasReviews = reviewElements.length > 0;
209
+ const reviewCount = reviewElements.length;
210
+
211
+ // Ratings
212
+ const ratingElements = $('[class*="rating"], [class*="star"], [itemprop="ratingValue"]');
213
+ const hasRatings = ratingElements.length > 0;
214
+ let averageRating: number | null = null;
215
+ const ratingValue = $('[itemprop="ratingValue"]').first().text();
216
+ if (ratingValue) {
217
+ const parsed = parseFloat(ratingValue);
218
+ if (!isNaN(parsed)) averageRating = parsed;
219
+ }
220
+
221
+ // Client logos
222
+ let clientLogoCount = 0;
223
+ for (const selector of CLIENT_LOGO_SELECTORS) {
224
+ const container = $(selector);
225
+ if (container.length > 0) {
226
+ clientLogoCount = container.find('img').length || 1;
227
+ break;
228
+ }
229
+ }
230
+ const hasClientLogos = clientLogoCount > 0;
231
+
232
+ // Case studies
233
+ const hasCaseStudies =
234
+ $('a[href*="case-stud"], [class*="case-study"]').length > 0 ||
235
+ text.includes('case study') || text.includes('case studies');
236
+
237
+ // Awards
238
+ const hasAwards =
239
+ $('[class*="award"]').length > 0 ||
240
+ text.includes('award-winning') || text.includes('winner');
241
+
242
+ // Certifications
243
+ const hasCertifications =
244
+ $('[class*="certif"], [class*="accredit"]').length > 0 ||
245
+ /certified|accredited|licensed/i.test(text);
246
+
247
+ // Trust badges
248
+ const hasTrustBadges =
249
+ $('[class*="trust-badge"], [class*="security-badge"], [class*="guarantee"]').length > 0;
250
+
251
+ // Statistics (numbers that prove credibility)
252
+ const statisticsFound: string[] = [];
253
+ const statPatterns = [
254
+ /(\d+(?:,\d{3})*\+?)\s*(customers?|clients?|users?|businesses?)/gi,
255
+ /(\d+(?:,\d{3})*\+?)\s*(years?)\s*(of experience|in business)/gi,
256
+ /(\d+)%\s*(satisfaction|success|increase|growth)/gi,
257
+ /\$(\d+(?:,\d{3})*(?:\.\d+)?[MBK]?)\s*(saved|recovered|generated)/gi,
258
+ ];
259
+ for (const pattern of statPatterns) {
260
+ const matches = text.match(pattern);
261
+ if (matches) {
262
+ statisticsFound.push(...matches.slice(0, 3));
263
+ }
264
+ }
265
+ const hasStatistics = statisticsFound.length > 0;
266
+
267
+ // Calculate score
268
+ let score = 0;
269
+ if (hasTestimonials) score += 20;
270
+ if (hasReviews) score += 15;
271
+ if (hasRatings) score += 10;
272
+ if (hasClientLogos) score += 15;
273
+ if (hasCaseStudies) score += 15;
274
+ if (hasAwards || hasCertifications) score += 10;
275
+ if (hasTrustBadges) score += 5;
276
+ if (hasStatistics) score += 10;
277
+
278
+ return {
279
+ hasTestimonials,
280
+ testimonialCount,
281
+ hasReviews,
282
+ reviewCount,
283
+ hasRatings,
284
+ averageRating,
285
+ hasClientLogos,
286
+ clientLogoCount,
287
+ hasCaseStudies,
288
+ hasAwards,
289
+ hasCertifications,
290
+ hasTrustBadges,
291
+ hasStatistics,
292
+ statisticsFound: [...new Set(statisticsFound)].slice(0, 5),
293
+ socialProofScore: Math.min(100, score),
294
+ };
295
+ }
296
+
297
+ /**
298
+ * Detect engagement triggers (interactive elements)
299
+ */
300
+ export function detectEngagementTriggers(html: string): EngagementTriggers {
301
+ const $ = cheerio.load(html);
302
+ const htmlLower = html.toLowerCase();
303
+
304
+ // Calculators
305
+ const calculatorTypes: string[] = [];
306
+ const calcPatterns = [
307
+ { pattern: /calculator/i, type: 'calculator' },
308
+ { pattern: /estimator/i, type: 'estimator' },
309
+ { pattern: /roi.*calculator|calculator.*roi/i, type: 'ROI calculator' },
310
+ { pattern: /price.*calculator|cost.*calculator/i, type: 'price calculator' },
311
+ { pattern: /mortgage.*calculator/i, type: 'mortgage calculator' },
312
+ { pattern: /loan.*calculator/i, type: 'loan calculator' },
313
+ { pattern: /bmi.*calculator/i, type: 'BMI calculator' },
314
+ { pattern: /quote.*tool|instant.*quote/i, type: 'quote tool' },
315
+ ];
316
+
317
+ for (const { pattern, type } of calcPatterns) {
318
+ if (pattern.test(htmlLower)) {
319
+ calculatorTypes.push(type);
320
+ }
321
+ }
322
+ const hasCalculator = calculatorTypes.length > 0;
323
+
324
+ // Quiz
325
+ const hasQuiz =
326
+ $('[class*="quiz"], [id*="quiz"]').length > 0 ||
327
+ /quiz|assessment|self-test/i.test(htmlLower);
328
+
329
+ // Interactive elements
330
+ const interactiveTypes: string[] = [];
331
+ if ($('input[type="range"], .slider, [class*="slider"]').length > 0) interactiveTypes.push('slider');
332
+ if ($('[class*="configurator"], [class*="customizer"]').length > 0) interactiveTypes.push('configurator');
333
+ if ($('canvas, [class*="chart"], [class*="graph"]').length > 0) interactiveTypes.push('charts/graphs');
334
+ if ($('[class*="map"], #map, .map').length > 0) interactiveTypes.push('interactive map');
335
+ if ($('[class*="filter"], [class*="sort"]').length > 0) interactiveTypes.push('filters');
336
+
337
+ const hasInteractiveElement = interactiveTypes.length > 0;
338
+
339
+ // Embedded video
340
+ const videos = $('video, iframe[src*="youtube"], iframe[src*="vimeo"], iframe[src*="wistia"], [class*="video-embed"]');
341
+ const hasEmbeddedVideo = videos.length > 0;
342
+ const videoCount = videos.length;
343
+
344
+ // Expandable content
345
+ const hasExpandableContent =
346
+ $('details, [class*="accordion"], [class*="collapsible"], [class*="expandable"]').length > 0;
347
+
348
+ // Tabs
349
+ const hasTabsOrAccordion =
350
+ $('[role="tablist"], [class*="tabs"], [class*="tab-content"]').length > 0;
351
+
352
+ // Chat widget
353
+ const hasChatWidget =
354
+ $('[class*="chat-widget"], [class*="live-chat"], [id*="chat"]').length > 0 ||
355
+ /intercom|drift|crisp|zendesk|livechat|tidio/i.test(html);
356
+
357
+ // Calculate score
358
+ let score = 0;
359
+ if (hasCalculator) score += 25;
360
+ if (hasQuiz) score += 20;
361
+ if (hasInteractiveElement) score += 15;
362
+ if (hasEmbeddedVideo) score += 20;
363
+ if (hasExpandableContent || hasTabsOrAccordion) score += 10;
364
+ if (hasChatWidget) score += 10;
365
+
366
+ return {
367
+ hasCalculator,
368
+ calculatorTypes,
369
+ hasQuiz,
370
+ hasInteractiveElement,
371
+ interactiveTypes,
372
+ hasEmbeddedVideo,
373
+ videoCount,
374
+ hasExpandableContent,
375
+ hasTabsOrAccordion,
376
+ hasChatWidget,
377
+ engagementScore: Math.min(100, score),
378
+ };
379
+ }
380
+
381
+ /**
382
+ * Detect page type (commercial vs informational)
383
+ */
384
+ export function detectPageType(html: string, url: string): 'commercial' | 'informational' | 'mixed' | 'unknown' {
385
+ const $ = cheerio.load(html);
386
+ const text = $('body').text().toLowerCase();
387
+ const urlLower = url.toLowerCase();
388
+
389
+ let commercialSignals = 0;
390
+ let informationalSignals = 0;
391
+
392
+ // URL signals
393
+ if (/\/product|\/service|\/pricing|\/buy|\/shop|\/contact/i.test(urlLower)) commercialSignals += 2;
394
+ if (/\/blog|\/article|\/guide|\/how-to|\/what-is|\/learn/i.test(urlLower)) informationalSignals += 2;
395
+
396
+ // Content signals
397
+ if (/buy now|add to cart|get quote|contact us|free consultation/i.test(text)) commercialSignals += 2;
398
+ if ($('form').length > 0) commercialSignals += 1;
399
+ if (/pricing|price|\$\d+/i.test(text)) commercialSignals += 1;
400
+
401
+ if (/table of contents|in this article|what you.ll learn/i.test(text)) informationalSignals += 2;
402
+ if ($('article').length > 0) informationalSignals += 1;
403
+ if (text.length > 3000) informationalSignals += 1; // Long content is usually informational
404
+
405
+ if (commercialSignals > informationalSignals + 1) return 'commercial';
406
+ if (informationalSignals > commercialSignals + 1) return 'informational';
407
+ if (commercialSignals > 0 && informationalSignals > 0) return 'mixed';
408
+ return 'unknown';
409
+ }
410
+
411
+ /**
412
+ * Main function: Analyze conversion elements
413
+ */
414
+ export function analyzeConversionElements(
415
+ html: string,
416
+ url: string
417
+ ): { issues: AuditIssue[]; data: ConversionElementsData } {
418
+ const issues: AuditIssue[] = [];
419
+
420
+ const aboveFold = analyzeAboveFold(html);
421
+ const socialProof = analyzeSocialProof(html);
422
+ const engagementTriggers = detectEngagementTriggers(html);
423
+ const pageType = detectPageType(html, url);
424
+
425
+ const recommendations: string[] = [];
426
+
427
+ // Above-the-fold issues for commercial pages
428
+ if (pageType === 'commercial' || pageType === 'mixed') {
429
+ if (!aboveFold.hasCTA) {
430
+ issues.push({
431
+ code: 'COMMERCIAL_NO_CTA',
432
+ severity: 'warning',
433
+ category: 'content',
434
+ title: 'Commercial page without clear CTA',
435
+ description: 'This appears to be a commercial page but has no clear call-to-action.',
436
+ impact: 'Without a CTA, visitors have no clear next step. 80% of users only see above-the-fold content.',
437
+ howToFix: 'Add a prominent CTA button above the fold (e.g., "Get Free Quote", "Contact Us", "Start Free Trial").',
438
+ affectedUrls: [url],
439
+ details: { pageType },
440
+ });
441
+ recommendations.push('Add prominent CTA button above the fold');
442
+ }
443
+
444
+ if (!aboveFold.hasForm && pageType === 'commercial') {
445
+ issues.push({
446
+ code: 'COMMERCIAL_NO_FORM',
447
+ severity: 'notice',
448
+ category: 'content',
449
+ title: 'Commercial page without lead capture form',
450
+ description: 'This commercial page lacks a visible form for lead capture.',
451
+ impact: 'Forms above the fold significantly increase conversion rates.',
452
+ howToFix: 'Add a contact form, quote request, or signup form visible without scrolling.',
453
+ affectedUrls: [url],
454
+ });
455
+ recommendations.push('Add lead capture form above the fold');
456
+ }
457
+
458
+ if (!socialProof.hasTestimonials && !socialProof.hasReviews) {
459
+ issues.push({
460
+ code: 'NO_SOCIAL_PROOF',
461
+ severity: 'warning',
462
+ category: 'content',
463
+ title: 'No testimonials or reviews found',
464
+ description: 'Page lacks testimonials, reviews, or other social proof.',
465
+ impact: '97% of consumers look at reviews. Testimonials can increase conversions by 34%.',
466
+ howToFix: 'Add customer testimonials, reviews, ratings, or case studies to build trust.',
467
+ affectedUrls: [url],
468
+ details: { socialProofScore: socialProof.socialProofScore },
469
+ });
470
+ recommendations.push('Add customer testimonials or reviews');
471
+ }
472
+
473
+ if (!socialProof.hasClientLogos && pageType === 'commercial') {
474
+ recommendations.push('Add client/partner logos for credibility ("Trusted by...")');
475
+ }
476
+ }
477
+
478
+ // Engagement triggers for any page type
479
+ if (!engagementTriggers.hasEmbeddedVideo && !engagementTriggers.hasInteractiveElement) {
480
+ issues.push({
481
+ code: 'NO_ENGAGEMENT_TRIGGERS',
482
+ severity: 'notice',
483
+ category: 'content',
484
+ title: 'No engagement triggers found',
485
+ description: 'Page lacks interactive elements, videos, or calculators.',
486
+ impact: 'Interactive content increases dwell time, a user signal that influences rankings.',
487
+ howToFix: 'Add video content, calculators, interactive tools, or expandable sections.',
488
+ affectedUrls: [url],
489
+ details: { engagementScore: engagementTriggers.engagementScore },
490
+ });
491
+ recommendations.push('Add video or interactive elements to increase engagement');
492
+ }
493
+
494
+ // Calculator suggestion for service pages
495
+ if (pageType === 'commercial' && !engagementTriggers.hasCalculator) {
496
+ const isServicePage = /service|pricing|quote|cost|estimate/i.test(url + html);
497
+ if (isServicePage) {
498
+ recommendations.push('Consider adding a calculator or instant quote tool');
499
+ }
500
+ }
501
+
502
+ // Headline check
503
+ if (!aboveFold.hasHeadline) {
504
+ issues.push({
505
+ code: 'NO_VISIBLE_HEADLINE',
506
+ severity: 'warning',
507
+ category: 'on-page',
508
+ title: 'No H1 headline visible',
509
+ description: 'Page appears to lack a visible H1 headline above the fold.',
510
+ impact: '80% of visitors only read headlines. A strong headline is critical for engagement.',
511
+ howToFix: 'Add a clear, compelling H1 headline that communicates the page value proposition.',
512
+ affectedUrls: [url],
513
+ });
514
+ }
515
+
516
+ return {
517
+ issues,
518
+ data: {
519
+ aboveFold,
520
+ socialProof,
521
+ engagementTriggers,
522
+ pageType,
523
+ recommendations,
524
+ },
525
+ };
526
+ }