Realtime SQL Access for Segment

This article describes how to ingest data from Segment (formerly Segment.io) to Treasure Data. We have native connectivity, so you can just visit the Segment UI and add the TD apikey and it’s done! Data ingestion happens every minute, so you can query data almost in real-time.



Table of Contents

Step 1: Create a Segment Account

First, please set up your Segment account from here.



Step 2: Create a Project

Second, create your first project in Segment.



Next, input the project name.



Step 3: Set up Integration

Please click INTEGRATIONS from the left menu, and select TREASURE DATA from the menu.



From Treasure Data console, obtain your write-only API key from Treasure Data and specify the database name.



Step 4: Set up Segment JavaScript SDK

Finally, let’s set up Segment JavaScript SDK. Check Segment API key.



Then, create an empty HTML file with Segment JavaScript SDK.

<html>
  <head>
  <script type="text/javascript">
    !function(){var analytics=window.analytics=window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","group","track","ready","alias","page","once","off","on"];analytics.factory=function(t){return function(){var e=Array.prototype.slice.call(arguments);e.unshift(t);analytics.push(e);return analytics}};for(var t=0;t<analytics.methods.length;t++){var e=analytics.methods[t];analytics[e]=analytics.factory(e)}analytics.load=function(t){var e=document.createElement("script");e.type="text/javascript";e.async=!0;e.src=("https:"===document.location.protocol?"https://":"http://")+"cdn.segment.com/analytics.js/v1/"+t+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(e,n)};analytics.SNIPPET_VERSION="3.0.1";
    analytics.load("YOUR_WRITE_KEY");
    analytics.page()
    }}();
  </script>
  <title>Hello Segment and TreasureData integration!</title>
  </head>
  <body>
    <p>Hello Segment and TreasureData integration!</p>
  </body>
</html>

Open the HTML file above. This will send the event to Segment.



By using Segment Project Debugger, you can confirm if the data is uploaded (or not).



Step 5: Check your Treasure Data account

Visit Treasure Data console to see if the events are coming in.



In this case, you’ll see the events in the page table since we called the analytics.page() function in JavaScript.

References


Last modified: Apr 17 2016 06:59:49 UTC

If this article is incorrect or outdated, or omits critical information, please let us know. For all other issues, please see our support channels.