{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-@l10n/ja/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["admonition"]},"type":"markdown"},"seo":{"title":"Cookie Consentを使用したJavaScriptでのWeb Tracking","description":"Treasure Data Product Documentation · Collect and Unify · Segment and Activate · Experiment and Analyze · Decisioning Automate with AI Scale and Trust.","siteUrl":"https://docs.treasuredata.com","lang":"en-US","llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"cookie-consentを使用したjavascriptでのweb-tracking","__idx":0},"children":["Cookie Consentを使用したJavaScriptでのWeb Tracking"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Cookie Consentは、ウェブサイトでのcookieの使用についてユーザーに警告するための無料のJavaScript pluginです。GDPRなどのデータプライバシー規制に準拠しながら、高品質なユーザー体験を提供するのに役立つように設計されています。"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://cookieconsent.insites.com/documentation/about-cookie-consent/"},"children":["https://cookieconsent.insites.com/documentation/about-cookie-consent/"]}]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Treasure Dataは、サイトでTreasure Data JavaScript SDK version 3を使用した新機能や機能の実装を推奨しています。cookieの管理方法が異なります。これらの記事のほとんどを参照する際は、提案されたeventコレクターとTreasure Data JavaScript SDK version 3の呼び出しをソリューション内で定義する必要があることに注意してください。"]}]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/ja/products/customer-data-platform/integration-hub/streaming/td-javascript-sdk/web-tracking-with-javascript-using-cookie-consent#customize-your-layout"},"children":["レイアウトのカスタマイズ"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/ja/products/customer-data-platform/integration-hub/streaming/td-javascript-sdk/web-tracking-with-javascript-using-cookie-consent#user-views"},"children":["ユーザービュー"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/ja/products/customer-data-platform/integration-hub/streaming/td-javascript-sdk/web-tracking-with-javascript-using-cookie-consent#run-a-sample"},"children":["サンプルの実行"]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"レイアウトのカスタマイズ","__idx":1},"children":["レイアウトのカスタマイズ"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["以下の例を含む、幅広いレイアウトとカラースキームから選択できます:"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/screen_shot_2019-08-20_at_6.35.39_pm.faadffcfb5aed073a31c735948e0339aa15ae2114079072c23c30f11286d33a8.ad50cbca.png","alt":""},"children":[]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/image-20191008-205449.e893c72cab6bc03544429c9c828ac3acf7ef8d8653eefd6a4811f4eba52c995f.ad50cbca.png","alt":""},"children":[]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"ユーザービュー","__idx":2},"children":["ユーザービュー"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["ユーザーが初めてwebページにアクセスすると、デフォルトで以下の情報が保存されたcookieに含まれます(td_ip、td_client_id、td_global_id)。"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/screen_shot_2019-08-20_at_6.35.39_pm.faadffcfb5aed073a31c735948e0339aa15ae2114079072c23c30f11286d33a8.ad50cbca.png","alt":""},"children":[]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["ユーザーがcookie consent promptで\"Decline\"を選択した場合、以下のfield(td_ip、td_client_id、td_global_id)は、このユーザーによる後続のページ訪問では送信",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["されません"]},"。"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/screen_shot_2019-08-20_at_6.39.09_pm.9b301e0d788206942b968860edf07df290c17ab01a4f9e9bba0ebda10e38fe5e.ad50cbca.png","alt":""},"children":[]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"サンプルの実行","__idx":3},"children":["サンプルの実行"]},{"$$mdtype":"Tag","name":"ol","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["テストを実行するには、test.mdを使用してHTMLを作成する必要があります"," ","以下の内容をカスタマイズした詳細に置き換えます:"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["a. 'WRITE YOUR WRITE ONLY API KEY'"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["b. 'WRITE YOUR DB NAME'"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["c. 'WRITE YOUR TABLE NAME'"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"html","header":{"controls":{"copy":{}}},"source":"<html>\n  <head>\n  <script type=\"text/javascript\">\n    !function(t,e){if(void 0===e[t]){e[t]=function(){e[t].clients.push(this),this._init=[Array.prototype.slice.call(arguments)]},e[t].clients=[];for(var r=function(t){return function(){return this[\"_\"+t]=this[\"_\"+t]||[],this[\"_\"+t].push(Array.prototype.slice.call(arguments)),this}},s=[\"addRecord\",\"blockEvents\",\"fetchServerCookie\",\"fetchGlobalID\",\"fetchUserSegments\",\"resetUUID\",\"ready\",\"setSignedMode\",\"setAnonymousMode\",\"set\",\"trackEvent\",\"trackPageview\",\"trackClicks\",\"unblockEvents\"],n=0;n<s.length;n++){var c=s[n];e[t].prototype[c]=r(c)}var o=document.createElement(\"script\");o.type=\"text/javascript\",o.async=!0,o.src=(\"https:\"===document.location.protocol?\"https:\":\"http:\")+\"//cdn.treasuredata.com/sdk/2.5/td.min.js\";var a=document.getElementsByTagName(\"script\")[0];a.parentNode.insertBefore(o,a)}}(\"Treasure\",this);\n\n    // Configure an instance for your database\n    var td = new Treasure({\n      host: 'in.treasuredata.com',\n      writeKey: 'WRITE YOUR WRITE ONLY API KEY',\n      database: 'WRITE YOUR DB NAME',\n      startInSignedMode: true\n    });\n\n    // Enable cross-domain tracking\n    td.set('$global', 'td_global_id', 'td_global_id');\n    // Track pageview information to a table\n    td.trackPageview('WRITE YOUR TABLE NAME');\n    </script>\n    <!-- =======================================================\n      Start https://cookieconsent.insites.com/ tag\n    ======================================================= -->\n    <link rel=\"stylesheet\" type=\"text/css\" href=\"https://cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.1.0/cookieconsent.min.css\" />\n    <script src=\"https://cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.1.0/cookieconsent.min.js\"></script>\n    <script>\n    window.addEventListener(\"load\", function(){\n      window.cookieconsent.initialise({\n        \"palette\": {\n        \"popup\": {\n          \"background\": \"#3c404d\",\n          \"text\": \"#d6d6d6\"\n        },\n        \"button\": {\n          \"background\": \"#8bed4f\"\n        }\n      },\n        \"type\": \"opt-out\",\n        \"revokable\": true,\n        onStatusChange: function(status) {\n          this.hasConsented() ? td.setSignedMode() : td.setAnonymousMode();\n          },\n        })\n      });\n      </script>\n    </head>\n  <body></body>\n</html>\n","lang":"html"},"children":[]},{"$$mdtype":"Tag","name":"ol","attributes":{"start":2},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["簡単なHTTPサーバーをセットアップします。"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["たとえばMacの場合:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"sudo apachectl start\nsudo cp test.md /Library/WebServer/Documents\n# setup owner and permission same with other files in copy destination folder above\n# sudo chown\n# sudo chmod\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["ブラウザから次のURLにアクセスしてみてください: http://127.0.0.1/test.md"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["または、このライブデモを参照できます: ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://treasure-data.github.io/js-examples/consensus-management/index.html"},"children":["https://treasure-data.github.io/js-examples/consensus-management/index.html"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["下部にバーが表示された空白のページが表示されます。"]},{"$$mdtype":"Tag","name":"ol","attributes":{"start":3},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["\"Allow cookies\"オプションを選択しないでください。"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/screen_shot_2019-03-13_at_18.28.45.ed34df1f38e7b557e489b90bfbf7161a4e292df6e91cd2845493a3bfa8832eb6.ad50cbca.png","alt":""},"children":[]}]},{"$$mdtype":"Tag","name":"ol","attributes":{"start":4},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["ページを数回更新し、tracking情報が送信される宛先tableを確認します。"," ","最大で数分後には、宛先tableでstreamingデータが表示され始めるはずです。"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["以下のようなqueryを実行して、streamingデータを確認します:"]}]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"sql","header":{"controls":{"copy":{}}},"source":"select td_ip,td_client_id,td_global_id from <db name>.<tbl name>\n","lang":"sql"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/screen_shot_2019-03-13_at_18.18.35.050e9f4360943cc3501eea0b94af96ca31e47f6bdbedfb4a98442b5a57d3245d.ad50cbca.png","alt":""},"children":[]}," ","6. test.mdページでDeclineを選択します。"]},{"$$mdtype":"Tag","name":"ol","attributes":{"start":7},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["ページを更新します。更新後、consent promptは表示されなくなります。"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/screen_shot_2019-03-13_at_18.28.45.ed34df1f38e7b557e489b90bfbf7161a4e292df6e91cd2845493a3bfa8832eb6.ad50cbca.png","alt":""},"children":[]}]},{"$$mdtype":"Tag","name":"ol","attributes":{"start":8},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["web trackingの宛先tableを再度確認します。"," ","最大で数分後には、宛先tableで新しいstreamingデータが表示され始めるはずです。"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["以下のようなqueryを実行して確認します:"]}]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"sql","header":{"controls":{"copy":{}}},"source":"select td_ip,td_client_id,td_global_id from <db name>.<tbl name>\n","lang":"sql"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["以下のtableでは、td_ip、td_client_id、td_global_id columnがTDに送信されたstreamingデータから除外されていることがわかります。"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/screen_shot_2019-03-13_at_18.21.49.95acf0d08ec7aa9dc7bf145888f3f1096245066fbd356463fb64f9aea013aca7.ad50cbca.png","alt":""},"children":[]}]},{"$$mdtype":"Tag","name":"ol","attributes":{"start":10},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["ローカルPCでHTTPサーバーの実行を停止し、test.mdファイルを削除することでファイルをクリーンアップできます。"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"sudo apachectl stop\nsudo rm -f Library/WebServer/Documents/test.md\n","lang":"bash"},"children":[]}]},"headings":[{"value":"Cookie Consentを使用したJavaScriptでのWeb Tracking","id":"cookie-consentを使用したjavascriptでのweb-tracking","depth":1},{"value":"レイアウトのカスタマイズ","id":"レイアウトのカスタマイズ","depth":1},{"value":"ユーザービュー","id":"ユーザービュー","depth":1},{"value":"サンプルの実行","id":"サンプルの実行","depth":1}],"frontmatter":{"seo":{"title":"Cookie Consentを使用したJavaScriptでのWeb Tracking"}},"lastModified":"2026-05-14T07:31:32.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/ja/products/customer-data-platform/integration-hub/streaming/td-javascript-sdk/web-tracking-with-javascript-using-cookie-consent","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}