gbu-accessibility-package 3.8.9 → 3.9.0

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.
package/README-vi.md CHANGED
@@ -25,6 +25,7 @@ gbu-a11y --forms-only # Sửa form labels + dọn dẹpio/js/gbu-accessib
25
25
  - 🎯 **Nested Controls Detection** - Phát hiện và sửa các control tương tác lồng nhau
26
26
  - 🔍 **Broken Links Detection** - Phát hiện liên kết external bị hỏng
27
27
  - 📁 **404 Resources Detection** - Phát hiện tài nguyên local bị thiếu (hình ảnh, CSS, JS, v.v.)
28
+ - 🏷️ **Kiểm tra Google Tag Manager** - Xác thực cài đặt GTM (script + noscript)
28
29
  - 🗂️ **Unused Files Detection** - Tìm file không được tham chiếu ở đâu trong dự án
29
30
  - ☠️ **Dead Code Analysis** - Phát hiện CSS rules và JavaScript functions không sử dụng
30
31
  - 📏 **File Size Analysis** - Kiểm tra dung lượng file và đề xuất tối ưu hóa
@@ -162,6 +163,7 @@ Chế độ sửa lỗi:
162
163
  --links-check Kiểm tra liên kết bị hỏng và tài nguyên 404 (toàn diện, không tự động sửa)
163
164
  --broken-links Chỉ kiểm tra liên kết external bị hỏng (không tự động sửa)
164
165
  --404-resources Chỉ kiểm tra tài nguyên local bị thiếu (không tự động sửa)
166
+ --gtm-check Kiểm tra cài đặt Google Tag Manager (không tự động sửa)
165
167
  --unused-files Kiểm tra file không sử dụng trong dự án
166
168
  --dead-code Kiểm tra dead code trong CSS và JavaScript
167
169
  --file-size, --size-check Kiểm tra dung lượng file và đề xuất tối ưu hóa
@@ -199,6 +201,7 @@ gbu-a11y --headings-only --auto-fix-headings # Tự động sửa heading struc
199
201
  gbu-a11y --links-check # Kiểm tra liên kết bị hỏng và tài nguyên thiếu + dọn dẹp
200
202
  gbu-a11y --broken-links # Chỉ kiểm tra liên kết external bị hỏng + dọn dẹp
201
203
  gbu-a11y --404-resources # Chỉ kiểm tra tài nguyên local bị thiếu + dọn dẹp
204
+ gbu-a11y --gtm-check # Kiểm tra cài đặt Google Tag Manager
202
205
  gbu-a11y --unused-files # Kiểm tra file không sử dụng trong dự án
203
206
  gbu-a11y --dead-code # Kiểm tra dead CSS và JavaScript code
204
207
  gbu-a11y --file-size # Kiểm tra dung lượng file và đề xuất tối ưu hóa
@@ -373,12 +376,103 @@ await fixer.checkFileSizes('./src');
373
376
  - JavaScript functions không bao giờ được gọi trong toàn bộ codebase
374
377
  - Variables được khai báo nhưng không sử dụng
375
378
  - Smart skipping các patterns động và third-party code
379
+ - **Kiểm tra Google Tag Manager** → Xác thực cài đặt GTM
380
+ - Phát hiện GTM script trong phần `<head>`
381
+ - Xác minh noscript fallback trong phần `<body>`
382
+ - Kiểm tra tính nhất quán của container ID
383
+ - Xác thực vị trí đặt đúng của cả hai đoạn mã
384
+ - Báo cáo: cài đặt hoàn chỉnh, thiếu thành phần, vấn đề vị trí
376
385
  - **Phân tích dung lượng file** → Kiểm tra kích thước file và đề xuất tối ưu hóa
377
386
  - Phát hiện file lớn vượt ngưỡng khuyến nghị
378
387
  - Đề xuất tối ưu hóa theo từng loại file (hình ảnh, CSS, JS, v.v.)
379
388
  - Thống kê dung lượng theo loại file
380
389
  - Top 10 file có dung lượng lớn nhất
381
390
 
