---
title: "同意ページをカスタムコードで作成する方法"
description: "Klaviyo のホストページ機能を有効にして使用する方法を確認します。この機能を使うと、独自のカスタムコードで独自の設定ページ、購読ページ、購読解除ページを作成できます。"
canonical_url: "https://help.klaviyo.com/hc/ja-jp/articles/115005077067"
markdown_url: "https://help.klaviyo.com/hc/ja-jp/articles/115005077067.md"
locale: "ja-jp"
category: "サインアップフォーム"
section: "同意ページのスタートガイド"
updated: "2025-08-05"
---

# 同意ページをカスタムコードで作成する方法

## このページで学べること

独自の設定ページ、購読ページ、購読解除ページをカスタムコードで作成できるKlaviyoのホスト型ページ機能を有効にして使用する方法をご確認ください。

**📝 Note:** この記事は開発者向けです。Klaviyo では現在、カスタムコードの構築を支援するサービスは提供しておらず、カスタムコードのトラブルシューティングに関するサポートも提供していません。組み込みのアプリ同意ページについては、[同意ページのスタートガイドに関する記事](https://help.klaviyo.com/hc/ja-jp/articles/115005251848.md)をご覧ください。

## 始める前に

**📝 Note:** 有料メール機能が有効で、[アカウントの確認](https://help.klaviyo.com/hc/ja-jp/articles/115000628331.md)に合格したアカウントのみが、カスタムホストページを有効にできます。

ホストページを設定する前に、次の機能を有効にしてください：

1. **[設定] > その他**に進みます。

2. **同意ページ**を選択します。

3. **カスタムホストページ**で、**カスタムページを有効にする**をクリックしてください。



![The Custom Hosted Pages section on the Consent Pages tab in Klaviyo showing the switch to enable hosted pages.](https://cdn.sanity.io/images/6ct6b26e/help-center-prod/ca46854c6eb24b2db423aa0a1af7fc417bd9a281-1354x1170.jpg?auto=format)

カスタムの専用ドメインは任意です；ホストページを有効にするために設定する必要はありません。

## カスタムの同意ページを作成

1. **[設定] > その他**に進みます。

2. **[ホストされたページ]** をクリックします。 

3. *Pages* の横にある **+** 記号をクリックして、新しいページを追加します。

4. このページに名前を付けます（例：unsubscribe.tmpl）、次に**ページを追加**をクリックします。設定、購読、またはメールの購読解除ページとして使用できます。また、必要に応じて2ページ以上作成することもできます。



**📝 Note:** ホストページ名にはスペースを含めることはできません。含めるとエラーが発生します。スペースは避けるか、アンダースコアを使用してタイトルを区切ってください。

1. 任意のフィールドと機能を含む HTML ページをデザインします。カスタム同意ページに挿入できるフィールドの例は次のとおりです：


   - メール配信頻度の選択肢：


     - 購読解除するオプション

     - すべてのメールを受信するオプション

     - 日次、週次、月次などのニュースレターの配信頻度オプション

   - ターゲティングとセグメント化に使用できる情報：

     - ユーザーがセール告知を希望するかどうかを指定するチェックボックス

     - ユーザーが商品のお知らせを希望するかどうかのチェックボックス

     - ユーザーがブログの更新情報を希望するかどうかのチェックボックス

     - ユーザーが参加したいと思う可能性がある他のリスト



**▸ 同意ページ用の HTML コードの例**

この例をunsubscribe.tmplで使用して、メールの種類と配信頻度の設定を収集します。使用する前に、サンプルのロゴ、会社名、プライバシーポリシーへのリンクを自社のものに置き換えてください。

```text
<!DOCTYPE html>
<html lang="en">
   <head>
      <meta charset="utf-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <!-- Latest compiled and minified CSS -->
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
      <style type="text/css">
        /* Space out content a bit */
        body {
            padding-top: 20px;
            padding-bottom: 20px;
        }

        form {
            margin-bottom: 18px;
        }

        /* Custom page header */
        .header {
            border-bottom: 1px solid #e5e5e5;
            margin-bottom: 10px;
        }

        .header h1 {
            margin: 10px 0;
        }

        .required-fields {
            text-align: right;
        }

        .required-fields span {
            color: #a94442;
            font-weight: bold;
        }

        .list-group-item label {
            font-weight: normal;
            margin-top: 17px;
        }

        .list-group-item label input[type="checkbox"] {
            margin-right: 4px;
        }

        .form-group span.required {
            position: absolute;
            top: 0;
            right: 0;
            font-size: 20px;
            color: #a94442;
            font-weight: bold;
            user-select: none;
        }

        label.error {
            color: #a94442;
            font-weight: bold;
            margin-top: 4px;
        }

        .form-actions {
            margin: 25px 0;
        }

        .form-control+.form-control {
            margin-top: 6px;
        }

        .panel-group .panel-title .closed-icon,
        .panel-group .panel-title .open-icon {
            margin-right: 0.5em;
            top: 2px;
        }

        .panel-group .panel-title a:hover,
        .panel-group .panel-title a:active {
            text-decoration: none;
        }

        .panel-group .panel-title a:hover .text,
        .panel-group .panel-title a:active .text {
            text-decoration: underline;
        }

        .panel-group .panel-title .closed-icon {
            display: none;
        }

        .panel-group.closed .panel-title .open-icon {
            display: none;
        }

        .panel-group.closed .panel-title .closed-icon {
            display: inline;
        }

        /* Custom page footer */
        .footer {
            padding-top: 18px;
            border-top: 1px solid #e5e5e5;
        }

        /* Customize container */
        @media (min-width: 768px) {
            .container {
                max-width: 730px;
            }
        }
    </style>
      <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
      <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
      <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
      <![endif]-->
   </head>
   <body>
      <div class="container">
         <div class="header">
            <img src="http://via.placeholder.com/300x75" />
            <h1>Email Preferences</h1>
         </div>
         <form action="" id="preferences_form" method="POST" role="form" class="form-horizontal">
            {% if form.non_field_errors %}
            <div class="alert alert-danger">
               {% for error in form.non_field_errors %}
               {{ error }}{% if not forloop.last %}<br />{% endif %}
               {% endfor %}
            </div>
            {% endif %}
            <input type="hidden" name="$fields" value="EmailInterests,EmailFrequency" />
            <input type="hidden" name="$list_fields" value="EmailInterests" />
            <!-- <input type="hidden" name="$unsubscribed_url" value="/p/preferences_updated" /> -->
            <!-- <input type="hidden" name="$updated_profile_url" value="/p/preferences_updated" /> -->
            <!--<p class="required-fields">
               <span>*</span> Required Information
               </p>-->
            <div class="form-group{% if form.errors|lookup:'$email' %} has-error{% endif %}">
               <label for="email" class="col-sm-3 control-label">Email Address<span class="required">*</span></label>
               <div class="col-sm-9">
                  <input type="email" class="form-control" id="email" name="$email" value="{% if request.POST|lookup:'$email' %}{{ request.POST|lookup:'$email' }}{% else %}{{ person.email|default:'' }}{% endif %}" />
                  {% if form.errors|lookup:'$email' %}
                  <p class="help-block">{% for error in form.errors|lookup:'$email' %}{{ error }}{% endfor %}</p>
                  {% endif %}
               </div>
            </div>
            <div class="form-group">
               <label for="first_name" class="col-sm-3 control-label">First Name</label>
               <div class="col-sm-9">
                  <input type="text" class="form-control" id="first_name" name="$first_name" value="{% if request.POST|lookup:'$email' %}{{ request.POST|lookup:'$first_name' }}{% else %}{{ person.first_name|default:'' }}{% endif %}" />
               </div>
            </div>
            <div class="form-group">
               <label for="last_name" class="col-sm-3 control-label">Last Name</label>
               <div class="col-sm-9">
                  <input type="text" class="form-control" id="last_name" name="$last_name" value="{% if request.POST|lookup:'$email' %}{{ request.POST|lookup:'$last_name' }}{% else %}{{ person.last_name|default:'' }}{% endif %}" />
               </div>
            </div>
            <div class="form-group">
               <label for="interests" class="col-sm-3 control-label">Interests</label>
               <div class="col-sm-9">
                  <div class="checkbox">
                     <label>
                     <input type="checkbox" name="EmailInterests" value="New Releases" {% if 'New Releases' in person.EmailInterests or 'New Releases' in request.POST.EmailInterests %}checked="checked"{% elif not person.EmailInterests and not request.POST.EmailInterests %}{% endif %} />
                     New Product Releases
                     </label>
                  </div>
                  <div class="checkbox">
                     <label>
                     <input type="checkbox" name="EmailInterests" value="Promotions" {% if 'Promotions' in person.EmailInterests or 'Promotions' in request.POST.EmailInterests %}checked="checked"{% elif not person.EmailInterests and not request.POST.EmailInterests %}{% endif %} />
                     Promotions & Sales
                     </label>
                  </div>
                  <div class="checkbox">
                     <label>
                     <input type="checkbox" name="EmailInterests" value="Blog" {% if 'Blog' in person.EmailInterests or 'Blog' in request.POST.EmailInterests %}checked="checked"{% elif not person.EmailInterests and not request.POST.EmailInterests %}{% endif %} />
                     Latest from the Blog
                     </label>
                  </div>
                  <div class="checkbox">
                     <label>
                     <input type="checkbox" name="EmailInterests" value="Events" {% if 'Events' in person.EmailInterests or 'Events' in request.POST.EmailInterests %}checked="checked"{% elif not person.EmailInterests and not request.POST.EmailInterests %}{% endif %} />
                     Events
                     </label>
                  </div>
               </div>
            </div>
            <div class="form-group">
               <label for="interests" class="col-sm-3 control-label">How often would you like to hear from us?</label>
               <div class="col-sm-9">
                  <div class="radio">
                     <label>
                        <!-- Default value. -->
                        <input type="radio" name="EmailFrequency" id="email_frequency_0" value="All" {% if person.EmailFrequency == 'All' or request.POST.EmailFrequency == 'All' %}checked="checked"{% elif not person.EmailFrequency and not request.POST.EmailFrequency %}checked="checked"{% endif %} />
                        Twice per Week
                     </label>
                  </div>
                  <div class="radio">
                     <label>
                     <input type="radio" name="EmailFrequency" id="email_frequency_1" value="Weekly" {% if person.EmailFrequency == 'Weekly' or request.POST.EmailFrequency == 'Weekly' %}checked="checked"{% endif %} />
                     Once per Week
                     </label>
                  </div>
                  <div class="radio">
                     <label>
                     <input type="radio" name="EmailFrequency" id="email_frequency_2" value="Monthly" {% if person.EmailFrequency == 'Monthly' or request.POST.EmailFrequency == 'Monthly' %}checked="checked"{% endif %} />
                     Once per Month
                     </label>
                  </div>
               </div>
            </div>
            <div class="checkbox">
               <label>
               <input type="checkbox" name="$unsubscribe" value="true" />
               <span class="text">Unsubscribe me.</span>
               </label>
            </div>
            <div class="clearfix form-actions">
               <div class="pull-right">
                  <button type="submit" class="btn btn-default btn-primary">Update Preferences</button>
               </div>
            </div>
         </form>
         <footer class="footer">
            <p>
               © 2017 Company Name — <a href="https://www.klaviyo.com" target="_blank">Privacy Policy</a>
            </p>
         </footer>
      </div>
      <!-- /container -->
      <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
      <!-- Latest compiled and minified JavaScript -->
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
      <script src="//cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.13.1/jquery.validate.min.js"></script>
      <script>
        $(function() {
            $('#preferences_form').validate({
                rules: {
                    $email: {
                        required: true
                    }
                },
                messages: {
                    $email: 'Please enter your email address.',
                    $first_name: 'Please enter your first name.',
                    $last_name: 'Please enter your last name.'
                }
            });
            // Toggle validation based on selection.
            $('input[name="$unsubscribe"]').on('change', function() {
                $('form .form-actions button[type="submit"]').toggleClass('cancel', $(this).is(':checked'));
            });
        });
        $('input[name="$unsubscribe"]').on('change', function(){
          $('input[type=checkbox]').not(this).prop('checked', false);
        });
        $('input[type=checkbox]').not('input[name="$unsubscribe"]').on('change', function(){
          $('input[name="$unsubscribe"]').prop('checked', false);
        });
    </script>
   </body>
</html>
```

この例では、メールの興味関心と配信頻度をプロファイルプロパティとして保存します。これらのプロパティを使用してキャンペーンとフローをターゲティングできます；ただし、配信頻度を選択してもメールは自動的にスケジュールされません。購読解除オプションは、アカウントとリストの購読解除設定に従います。

**保存**をクリックし、次に**プレビュー**をクリックして、同意ページに割り当てる前にページを確認してください。

### 送信後のホスト済みページのリダイレクトを設定します（任意）。

デフォルトでは、ホストページ（例：ホストされた設定ページ）が正常に送信されると、ユーザーは 2 か所のうち 1 つにリダイレクトされます。

- 購読解除をリクエストした場合、購読解除確認ページに送信されます。

- プロファイルを更新した場合（または購読解除リクエスト以外の操作を行った場合）、ユーザーは設定確認（成功）ページに送信されます。



リンクがカスタマイズされた同意ページを含むリストに関連付けられている場合、Klaviyoはそのリストの成功ページを使用します。それ以外の場合は、アカウントのデフォルトが使用されます。

サンプルHTMLには、次のオプションのリダイレクト入力が含まれています。これらはデフォルトの動作を上書きしないように、コメントアウトされています：

```text
<!-- <input type="hidden" name="$unsubscribed_url" value="/p/preferences_updated" /> --><!-- <input type="hidden" name="$updated_profile_url" value="/p/preferences_updated" /> -->
```

リダイレクトをカスタマイズするには、該当する入力欄の前後にある`<!--`と`-->`を削除し、その`value="..."`を使用するURLに置き換えてから、**保存**をクリックしてください。購読解除リクエストには`$unsubscribed_url`を、その他の正常な送信には`$updated_profile_url`を使用してください。`/p/preferences_updated`を使用する場合は、まず`preferences_updated.tmpl`という名前のホスト型ページを作成して保存してください。

### ホストされているページにカスタム アセットを追加する（任意）

ホスト型ページで独自の CSS ファイル、JS ファイル、または画像を使用する場合は、 *アセット* の横にある **+** 記号をクリックしてアップロードし、ページのソースコードで参照してください。

Klaviyo アカウントにアップロードしたアセットを参照するには、次のタグを使用します。 `{% asset_url 'style.css' %}`

![source code of your consent page showing uploaded custom asset tag](https://cdn.sanity.io/images/6ct6b26e/help-center-prod/b299c6656d998586712598ad601660bd92b8cf69-2046x1080.jpg?auto=format)

## カスタム同意ページの使用

アカウントのデフォルトの環境設定、購読ページ、およびメールの購読解除ページを、カスタムコードのページに置き換えることができます。個別のリストが独自のカスタムコード化されたページを使用するように設定することもできます。

- 特定のリスト向けに同意ページをカスタマイズしている場合、そのリストにのみ送信されるキャンペーン、およびそのリストによってトリガーされるフロー内のメールでは、それらのページが使用されます。

- カスタマイズされた同意ページがないリストでは、アカウントのデフォルトの同意ページが使用されます。メトリックをトリガーとするフローのメール、複数のリストまたはセグメントに送信されるキャンペーン、または[個別のメール](https://help.klaviyo.com/hc/ja-jp/articles/115005246328.md)など、単一のリストに関連付けられていないメールでも、デフォルトの同意ページが使用されます。



### デフォルトの同意ページをホスト型ページに変更

アカウントのデフォルトの同意ページ（例：設定ページ、購読ページ、またはメールの購読解除ページ）を 1 つ以上カスタム コードのページに置き換えたい場合は、次の手順に従ってください： 

1. Klaviyo の左下隅にある会社名をクリックします。 

2. [**設定**] を選択します。



![Account tab in the bottom left corner with settings selected from the navigation menu](https://cdn.sanity.io/images/6ct6b26e/help-center-prod/37e02a44ad5cc3b2032d30848752a733e9381e0d-452x552.png?auto=format)

3. **その他 > 同意ページ**を選択します。

4. 置き換える予定の同意ページで 3 点リーダーのドロップダウンメニューをクリックし、**[ホストページを使用]** を選択します。




![The Consent Pages tab in Klaviyo showing an the additional options menu open on an example preference page.](https://cdn.sanity.io/images/6ct6b26e/help-center-prod/dc8dc62330f92cca6fc3d284b07d3144e0e11310-1568x498.jpg?auto=format)

5. 表示されるダイアログ ウィンドウで、カスタム ページ ファイルを選択し、**[保存]** をクリックします。 



**📝 Note:** リストによってトリガーされないフローのメール、または複数のリストやセグメントに送信されるキャンペーンの場合は、上記の手順に従って、アカウントのデフォルトの同意ページをカスタムコードで作成したページに置き換えてください。リストトリガーのフローでは、そのリストのカスタム同意ページを使用できます。

### リストにカスタム同意ページを使用する

デフォルトの同意ページではなくカスタムページを使用するには、対象の各リストを個別に設定する必要があります。

1. カスタム ページに接続するリストに移動します。 

2. **同意ページ**タブをクリックしてください。

3. リストがデフォルトの同意ページを使用している場合は、**このリスト用にカスタマイズ**をクリックしてください。リストにすでにカスタマイズ済みの同意ページがある場合は、この手順をスキップしてください。

4. カスタムページに置き換えたい同意ページの下で、3 点のドロップダウンメニューをクリックし、**ホストページを使用** を選択してください。 





![The Subscribe & preferences pages tab for an example list in Klaviyo showing the additional actions menu open on the preferences page.](https://cdn.sanity.io/images/6ct6b26e/help-center-prod/1e1cba988502dc2c82558a30710cd980fc180ebe-1538x1270.jpg?auto=format)

**📝 Note:** 設定ページ、購読ページ、メールの購読解除ページに、ホスト型ページを割り当てることができます。確認メールはホスト型ページに対応していません。

1. 表示されるダイアログ ウィンドウで、カスタム ページ ファイルを選択し、**[保存]** をクリックします。



**📝 Note:** メールでは、標準の Klaviyo の購読解除および配信設定を管理するタグ（例：{% unsubscribe %} と {% manage_preferences %}）を引き続き使用する必要があります。これらのタグはライブメール内でリンクとして表示され、受信者は自動的にカスタムページに移動します。

## ホストされたページ FAQ

**このフォームを正しく送信するために、ページにJavaScriptを追加する必要はありますか？**
カスタムフォームはホストされたページ内にあるため、送信のために追加のJavaScriptやアクションURLは必要ありません。例のように、<form>のmethodをPOSTに設定します。メールでは、標準のKlaviyo購読解除タグまたは設定管理タグを使用して、生成されるリンクで正しいプロファイルが識別されるようにしてください。

**このページはHTMLである必要がありますか？**
このページはHTMLである必要があります。リンクで追加の画像やスタイルシートなどを指定するか、[アセット]の下に個別のファイルをアップロードしてページ内で参照することで、追加の画像やスタイルシートなどを含めることができます。

**Klaviyo はカスタムページの作成を支援できますか？**
Klaviyo は現在、カスタムコードの構築を支援するサービスを提供しておらず、カスタムコードのトラブルシューティングに関するサポートも提供していません。**ホストページ** 機能は、[開発者やコードに精通したマーケター](https://connect.klaviyo.com/)向けに、白紙の状態を提供することを目的としています。

**📝 Note:** [同意ページのスタートガイド](https://help.klaviyo.com/hc/ja-jp/articles/115005251848.md)で、Klaviyo の組み込み同意ページに関するカスタマイズ機能の詳細をご覧ください。

## その他のリソース

- [リストの購読解除ページをカスタマイズする方法](https://help.klaviyo.com/hc/ja-jp/articles/115005079627.md)
  特定の Klaviyo リスト用に購読解除ページをカスタマイズする方法をご確認ください。このページでは、購読者がマーケティングの受信を購読解除できます。 
- [サインアップフォームと購読ページの参照](https://help.klaviyo.com/hc/ja-jp/articles/115005080327.md)
  サインアップフォームや購読ページなど、さまざまな種類のリスト成長ツール、または新しい購読者を収集してエンゲージメントするためのサードパーティ外部連携など、Klaviyo のリスト成長ツールの使用方法をご確認ください。 
- [Klaviyo のカスタム ホストページについて理解する](https://help.klaviyo.com/hc/ja-jp/articles/360057676272.md)
  Klaviyo のカスタム ホスト ページについて、その概要と実行できることを含めて学びます。
