ข้ามไปยังเนื้อหาหลัก
เริ่มต้น CDN
React SPA Programming Languages
ความสำคัญ SEO
95/100

ติดตั้ง SEONuxt CDN บน React (Vite / CRA)

วิธีติดตั้ง SEONuxt CDN ในโปรเจกต์ React SPA (Vite หรือ Create React App) ผ่านไฟล์ index.html

View as Markdown

ภาพรวมและประเด็นสำคัญ (Overview)

สำหรับ React SPA ที่สร้างด้วย Vite หรือ Create React App สามารถวาง <script defer __seonuxt="tracking" ...> ใน <head> และ <seonuxt_main> ท้าย <body> ของไฟล์ index.html (หรือ public/index.html สำหรับ CRA) ได้โดยตรง

สรุปประเด็นสำคัญที่ต้องรู้ (Key Takeaways)
TL;DR • 3 ประเด็น
  1. Vite: แก้ไขไฟล์ index.html ที่ Root ของโปรเจกต์
  2. Create React App: แก้ไขไฟล์ public/index.html
  3. ช่วยให้ SPA มี Meta Tags, Open Graph และ JSON-LD ครบถ้วนบน DOM

องค์ประกอบและข้อกำหนดเชิงลึก (2 หัวข้อ)

Head Integration

1. ติดตั้ง Global Site Tag (seon.js) ใน index.html (Root ของ Vite)

Critical Impact

โหลดแบบ defer ไม่บล็อกการเรนเดอร์หน้าเว็บ

วางแท็ก <script defer __seonuxt="tracking" ...> เป็นรายการแรกใน <head> ของ React (Vite / CRA) เพื่อเริ่มดาวน์โหลดสคริปต์ทันทีโดยไม่กระทบ Core Web Vitals

  • อัปเดต Meta Tags, Open Graph, Twitter Card และ Canonical อัตโนมัติ
  • ฉีด Structured Data (JSON-LD) เข้า <head> โดยไม่ต้องเขียนเองทุกหน้า
  • สลับโหมดพัฒนาด้วย attribute developers และนำออกเมื่อขึ้น Production
คำแนะนำ SEONuxt: ตรวจสอบให้แน่ใจว่าใส่ __seonuxt="tracking" และ data-tracking ตรงตามพร็อพเพอร์ตี้ของคุณ
#React#Vite#SPA#index.html
Body Container

2. วาง Container Tag (<seonuxt_main>) ท้าย <body>

Critical Impact

ตำแหน่งใต้ </footer> ก่อนปิด </body>

เพิ่ม <seonuxt_main section="seonuxt" data-tracking="YOUR-TRACKING-CODE"></seonuxt_main> ท้ายสุดของ Layout หลักใน React (Vite / CRA) เพื่อรองรับ Dynamic Content Container

  • รหัส data-tracking จับคู่กับสคริปต์ใน <head> อัตโนมัติ
  • ไม่รบกวน CSS หรือโครงสร้าง Layout เดิมของเว็บไซต์
คำแนะนำ SEONuxt: วางไว้ใต้ </footer> ก่อนปิดแท็ก </body> ใน Layout หลักที่ใช้ร่วมกันทุกหน้า
#seonuxt_main#React#Vite#SPA#index.html

แนวทางปฏิบัติที่ดี vs ข้อควรเลี่ยง (Do & Don't)

สิ่งที่ควรทำ #1

ติดตั้งใน Master Layout (index.html (Root ของ Vite)) เพียงจุดเดียวเพื่อให้ครอบคลุมทุกหน้าของ React (Vite / CRA)

สิ่งที่ควรหลีกเลี่ยง

คัดลอกสคริปต์ไปวางซ้ำหลายไฟล์ หรือลืมลบ attribute developers ก่อน Deploy Production

เหตุผล: การวางใน Master Layout ช่วยลดการดูแลซ้ำซ้อนและป้องกันสคริปต์ทำงานซ้ำสองรอบในหน้าเดียว

ตัวอย่างโค้ดและโครงสร้าง (Code Examples)

index.html (React + Vite)
html
<!doctype html>
<html lang="th">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>React App</title>
    <script
      defer
      __seonuxt="tracking"
      src="https://cdn.seonuxt.com/seon/tracking.js"
      data-tracking="YOUR-TRACKING-CODE"
      data-api="https://cdn.seonuxt.com"
    ></script>
  </head>
  <body>
    <div id="root"></div>
    <script type="module" src="/src/main.tsx"></script>
    <seonuxt_main section="seonuxt" data-tracking="YOUR-TRACKING-CODE"></seonuxt_main>
  </body>
</html>

วาง <script defer> ใน <head> และ <seonuxt_main> หลัง <div id="root"></div> ก่อนปิด </body>

คำถามที่พบบ่อย (FAQs)

กด Hard Refresh (Cmd+Shift+R / Ctrl+F5) แล้วเปิด DevTools → แท็บ Elements เพื่อดู Meta Tags / JSON-LD ใน <head> (ห้ามดูจาก View Page Source) และพิมพ์ seonuxt.help() ในแท็บ Console
SEONUXT ENGINEERING AUDIT

ติดตั้งบน React (Vite / CRA) เรียบร้อยแล้ว?

ตรวจสอบการทำงานใน DevTools หรือดูรายการ Attributes สำหรับปรับแต่งเพิ่มเติม