391
+ ## 🏷️ Xác thực Google Tag Manager
392
+
393
+ Tính năng `--gtm-check` xác thực cài đặt Google Tag Manager đúng cách trong toàn bộ dự án của bạn.
394
+
395
+ ### Những gì được kiểm tra
396
+
397
+ 1. **Script trong `<head>`**: Xác minh GTM script có mặt trước thẻ đóng `</head>`
398
+ 2. **Noscript trong `<body>`**: Xác nhận noscript fallback ngay sau thẻ mở `<body>`
399
+ 3. **Container ID**: Đảm bảo cả hai đoạn mã sử dụng cùng GTM container ID (định dạng: GTM-XXXXXX)
400
+ 4. **Xác thực vị trí**: Kiểm tra vị trí tối ưu của cả hai đoạn mã
401
+
402
+ ### Cách sử dụng
403
+
404
+ ```bash
405
+ # Kiểm tra cài đặt GTM trong toàn bộ dự án
406
+ gbu-a11y --gtm-check
407
+
408
+ # Kiểm tra thư mục cụ thể
409
+ gbu-a11y --gtm-check ./public
410
+
411
+ # Các lệnh thay thế
412
+ gbu-a11y --check-gtm
413
+ gbu-a11y --google-tag-manager
414
+ ```
415
+
416
+ ### Ví dụ kết quả
417
+
418
+ ```
419
+ 🏷️ Đang kiểm tra cài đặt Google Tag Manager (GTM)...
420
+
421
+ 📁 public/index.html:
422
+ ✅ GTM Container ID: GTM-ABC1234
423
+ ✅ Script trong head: Đã đặt đúng vị trí trước </head>
424
+ ✅ Noscript trong body: Đã đặt đúng vị trí sau <body>
425
+
426
+ 📁 public/about.html:
427
+ ✅ GTM Container ID: GTM-ABC1234
428
+ ✅ Script trong head: Đã đặt đúng vị trí trước </head>
429
+ ❌ Noscript trong body: Thiếu sau thẻ <body>
430
+ ❌ Thiếu GTM Noscript: Tìm thấy GTM script nhưng thiếu noscript dự phòng trong <body>
431
+ 💡 Thêm đoạn mã GTM noscript ngay sau thẻ mở <body>
432
+
433
+ 📊 Tóm tắt: Đã phân tích 2 file
434
+ ✅ File có GTM: 2
435
+ ⚠️ File có vấn đề về GTM: 1
436
+ 💡 GTM cần có cả <script> trong <head> và <noscript> sau <body>
437
+ ```
438
+
439
+ ### Yêu cầu cài đặt GTM
440
+
441
+ Để cài đặt GTM đúng cách, mỗi trang cần có:
442
+
443
+ 1. **Đoạn mã script trong `<head>`**:
444
+ ```html
445
+ <head>
446
+ <!-- Google Tag Manager -->
447
+ <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
448
+ new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
449
+ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
450
+ 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
451
+ })(window,document,'script','dataLayer','GTM-XXXXXX');</script>
452
+ <!-- End Google Tag Manager -->
453
+ </head>
454
+ ```
455
+
456
+ 2. **Đoạn mã noscript ngay sau `<body>`**:
457
+ ```html
458
+ <body>
459
+ <!-- Google Tag Manager (noscript) -->
460
+ <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXX"
461
+ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
462
+ <!-- End Google Tag Manager (noscript) -->
463
+
464
+ <!-- Nội dung trang của bạn -->
465
+ </body>
466
+ ```
467
+
468
+ ### Các vấn đề thường gặp được phát hiện
469
+
470
+ - ❌ **Thiếu Script**: Không tìm thấy GTM script trong `<head>`
471
+ - ❌ **Thiếu Noscript**: Không tìm thấy noscript fallback sau `<body>`
472
+ - ⚠️ **Vị trí sai**: Script hoặc noscript không ở vị trí tối ưu
473
+ - ❌ **ID không khớp**: Container ID khác nhau giữa script và noscript
474
+ - ⚠️ **Cài đặt không đầy đủ**: Chỉ có một trong hai đoạn mã bắt buộc
475
+
382
476
  ## 🔧 Quản lý Package
383
477
 
384
478
  ### Kiểm tra thông tin package
package/README.md CHANGED
@@ -22,6 +22,7 @@
22
22
  - 🎯 **Nested Controls Detection** - Detect and fix nested interactive controls
23
23
  - 🔍 **Broken Links Detection** - Detect broken external links
24
24
  - 📁 **404 Resources Detection** - Detect missing local resources (images, CSS, JS, etc.)
25
+ - 🏷️ **Google Tag Manager Check** - Validate GTM installation (script + noscript)
25
26
  - 🗂️ **Unused Files Detection** - Find files not referenced anywhere in the project
26
27
  - ☠️ **Dead Code Analysis** - Detect unused CSS rules and JavaScript functions
27
28
  - 📏 **File Size Analysis** - Check file sizes and suggest optimizations
@@ -154,9 +155,10 @@ Fix Modes:
154
155
  --landmarks-only Fix landmarks + cleanup
155
156
  --headings-only Analyze heading structure with optional auto-fix
156
157
  --auto-fix-headings Enable automatic heading structure fixes
157
- --links-check Check for broken links and 404 resources (comprehensive, no auto-fix)
158
+ --links-check Check for broken links and 404 resources (comprehensive, no auto-fix)
158
159
  --broken-links Check for broken external links only (no auto-fix)
159
160
  --404-resources Check for missing local resources only (no auto-fix)
161
+ --gtm-check Check Google Tag Manager installation (no auto-fix)
160
162
  --unused-files Check for unused files in project
161
163
  --dead-code Check for dead code in CSS and JavaScript
162
164
  --file-size, --size-check Check file sizes and suggest optimizations
@@ -195,6 +197,7 @@ gbu-a11y --headings-only --auto-fix-headings # Auto-fix heading structure
195
197
  gbu-a11y --links-check # Check broken links and missing resources + cleanup
