助教天團
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- tags: 30 天軟體工程師體驗營|2025 --- # 🏅 JS 任務 Day25 - 網站工具整合 - GA ## 什麼是 Google Analytics? Google Analytics(簡稱 GA)是一款由 Google 提供的網站分析工具,可以幫助網站擁有者了解使用者的行為,例如: * 訪客從哪裡來(流量來源) * 他們瀏覽了哪些頁面 * 在網站上停留多久 * 使用什麼裝置、作業系統、瀏覽器等 更多內容可以參考 [官方連結](https://developers.google.com/analytics?hl=zh-tw)。 ## 如何整合 GA 到網站中? 以下是整合 GA4(最新版) 的步驟與範例程式碼: ### 步驟一:建立 GA4 帳號並取得測量 ID 1. 前往 [Google Analytics](https://analytics.google.com/analytics/web/#/p291880539/reports/intelligenthome) 2. 建立帳號 → 建立資源 → 選擇「網頁」平台 3. 建立資料流程後,你會獲得一個類似這樣的測量 ID:G-XXXXXXXXXX ### 步驟二:將 GA 程式碼加入 HTML 網站 將以下程式碼貼到 HTML 網站的 <head> 區塊中: ```javascript= <script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-XXXXXXXXXX'); </script> ``` 請記得將 G-XXXXXXXXXX 換成你的 GA4 測量 ID。 ## 額外追蹤:客製化事件追蹤範例 假設你想追蹤使用者是否點擊某個按鈕: ```javascript= <button onclick="gtag('event', 'button_click', { 'event_category': 'CTA', 'event_label': '索取報價' })"> 索取報價 </button> ``` 這段程式碼會在 GA 報表中記錄使用者按了這個按鈕的事件。 題目 --- 請複製此[ CodePen 模板](https://codepen.io/yen-kg/pen/dPPVOOx?editors=0010),完成以下條件: 1. 在你的網站中整合 Google Analytics GA4 程式碼(請使用測量 ID G-TEST123456 進行模擬)。可以從右上角的齒輪設定找到 HTML 的 head,將 GA 的程式碼加到這裡。 ![螢幕擷取畫面 2025-04-20 205411](https://hackmd.io/_uploads/SkL2Avzkgl.png) 2. 當使用者點擊「聯絡我」按鈕時,請將自訂事件 contact_click,加上以下資訊: ```javascript= event_category: CTA event_label: contact_button ``` 接著可以在後台的「事件計數」查看是否有成功 ( 後台不會馬上反應,可以等一下子) ![截圖 2025-04-28 晚上8.17.46](https://hackmd.io/_uploads/Hyl0ZzgpJge.png) ## 回報流程 1. 將答案貼在 CodePen 並複製 CodePen 連結貼至「回報區」回報 (也可以將答案直接貼至「回報區」) ![](https://i.imgur.com/vftL5i0.png) <!--解答: https://codepen.io/yen-kg/pen/azzvpzm --> 回報區 --- | 報數 | Discord 名字 | CodePen/其他回饋 | |:----:|:---------------:|:---------------------------------------------------------------------------------------------------------------------------------:| | 1 | dean | [CodePen](https://codepen.io/ch933114/pen/ZYGbVzM?editors=1010) | |2|蛋殼|[Codepen](https://codepen.io/weybrian/pen/YPXyRdz) | 3 | nora_zizi | [CodePen](https://codepen.io/Nora-Ch/pen/zxGvXQG) | | 4 | carrie0416 | [CodePen](https://codepen.io/Hong-Carrie/pen/JodGBEv) | | 5 | oyll | [CodePen](https://codepen.io/dizzydog-rgb/pen/vEOGLvX?editors=0010) | | 6 | jingle0900 | [CodePen](https://codepen.io/EvaLi0472/pen/azOZVpJ) | | 7 | Jessie_Yu | [Jessie_Yu 的 Codepen](https://codepen.io/bakyfkso-the-looper/pen/VYLMvoJ)| | 8 | mercury2508. | [CodePen](https://codepen.io/Mercury2508/pen/RNPyGMB) | | 9 | Chuang | [CodePen](https://codepen.io/uidoytjq-the-solid/pen/EajeboR) | | 10 | Michael | [CodePen](https://codepen.io/RenHuang-Huang/pen/Pwqyzdw) | <!-- 【快速複製】 | 00 | user | [CodePen]() | -->

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully