{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["admonition"]},"redocly_category":"Products","product_name":"Integration Hub","type":"markdown"},"seo":{"title":"Click Tracking With JavaScript SDK","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":"click-tracking-with-javascript-sdk","__idx":0},"children":["Click Tracking With JavaScript SDK"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This article describes how to track click events with JavaScript SDK."]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/products/customer-data-platform/integration-hub/streaming/td-javascript-sdk/click-tracking-with-javascript-sdk#prerequisites"},"children":["Prerequisites"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/products/customer-data-platform/integration-hub/streaming/td-javascript-sdk/click-tracking-with-javascript-sdk#tracking-clicks-on-links"},"children":["Tracking Clicks on Links"]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"prerequisites","__idx":1},"children":["Prerequisites"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Basic knowledge of JavaScript and HTML."]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Basic knowledge of Treasure Data."]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Basic knowledge of Treasure Data JavaScript SDK."]}]}]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Treasure Data recommends you verify the implementation of any new features or functionality at your site using the Treasure Data JavaScript SDK version 3 before you start using it in production. It manages cookies differently. Be aware when referring to most of these articles that you need to define the suggested event collectors and Treasure Data JavaScript SDK version 3 calls in your solutions.For example, change //cdn.treasuredata.com/sdk/2.5/td.min.js to //cdn.treasuredata.com/sdk/3.0.0/td.min.js."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"tracking-clicks-on-links","__idx":2},"children":["Tracking Clicks on Links"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["When you have links to external sites on which you can not track pageview and would like to track which link the user clicked,"]},{"$$mdtype":"Tag","name":"ol","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Track click actions by calling ",{"$$mdtype":"Tag","name":"em","attributes":{},"children":["trackEvent"]}," function in link-tag using ",{"$$mdtype":"Tag","name":"em","attributes":{},"children":["onClick"]},"."]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The following example sends the default tracking data and link_url data to ",{"$$mdtype":"Tag","name":"em","attributes":{},"children":["pageviews"]}," table when the user clicks the link."]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Optionally, review ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://docs.treasuredata.com/smart/project-integrations/google-tag-manager-import-integration"},"children":["Google Tag Manager"]},"."]}]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"html","header":{"controls":{"copy":{}}},"source":"<html>\n  <head>\n  <!-- Treasure Data -->\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    \n  var td = new Treasure({\n    protocol: 'https',\n    host: 'in.treasuredata.com',\n    writeKey: 'xxxxx', // PLEASE MODIFY HERE\n    database: 'xxxxx'  // PLEASE MODIFY HERE\n  });\n      \n  // Enable cross-domain tracking\n  td.set('$global', 'td_global_id', 'td_global_id');\n      \n  // track pageview information to 'pageviews' table\n  td.trackPageview('pageviews');\n      \n  function tracklink(link_url) {\n    td.trackEvent('pageviews', {link_url: link_url});\n  }\n  </script>\n</head>\n<body>\n  Hello Treasure Data!\n    <A href=\"hellotd_link1.html\" onClick=\"tracklink('hello_link1.html')\">link1</A>\n    <A href=\"hellotd_link2.html\" onClick=\"tracklink('hello_link2.html')\">link2</A>\n    <A href=\"hellotd_link3.html\" onClick=\"tracklink('hello_link3.html')\">link3</A>    \n  </body>\n</html>\n","lang":"html"},"children":[]}]},"headings":[{"value":"Click Tracking With JavaScript SDK","id":"click-tracking-with-javascript-sdk","depth":1},{"value":"Prerequisites","id":"prerequisites","depth":2},{"value":"Tracking Clicks on Links","id":"tracking-clicks-on-links","depth":1}],"frontmatter":{"seo":{"title":"Click Tracking With JavaScript SDK"}},"lastModified":"2026-05-14T07:31:32.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/products/customer-data-platform/integration-hub/streaming/td-javascript-sdk/click-tracking-with-javascript-sdk","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}