- 登錄 Google Analytics,創建一個新帳戶或使用現有帳戶。
- 在 Google Analytics 中創建一個新的網站屬性,填寫網站 URL,並按照指示完成設置。
- 複製 Google Analytics 的跟蹤代碼。
- 登錄 WordPress 網站的後台管理系統,進入外觀 > 編輯器。
- 找到 functions.php 文件,並在檔案底部添加以下程式碼:
add_action('wp_head', 'wpb_add_googleanalytics');
function wpb_add_googleanalytics() { ?>
// 將複製的 Google Analytics 跟蹤代碼粘貼在此處
- 將複製的 Google Analytics 跟蹤代碼粘貼到上面程式碼的注釋部分。
- 保存 functions.php 文件。
完成這些步驟後,Google Analytics 就已經設置完成了,你可以開始使用它來監測網站的訪問量和其他數據。
English Version
- Log in to Google Analytics and create a new account or use an existing account.
- Create a new website property in Google Analytics, fill in the website URL, and follow the instructions to complete the setup.
- Copy the Google Analytics tracking code.
- Log in to the WordPress website’s admin dashboard, and go to Appearance > Editor.
- Find the functions.php file and add the following code at the bottom of the file:
add_action('wp_head', 'wpb_add_googleanalytics');
function wpb_add_googleanalytics() { ?>
// Paste the copied Google Analytics tracking code here
- Paste the copied Google Analytics tracking code into the commented section of the code above.
- Save the functions.php file.
After completing these steps, Google Analytics is fully set up, and you can start using it to monitor your website’s traffic and other data.
日本語版
- Google Analyticsにログインし、新しいアカウントを作成するか、既存のアカウントを使用します。
- Google Analyticsで新しいウェブサイトプロパティを作成し、ウェブサイトのURLを入力して、指示に従って設定を完了します。
- Google Analyticsのトラッキングコードをコピーします。
- WordPressウェブサイトの管理画面にログインし、外観 > エディターに移動します。
- functions.phpファイルを見つけ、ファイルの末尾に以下のコードを追加します:
add_action('wp_head', 'wpb_add_googleanalytics');
function wpb_add_googleanalytics() { ?>
// コピーしたGoogle Analyticsのトラッキングコードをここに貼り付けます
- コピーしたGoogle Analyticsのトラッキングコードを、上記コードのコメント部分に貼り付けます。
- functions.phpファイルを保存します。
これらの手順を完了すると、Google Analyticsの設定が完了し、ウェブサイトのアクセス数やその他のデータの監視を開始できます。