gbu-accessibility-package 3.8.9 → 3.10.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/CHANGELOG.md +31 -0
- package/README-vi.md +241 -0
- package/README.md +95 -1
- package/cli.js +176 -105
- package/lib/fixer.js +1002 -81
- package/package.json +11 -3
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,37 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [3.10.0] - 2025-12-09
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- **Meta Tags & Open Graph Protocol Validation**: New `--meta-check` command for comprehensive meta tag validation
|
|
12
|
+
- **4 Required OG Tags Check**: Validates presence of og:title, og:type, og:image, og:url
|
|
13
|
+
- **Syntax Validation**: Detects common mistake of using `name=""` instead of `property=""` for OG tags
|
|
14
|
+
- **Typo Detection**: Detects common typos in property names (og:sitename → og:site_name, og:imge → og:image, etc.)
|
|
15
|
+
- **Levenshtein Distance Algorithm**: Smart typo detection for unknown OG properties
|
|
16
|
+
- **Twitter Card Validation**: Checks twitter:card and related tags with valid value validation
|
|
17
|
+
- **Basic Meta Tags Check**: Validates description, viewport, canonical URL
|
|
18
|
+
- **Content Quality Check**: Title/description length, URL format, empty values
|
|
19
|
+
- **og:image Best Practices**: Suggests og:image:width, og:image:height, og:image:alt
|
|
20
|
+
- **Detailed Suggestions**: Provides specific fix recommendations for each issue
|
|
21
|
+
- **Summary Statistics**: Shows files with OG, issues count, and warnings count
|
|
22
|
+
|
|
23
|
+
- **Auto-Fix Meta Tags**: New `--meta-fix` command for automatic fixing
|
|
24
|
+
- **Typo Auto-Fix**: Automatically corrects misspelled OG/Twitter property names
|
|
25
|
+
- **Syntax Auto-Fix**: Corrects `name=""` to `property=""` for OG tags
|
|
26
|
+
- **Dry-Run Support**: Preview changes with `--meta-fix --dry-run`
|
|
27
|
+
- **Backup Support**: Create backups with `--meta-fix --backup`
|
|
28
|
+
|
|
29
|
+
### Changed
|
|
30
|
+
- **CLI Simplified**: Removed redundant aliases (`--og-check`, `--check-meta`, `--open-graph`), now using only `--meta-check`
|
|
31
|
+
- **Clear Separation**: `--meta-check` for checking only, `--meta-fix` for auto-fixing
|
|
32
|
+
|
|
33
|
+
### Technical
|
|
34
|
+
- **New Methods**: `checkMetaTags()`, `analyzeMetaTags()`, `parseMetaTagAttributes()`, `fixMetaTags()`, `findClosestOGProperty()`, `levenshteinDistance()`
|
|
35
|
+
- **Test Files**: Added `demo/meta-tags-test.html` and `demo/meta-tags-incomplete.html` for testing
|
|
36
|
+
- **npm Scripts**: Added `meta-check` and `meta-fix` scripts
|
|
37
|
+
|
|
38
|
+
|
|
8
39
|
## [3.8.3] - 2025-10-06
|
|
9
40
|
|
|
10
41
|
### Added
|
package/README-vi.md
CHANGED
|
@@ -25,6 +25,8 @@ 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)
|
|
29
|
+
- 🏷️ **Kiểm tra Meta Tags & Open Graph** - Xác thực meta tags theo chuẩn Open Graph Protocol
|
|
28
30
|
- 🗂️ **Unused Files Detection** - Tìm file không được tham chiếu ở đâu trong dự án
|
|
29
31
|
- ☠️ **Dead Code Analysis** - Phát hiện CSS rules và JavaScript functions không sử dụng
|
|
30
32
|
- 📏 **File Size Analysis** - Kiểm tra dung lượng file và đề xuất tối ưu hóa
|
|
@@ -162,9 +164,12 @@ Chế độ sửa lỗi:
|
|
|
162
164
|
--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
165
|
--broken-links Chỉ kiểm tra liên kết external bị hỏng (không tự động sửa)
|
|
164
166
|
--404-resources Chỉ kiểm tra tài nguyên local bị thiếu (không tự động sửa)
|
|
167
|
+
--gtm-check Kiểm tra cài đặt Google Tag Manager (không tự động sửa)
|
|
165
168
|
--unused-files Kiểm tra file không sử dụng trong dự án
|
|
166
169
|
--dead-code Kiểm tra dead code trong CSS và JavaScript
|
|
167
170
|
--file-size, --size-check Kiểm tra dung lượng file và đề xuất tối ưu hóa
|
|
171
|
+
--meta-check Kiểm tra Meta Tags và Open Graph Protocol
|
|
172
|
+
--meta-fix Tự động sửa lỗi chính tả và cú pháp OG/Twitter
|
|
168
173
|
--cleanup-only Chỉ dọn dẹp role attributes trùng lặp
|
|
169
174
|
|
|
170
175
|
Tùy chọn Enhanced Alt:
|
|
@@ -199,9 +204,12 @@ gbu-a11y --headings-only --auto-fix-headings # Tự động sửa heading struc
|
|
|
199
204
|
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
205
|
gbu-a11y --broken-links # Chỉ kiểm tra liên kết external bị hỏng + dọn dẹp
|
|
201
206
|
gbu-a11y --404-resources # Chỉ kiểm tra tài nguyên local bị thiếu + dọn dẹp
|
|
207
|
+
gbu-a11y --gtm-check # Kiểm tra cài đặt Google Tag Manager
|
|
202
208
|
gbu-a11y --unused-files # Kiểm tra file không sử dụng trong dự án
|
|
203
209
|
gbu-a11y --dead-code # Kiểm tra dead CSS và JavaScript code
|
|
204
210
|
gbu-a11y --file-size # Kiểm tra dung lượng file và đề xuất tối ưu hóa
|
|
211
|
+
gbu-a11y --meta-check # Kiểm tra Meta Tags và Open Graph Protocol
|
|
212
|
+
gbu-a11y --meta-fix # Tự động sửa lỗi chính tả và cú pháp OG/Twitter
|
|
205
213
|
|
|
206
214
|
# Tính năng enhanced alt attribute
|
|
207
215
|
gbu-a11y --enhanced-alt # Chế độ enhanced cơ bản
|
|
@@ -373,11 +381,244 @@ await fixer.checkFileSizes('./src');
|
|
|
373
381
|
- JavaScript functions không bao giờ được gọi trong toàn bộ codebase
|
|
374
382
|
- Variables được khai báo nhưng không sử dụng
|
|
375
383
|
- Smart skipping các patterns động và third-party code
|
|
384
|
+
- **Kiểm tra Google Tag Manager** → Xác thực cài đặt GTM
|
|
385
|
+
- Phát hiện GTM script trong phần `<head>`
|
|
386
|
+
- Xác minh noscript fallback trong phần `<body>`
|
|
387
|
+
- Kiểm tra tính nhất quán của container ID
|
|
388
|
+
- Xác thực vị trí đặt đúng của cả hai đoạn mã
|
|
389
|
+
- Báo cáo: cài đặt hoàn chỉnh, thiếu thành phần, vấn đề vị trí
|
|
376
390
|
- **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
391
|
- Phát hiện file lớn vượt ngưỡng khuyến nghị
|
|
378
392
|
- Đề xuất tối ưu hóa theo từng loại file (hình ảnh, CSS, JS, v.v.)
|
|
379
393
|
- Thống kê dung lượng theo loại file
|
|
380
394
|
- Top 10 file có dung lượng lớn nhất
|
|
395
|
+
- **Kiểm tra Meta Tags & Open Graph** → Xác thực meta tags theo chuẩn OGP
|
|
396
|
+
- Kiểm tra 4 thẻ OG bắt buộc: og:title, og:type, og:image, og:url
|
|
397
|
+
- Phát hiện sai cú pháp (dùng name="" thay vì property="")
|
|
398
|
+
- **Phát hiện lỗi chính tả** trong tên property (vd: og:sitename → og:site_name)
|
|
399
|
+
- Kiểm tra Twitter Card tags
|
|
400
|
+
- Xác thực meta description, viewport, canonical URL
|
|
401
|
+
- Đề xuất cải thiện SEO và accessibility
|
|
402
|
+
- **Auto-fix** lỗi chính tả và cú pháp với `--meta-fix`
|
|
403
|
+
|
|
404
|
+
## 🏷️ Xác thực Meta Tags và Open Graph Protocol
|
|
405
|
+
|
|
406
|
+
Tính năng `--meta-check` kiểm tra meta tags theo chuẩn Open Graph Protocol.
|
|
407
|
+
Tính năng `--meta-fix` tự động sửa lỗi chính tả và cú pháp OG/Twitter.
|
|
408
|
+
|
|
409
|
+
### Những gì được kiểm tra
|
|
410
|
+
|
|
411
|
+
1. **4 thẻ OG bắt buộc**: og:title, og:type, og:image, og:url
|
|
412
|
+
2. **Cú pháp đúng**: OG tags phải dùng `property=""` thay vì `name=""`
|
|
413
|
+
3. **Lỗi chính tả**: Phát hiện typo trong tên property (og:sitename, og:imge, twitter:tittle...)
|
|
414
|
+
4. **Twitter Card**: Kiểm tra twitter:card và các thẻ liên quan
|
|
415
|
+
5. **Meta cơ bản**: description, viewport, canonical URL
|
|
416
|
+
6. **Chất lượng nội dung**: Độ dài, giá trị hợp lệ, URL format
|
|
417
|
+
|
|
418
|
+
### Cách sử dụng
|
|
419
|
+
|
|
420
|
+
```bash
|
|
421
|
+
# Kiểm tra meta tags trong toàn bộ dự án
|
|
422
|
+
gbu-a11y --meta-check
|
|
423
|
+
|
|
424
|
+
# Kiểm tra thư mục cụ thể
|
|
425
|
+
gbu-a11y --meta-check ./public
|
|
426
|
+
|
|
427
|
+
# Tự động sửa lỗi chính tả và cú pháp OG/Twitter
|
|
428
|
+
gbu-a11y --meta-fix
|
|
429
|
+
|
|
430
|
+
# Xem trước trước khi sửa
|
|
431
|
+
gbu-a11y --meta-fix --dry-run
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
### Ví dụ kết quả
|
|
435
|
+
|
|
436
|
+
```
|
|
437
|
+
🏷️ Đang kiểm tra Meta Tags và Open Graph Protocol...
|
|
438
|
+
|
|
439
|
+
📁 index.html:
|
|
440
|
+
✅ Open Graph Protocol: Đã cài đặt
|
|
441
|
+
✅ og:title: Trang chủ - GBU Tool
|
|
442
|
+
✅ og:type: website
|
|
443
|
+
✅ og:image: https://example.com/og-image.jpg
|
|
444
|
+
✅ og:url: https://example.com/
|
|
445
|
+
✅ Twitter Card: Đã cài đặt
|
|
446
|
+
|
|
447
|
+
📁 about.html:
|
|
448
|
+
⚠️ Open Graph Protocol: Chưa cài đặt
|
|
449
|
+
❌ Thiếu thẻ OG bắt buộc: Thiếu og:title
|
|
450
|
+
💡 Thêm <meta property="og:title" content="...">
|
|
451
|
+
❌ Sai cú pháp OG: og:image sử dụng name="" thay vì property=""
|
|
452
|
+
💡 Thay đổi từ <meta name="og:image" ...> thành <meta property="og:image" ...>
|
|
453
|
+
⚠️ Thiếu Meta Description: Không tìm thấy thẻ meta description
|
|
454
|
+
💡 Thêm <meta name="description" content="Mô tả trang web của bạn">
|
|
455
|
+
|
|
456
|
+
📊 Tóm tắt: Đã phân tích 2 file
|
|
457
|
+
✅ File có Open Graph: 1
|
|
458
|
+
❌ File có lỗi: 1 (3 vấn đề)
|
|
459
|
+
⚠️ File có cảnh báo: 1 (1 cảnh báo)
|
|
460
|
+
💡 Open Graph Protocol cần có 4 thẻ bắt buộc: og:title, og:type, og:image, og:url
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
### Yêu cầu Open Graph Protocol
|
|
464
|
+
|
|
465
|
+
Để cài đặt OG tags đúng cách, mỗi trang cần có:
|
|
466
|
+
|
|
467
|
+
```html
|
|
468
|
+
<head>
|
|
469
|
+
<!-- Meta cơ bản -->
|
|
470
|
+
<meta charset="UTF-8">
|
|
471
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
472
|
+
<meta name="description" content="Mô tả ngắn gọn về trang">
|
|
473
|
+
<title>Tiêu đề trang</title>
|
|
474
|
+
|
|
475
|
+
<!-- Open Graph Protocol (bắt buộc) -->
|
|
476
|
+
<meta property="og:title" content="Tiêu đề trang">
|
|
477
|
+
<meta property="og:type" content="website">
|
|
478
|
+
<meta property="og:image" content="https://example.com/images/og-image.jpg">
|
|
479
|
+
<meta property="og:url" content="https://example.com/your-page">
|
|
480
|
+
|
|
481
|
+
<!-- Open Graph Protocol (khuyến nghị) -->
|
|
482
|
+
<meta property="og:description" content="Mô tả chi tiết">
|
|
483
|
+
<meta property="og:site_name" content="Tên website">
|
|
484
|
+
<meta property="og:locale" content="vi_VN">
|
|
485
|
+
<meta property="og:image:width" content="1200">
|
|
486
|
+
<meta property="og:image:height" content="630">
|
|
487
|
+
<meta property="og:image:alt" content="Mô tả hình ảnh">
|
|
488
|
+
|
|
489
|
+
<!-- Twitter Card -->
|
|
490
|
+
<meta name="twitter:card" content="summary_large_image">
|
|
491
|
+
<meta name="twitter:title" content="Tiêu đề trang">
|
|
492
|
+
<meta name="twitter:description" content="Mô tả">
|
|
493
|
+
<meta name="twitter:image" content="https://example.com/images/twitter.jpg">
|
|
494
|
+
|
|
495
|
+
<!-- Canonical URL -->
|
|
496
|
+
<link rel="canonical" href="https://example.com/your-page">
|
|
497
|
+
</head>
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
### Các vấn đề thường gặp được phát hiện
|
|
501
|
+
|
|
502
|
+
- ❌ **Thiếu thẻ OG bắt buộc**: og:title, og:type, og:image, og:url
|
|
503
|
+
- ❌ **Sai cú pháp OG**: Dùng `name="og:..."` thay vì `property="og:..."` (✅ tự động sửa)
|
|
504
|
+
- ❌ **Lỗi chính tả OG/Twitter**: og:sitename, og:imge, twitter:tittle... (✅ tự động sửa)
|
|
505
|
+
- ❌ **Giá trị rỗng**: Thẻ meta có content rỗng
|
|
506
|
+
- ❌ **og:url không hợp lệ**: URL không bắt đầu bằng http:// hoặc https://
|
|
507
|
+
- ❌ **twitter:card không hợp lệ**: Giá trị không phải summary, summary_large_image, app, player
|
|
508
|
+
- ⚠️ **og:image không phải URL tuyệt đối**: Nên dùng URL đầy đủ
|
|
509
|
+
- ⚠️ **Thiếu kích thước og:image**: Chưa khai báo og:image:width, og:image:height
|
|
510
|
+
- ⚠️ **Thiếu og:image:alt**: Chưa có mô tả accessibility cho hình ảnh OG
|
|
511
|
+
- ⚠️ **Title/Description quá dài/ngắn**: Ảnh hưởng đến SEO
|
|
512
|
+
- ⚠️ **Thiếu Canonical URL**: Link rel="canonical" chưa được khai báo
|
|
513
|
+
- ⚠️ **Thiếu Twitter Card**: Đã có OG nhưng chưa có Twitter Card
|
|
514
|
+
|
|
515
|
+
### Lỗi chính tả được phát hiện và tự động sửa
|
|
516
|
+
|
|
517
|
+
Công cụ sử dụng **thuật toán Levenshtein Distance** để phát hiện **TẤT CẢ** các lỗi chính tả, không chỉ các lỗi đã được định nghĩa sẵn.
|
|
518
|
+
|
|
519
|
+
#### Cách hoạt động:
|
|
520
|
+
1. **Danh sách lỗi phổ biến** - Phát hiện nhanh các lỗi đã biết (og:sitename, og:imge...)
|
|
521
|
+
2. **Thuật toán Levenshtein** - So sánh với danh sách property hợp lệ và tìm gợi ý gần nhất
|
|
522
|
+
3. **Ngưỡng động** - Dựa trên độ dài property để quyết định có phải typo hay không
|
|
523
|
+
|
|
524
|
+
#### Ví dụ các lỗi được phát hiện tự động:
|
|
525
|
+
|
|
526
|
+
| Lỗi chính tả | Sửa thành | Phương pháp |
|
|
527
|
+
|--------------|-----------|-------------|
|
|
528
|
+
| og:sitename | og:site_name | Danh sách cố định |
|
|
529
|
+
| og:imge | og:image | Danh sách cố định |
|
|
530
|
+
| og:ttle | og:title | Levenshtein (distance=1) |
|
|
531
|
+
| og:descritpion | og:description | Levenshtein (distance=2) |
|
|
532
|
+
| og:locle | og:locale | Levenshtein (distance=1) |
|
|
533
|
+
| og:image:wdth | og:image:width | Levenshtein (distance=1) |
|
|
534
|
+
| twitter:descrption | twitter:description | Levenshtein (distance=1) |
|
|
535
|
+
| twitter:imag | twitter:image | Levenshtein (distance=1) |
|
|
536
|
+
| name="og:..." | property="og:..." | Sai cú pháp |
|
|
537
|
+
|
|
538
|
+
💡 **Mọi property OG/Twitter không hợp lệ đều được kiểm tra và đề xuất sửa!**
|
|
539
|
+
|
|
540
|
+
## 🏷️ Xác thực Google Tag Manager
|
|
541
|
+
|
|
542
|
+
### Những gì được kiểm tra
|
|
543
|
+
|
|
544
|
+
1. **Script trong `<head>`**: Xác minh GTM script có mặt trước thẻ đóng `</head>`
|
|
545
|
+
2. **Noscript trong `<body>`**: Xác nhận noscript fallback ngay sau thẻ mở `<body>`
|
|
546
|
+
3. **Container ID**: Đảm bảo cả hai đoạn mã sử dụng cùng GTM container ID (định dạng: GTM-XXXXXX)
|
|
547
|
+
4. **Xác thực vị trí**: Kiểm tra vị trí tối ưu của cả hai đoạn mã
|
|
548
|
+
|
|
549
|
+
### Cách sử dụng
|
|
550
|
+
|
|
551
|
+
```bash
|
|
552
|
+
# Kiểm tra cài đặt GTM trong toàn bộ dự án
|
|
553
|
+
gbu-a11y --gtm-check
|
|
554
|
+
|
|
555
|
+
# Kiểm tra thư mục cụ thể
|
|
556
|
+
gbu-a11y --gtm-check ./public
|
|
557
|
+
|
|
558
|
+
# Các lệnh thay thế
|
|
559
|
+
gbu-a11y --check-gtm
|
|
560
|
+
gbu-a11y --google-tag-manager
|
|
561
|
+
```
|
|
562
|
+
|
|
563
|
+
### Ví dụ kết quả
|
|
564
|
+
|
|
565
|
+
```
|
|
566
|
+
🏷️ Đang kiểm tra cài đặt Google Tag Manager (GTM)...
|
|
567
|
+
|
|
568
|
+
📁 public/index.html:
|
|
569
|
+
✅ GTM Container ID: GTM-ABC1234
|
|
570
|
+
✅ Script trong head: Đã đặt đúng vị trí trước </head>
|
|
571
|
+
✅ Noscript trong body: Đã đặt đúng vị trí sau <body>
|
|
572
|
+
|
|
573
|
+
📁 public/about.html:
|
|
574
|
+
✅ GTM Container ID: GTM-ABC1234
|
|
575
|
+
✅ Script trong head: Đã đặt đúng vị trí trước </head>
|
|
576
|
+
❌ Noscript trong body: Thiếu sau thẻ <body>
|
|
577
|
+
❌ Thiếu GTM Noscript: Tìm thấy GTM script nhưng thiếu noscript dự phòng trong <body>
|
|
578
|
+
💡 Thêm đoạn mã GTM noscript ngay sau thẻ mở <body>
|
|
579
|
+
|
|
580
|
+
📊 Tóm tắt: Đã phân tích 2 file
|
|
581
|
+
✅ File có GTM: 2
|
|
582
|
+
⚠️ File có vấn đề về GTM: 1
|
|
583
|
+
💡 GTM cần có cả <script> trong <head> và <noscript> sau <body>
|
|
584
|
+
```
|
|
585
|
+
|
|
586
|
+
### Yêu cầu cài đặt GTM
|
|
587
|
+
|
|
588
|
+
Để cài đặt GTM đúng cách, mỗi trang cần có:
|
|
589
|
+
|
|
590
|
+
1. **Đoạn mã script trong `<head>`**:
|
|
591
|
+
```html
|
|
592
|
+
<head>
|
|
593
|
+
<!-- Google Tag Manager -->
|
|
594
|
+
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
|
|
595
|
+
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
|
|
596
|
+
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
|
|
597
|
+
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
|
|
598
|
+
})(window,document,'script','dataLayer','GTM-XXXXXX');</script>
|
|
599
|
+
<!-- End Google Tag Manager -->
|
|
600
|
+
</head>
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
2. **Đoạn mã noscript ngay sau `<body>`**:
|
|
604
|
+
```html
|
|
605
|
+
<body>
|
|
606
|
+
<!-- Google Tag Manager (noscript) -->
|
|
607
|
+
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXX"
|
|
608
|
+
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
|
|
609
|
+
<!-- End Google Tag Manager (noscript) -->
|
|
610
|
+
|
|
611
|
+
<!-- Nội dung trang của bạn -->
|
|
612
|
+
</body>
|
|
613
|
+
```
|
|
614
|
+
|
|
615
|
+
### Các vấn đề thường gặp được phát hiện
|
|
616
|
+
|
|
617
|
+
- ❌ **Thiếu Script**: Không tìm thấy GTM script trong `<head>`
|
|
618
|
+
- ❌ **Thiếu Noscript**: Không tìm thấy noscript fallback sau `<body>`
|
|
619
|
+
- ⚠️ **Vị trí sai**: Script hoặc noscript không ở vị trí tối ưu
|
|
620
|
+
- ❌ **ID không khớp**: Container ID khác nhau giữa script và noscript
|
|
621
|
+
- ⚠️ **Cài đặt không đầy đủ**: Chỉ có một trong hai đoạn mã bắt buộc
|
|
381
622
|
|
|
382
623
|
## 🔧 Quản lý Package
|
|
383
624
|
|
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
|
-
|
|
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
|