196
198
  gbu-a11y --broken-links # Check broken external links only + cleanup
197
199
  gbu-a11y --404-resources # Check missing local resources only + cleanup
200
+ gbu-a11y --gtm-check # Check Google Tag Manager installation
198
201
  gbu-a11y --unused-files # Check for unused files in project
199
202
  gbu-a11y --dead-code # Check for dead CSS and JavaScript code
200
203
  gbu-a11y --file-size # Check file sizes and suggest optimizations
@@ -357,12 +360,103 @@ await fixer.checkFileSizes('./src');
357
360
  - JavaScript functions never called
358
361
  - Variables declared but never used
359
362
  - Smart skipping of dynamic patterns
363
+ - **Google Tag Manager Check** → Validate GTM installation
364
+ - Detect GTM script in `<head>` section
365
+ - Verify noscript fallback in `<body>` section
366
+ - Check container ID consistency
367
+ - Validate proper positioning of both snippets
368
+ - Reports: complete installation, missing components, position issues
360
369
  - **File Size Analysis** → Check file sizes and suggest optimizations
361
370
  - Detect large files exceeding recommended thresholds
362
371
  - Type-specific optimization suggestions (images, CSS, JS, etc.)
363
372
  - File size breakdown by type
364
373
  - Top 10 largest files reporting
365
374
 
375
+ ## 🏷️ Google Tag Manager Validation
376
+
377
+ The `--gtm-check` feature validates proper Google Tag Manager installation across your project.
378
+
379
+ ### What It Checks
380
+
381
+ 1. **Script in `<head>`**: Verifies GTM script is present before `</head>` closing tag
382
+ 2. **Noscript in `<body>`**: Confirms noscript fallback is immediately after `<body>` opening tag
383
+ 3. **Container ID**: Ensures both snippets use the same GTM container ID (format: GTM-XXXXXX)
384
+ 4. **Position Validation**: Checks optimal placement of both code snippets
385
+
386
+ ### Usage
387
+
388
+ ```bash
389
+ # Check GTM installation in entire project
390
+ gbu-a11y --gtm-check
391
+
392
+ # Check specific directory
393
+ gbu-a11y --gtm-check ./public
394
+
395
+ # Alternative commands
396
+ gbu-a11y --check-gtm
397
+ gbu-a11y --google-tag-manager
398
+ ```
399
+
400
+ ### Example Output
401
+
402
+ ```
403
+ 🏷️ Đang kiểm tra cài đặt Google Tag Manager (GTM)...
404
+
405
+ 📁 public/index.html:
406
+ ✅ GTM Container ID: GTM-ABC1234
407
+ ✅ Script trong head: Đã đặt đúng vị trí trước </head>
408
+ ✅ Noscript trong body: Đã đặt đúng vị trí sau <body>
409
+
410
+ 📁 public/about.html:
411
+ ✅ GTM Container ID: GTM-ABC1234
412
+ ✅ Script trong head: Đã đặt đúng vị trí trước </head>
413
+ ❌ Noscript trong body: Thiếu sau thẻ <body>
414
+ ❌ Thiếu GTM Noscript: Tìm thấy GTM script nhưng thiếu noscript dự phòng trong <body>
415
+ 💡 Thêm đoạn mã GTM noscript ngay sau thẻ mở <body>
416
+
417
+ 📊 Tóm tắt: Đã phân tích 2 file
418
+ ✅ File có GTM: 2
419
+ ⚠️ File có vấn đề về GTM: 1
420
+ 💡 GTM cần có cả <script> trong <head> và <noscript> sau <body>
421
+ ```
422
+
423
+ ### GTM Installation Requirements
424
+
425
+ For proper GTM installation, each page should have:
426
+
427
+ 1. **Script snippet in `<head>`**:
428
+ ```html
429
+ <head>
430
+ <!-- Google Tag Manager -->
431
+ <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
432
+ new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
433
+ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
434
+ 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
435
+ })(window,document,'script','dataLayer','GTM-XXXXXX');</script>
436
+ <!-- End Google Tag Manager -->
437
+ </head>
438
+ ```
439
+
440
+ 2. **Noscript snippet immediately after `<body>`**:
441
+ ```html
442
+ <body>
443
+ <!-- Google Tag Manager (noscript) -->
444
+ <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXX"
445
+ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
446
+ <!-- End Google Tag Manager (noscript) -->
447
+
448
+ <!-- Your page content -->
449
+ </body>
450
+ ```
451
+
452
+ ### Common Issues Detected
453
+
454
+ - ❌ **Missing Script**: GTM script not found in `<head>`
455
+ - ❌ **Missing Noscript**: Noscript fallback not found after `<body>`
456
+ - ⚠️ **Wrong Position**: Script or noscript not in optimal position
457
+ - ❌ **ID Mismatch**: Different container IDs between script and noscript
458
+ - ⚠️ **Incomplete Installation**: Only one of the two required snippets present
459
+
366
460
  ## 🔧 Package Management
367
461
 
368
462
  ### Check package information