UNPKG

seo-metadata-checker

Version:

Browser-focused SEO metadata checker for SPAs. Automatically monitors and displays SEO tags with real-time route change detection for React, Vue, Angular apps.

294 lines (230 loc) • 7.26 kB
# šŸ” SEO Metadata Checker A **browser-focused npm package** that automatically monitors and displays SEO metadata for Single Page Applications (SPAs). Perfect for **React, Vue, Angular**, and vanilla JavaScript applications. ## ✨ Features - šŸš€ **Auto-initializing** - Works immediately after import - šŸ”„ **Real-time route monitoring** - Detects SPA route changes automatically - šŸ“± **Floating panel display** - Clean, toggleable UI overlay - šŸ“Š **Console logging** - Detailed SEO analysis in DevTools - 🌐 **Global access** - `window.getSeoMetadata()` function - ⚔ **Zero dependencies** - Lightweight and fast - šŸŽÆ **Framework agnostic** - Works with any SPA framework - šŸ”§ **Configurable** - Customize behavior and appearance ## šŸš€ Installation ```bash npm install seo-metadata-checker ``` ## šŸ“– Quick Start ### ES6 Modules ```javascript import 'seo-metadata-checker'; // That's it! The checker auto-initializes and starts monitoring ``` ### CommonJS ```javascript require('seo-metadata-checker'); ``` ### HTML Script Tag ```html <script type="module" src="node_modules/seo-metadata-checker/index.js"></script> ``` ### CDN (via unpkg) ```html <script type="module" src="https://unpkg.com/seo-metadata-checker@latest/index.js"></script> ``` ## šŸ“‹ What It Monitors The package automatically checks and displays: ### šŸ“„ Basic SEO - Page title (`<title>`) - Meta description - Canonical URL - Language attribute - Charset - Viewport settings - Robots meta tag ### šŸ“± Open Graph Tags - `og:title` - `og:description` - `og:image` - `og:url` - `og:type` - `og:site_name` ### 🐦 Twitter Cards - `twitter:card` - `twitter:title` - `twitter:description` - `twitter:image` - `twitter:site` - `twitter:creator` ### šŸ“Š Structured Data - JSON-LD schema.org markup - Automatic parsing and validation ## šŸŽ® Usage Examples ### Programmatic Access ```javascript // Get current page SEO metadata const metadata = window.getSeoMetadata(); console.log(metadata); // Example output: { title: "My Awesome Page", description: "This is a great page about...", canonical: "https://example.com/page", openGraph: { title: "My Awesome Page", description: "This is a great page about...", image: "https://example.com/image.jpg", // ... more OG tags }, twitter: { card: "summary_large_image", title: "My Awesome Page", // ... more Twitter tags }, // ... additional metadata } ``` ### Custom Configuration ```javascript import seoChecker from 'seo-metadata-checker'; // Customize behavior seoChecker.init({ autoShow: true, // Show floating panel automatically position: 'top-left', // Panel position: 'top-left', 'top-right', 'bottom-left', 'bottom-right' logToConsole: true, // Enable console logging panelStyle: 'compact' // Panel style: 'compact' or 'detailed' }); ``` ### Manual Control ```javascript import seoChecker from 'seo-metadata-checker'; // Manual initialization with custom config seoChecker.init({ autoShow: false, // Don't show panel automatically logToConsole: true }); // Manually trigger check and display const metadata = seoChecker.getSeoMetadata(); seoChecker.showPanel(metadata); // Clean up when needed seoChecker.destroy(); ``` ## šŸ”§ Framework Integration ### React ```jsx // App.js or main component import 'seo-metadata-checker'; function App() { return ( <div className="App"> {/* Your app content */} </div> ); } ``` ### Vue ```javascript // main.js import { createApp } from 'vue'; import App from './App.vue'; import 'seo-metadata-checker'; createApp(App).mount('#app'); ``` ### Angular ```typescript // main.ts import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { AppModule } from './app/app.module'; import 'seo-metadata-checker'; platformBrowserDynamic().bootstrapModule(AppModule); ``` ### Next.js ```javascript // pages/_app.js import { useEffect } from 'react'; export default function MyApp({ Component, pageProps }) { useEffect(() => { import('seo-metadata-checker'); }, []); return <Component {...pageProps} />; } ``` ## šŸŽØ UI Features ### Floating Panel - **Compact design** - Minimal screen space usage - **Toggle visibility** - Expand/collapse content - **Issue highlighting** - Visual indicators for SEO problems - **Positioned corners** - Choose your preferred location - **Dark theme** - Easy on the eyes during development ### Console Output ``` šŸ” SEO Metadata Analysis šŸ“„ Title: My Awesome Page šŸ“ Description: This page is about amazing things... šŸ”— Canonical: https://example.com/page 🌐 Language: en šŸ¤– Robots: index,follow šŸ“± Open Graph title: My Awesome Page description: This page is about amazing things... image: https://example.com/og-image.jpg url: https://example.com/page type: website 🐦 Twitter Cards card: summary_large_image title: My Awesome Page description: This page is about amazing things... image: https://example.com/twitter-image.jpg ``` ## āš ļø Issue Detection The package automatically detects common SEO issues: - āŒ Missing page title - āŒ Missing meta description - āŒ Missing language attribute - āŒ Missing Open Graph image - āš ļø Title too long (>60 characters) - āš ļø Description too long (>160 characters) - āš ļø Invalid canonical URL ## šŸ”„ Route Change Detection Works seamlessly with all major SPA routing solutions: - **React Router** - History API monitoring - **Vue Router** - Automatic route detection - **Angular Router** - Navigation change tracking - **Hash routing** - Polling fallback for hash changes - **Custom routing** - MutationObserver for dynamic content ## 🌐 Browser Support - āœ… Chrome 60+ - āœ… Firefox 55+ - āœ… Safari 12+ - āœ… Edge 79+ ## šŸ¤ Contributing Contributions are welcome! Please feel free to submit a Pull Request. ### Development Setup ```bash git clone https://github.com/yourusername/seo-metadata-checker.git cd seo-metadata-checker npm install ``` ### Running Tests ```bash npm test ``` ## šŸ“„ License MIT License - see the [LICENSE](LICENSE) file for details. ## šŸŽÆ Use Cases - **Development debugging** - Quickly verify SEO tags during development - **QA testing** - Ensure proper metadata across all pages - **Social media optimization** - Validate Open Graph and Twitter Cards - **SEO auditing** - Quick checks during content updates - **Team collaboration** - Share SEO status visually ## šŸ“š API Reference ### `window.getSeoMetadata()` Returns complete SEO metadata object for the current page. ### `window.seoMetadataChecker.init(config)` Initialize with custom configuration. ### `window.seoMetadataChecker.showPanel(metadata)` Manually display the floating panel. ### `window.seoMetadataChecker.destroy()` Clean up and remove all event listeners. --- **Made with ā¤ļø for better SEO** Found this useful? Give it a ⭐ on GitHub!