What problem does it solve?
This Skill provides expert assistance for importing data to Treasure Data using the JavaScript SDK, simplifying browser-based event tracking, page analytics, and client-side data collection for web applications. It helps users capture rich user behavior data directly from their websites, enabling deeper insights and personalization.
Core Features & Use Cases
- Event Tracking: Guides on implementing
addRecord(), trackPageview(), and trackEvent() for comprehensive user interaction and page view tracking.
- E-commerce & Form Tracking: Provides patterns for tracking e-commerce events (product views, add to cart, purchases) and detailed form interactions (starts, submissions, abandonments).
- Privacy & SPA Support: Explains how to implement privacy controls (consent management, anonymous mode) and track events in Single Page Applications (SPAs) with virtual page views.
- Use Case: A marketing team wants to understand user journeys on their e-commerce website, from product views to purchases. This skill helps a frontend developer implement the TD JavaScript SDK to track all these events, including user IDs and session data, ensuring accurate attribution and funnel analysis.
Quick Start
Add SDK loader to your HTML <head>
<script type="text/javascript">
!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}},n=["addRecord","blockEvents","fetchServerCookie","fetchGlobalID","fetchUserSegments","resetUUID","ready","setSignedMode","setAnonymousMode","set","trackEvent","trackPageview","trackClicks","unblockEvents"],s=0;s<n.length;s++){var c=n[s];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 i=document.getElementsByTagName("script")[0];i.parentNode.insertBefore(o,i)}}("Treasure",this);
</script>
Initialize and track a pageview
<script type="text/javascript">
var treasure = new Treasure({
database: 'your_database_name',
writeKey: 'your_write_only_api_key'
});
treasure.trackPageview('pageviews');
</script>