{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-@l10n/ja/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["partial"]},"type":"markdown"},"seo":{"title":"Ruby SDK Data Import","description":"Treasure AI Product Documentation · Collect and Unify · Segment and Activate · Experiment and Analyze · Decisioning Automate with AI Scale and Trust.","siteUrl":"https://docs.treasure.ai","lang":"en-US","jsonLd":{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.treasure.ai/","name":"Treasure AI","url":"https://www.treasure.ai/","logo":"https://www.treasure.ai/hubfs/assets/images/logos/primary-logo.svg"},{"@type":"WebSite","@id":"https://docs.treasure.ai/#website","name":"Treasure AI Documentation","url":"https://docs.treasure.ai/","inLanguage":["en","ja"],"publisher":{"@id":"https://www.treasure.ai/"}}]},"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":"ruby-sdk-data-import","__idx":0},"children":["Ruby SDK Data Import"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This article describes how to import the data from your Ruby applications using Treasure Data’s Ruby SDK."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"prerequisites","__idx":1},"children":["Prerequisites"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Basic knowledge of Ruby, Gems, and Bundler."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Basic knowledge of Treasure Data."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Ruby 3.4 or higher (for local testing)."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"install-td-gem","__idx":2},"children":["Install ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["td"]}," Gem"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Add the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["td"]}," (Treasure Data) gem to your ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Gemfile"]},"."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"gem 'td', \"~> 3.0.0\"\n"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Install the gem locally via bundler."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"bundle install\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"modify-your-app","__idx":3},"children":["Modify Your App"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["td"]}," gem comes with a built-in library for recording in-app events. Insert code, as shown in the following example, to record events from your app. Further details regarding the event logger API can be found in the GitHub repository ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://github.com/treasure-data/td-logger-ruby"},"children":["td-logger-ruby"]},"."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["YOUR_API_KEY"]}," should be your actual apikey string."]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["YOUR_API_KEY"]}," は、実際の apikey 文字列に置き換える必要があります。API キーは、Treasure コンソール のプロファイルから取得できます。",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/products/my-settings/getting-your-api-keys"},"children":["Write-only API key"]}," の使用が推奨されます。"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"ruby","header":{"controls":{"copy":{}}},"source":"# Initialization\nTreasureData::Logger.open('production',\n                          :apikey=>\"YOUR_API_KEY\",\n                          :auto_create_table=>true)\n\n# Example1: login event\nTD.event.post('login', {:uid=>123})\n\n# Example2: follow event\nTD.event.post('follow', {:uid=>123, :from=>'TreasureData', :to=>'kzk_mover'})\n\n# Example3: pay event\nTD.event.post('pay',\n              {:uid=>123, :item_name=>'Stone of Jordan',\n               :category=>'ring', :price=>100, :count=>1})\n\n","lang":"ruby"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Your event-logging code should be placed near its corresponding event-generating code."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["When using the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["td"]}," gem, the posted records are buffered in the memory locally at first, and the data is uploaded every 5 minutes. Because a dedicated thread uploads the data into the cloud, it doesn’t affect your application’s response time."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The local buffer also has a size limit. If the local data exceeds this limit, the records are uploaded immediately."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"confirming-data-import","__idx":4},"children":["Confirming Data Import"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The data gets uploaded every 5 minutes. You can confirm the data import from Treasure Console or CLI."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["From Treasure Console"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["To confirm that your data has been uploaded successfully, check your dataset from the Treasure Console."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["From CLI"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Issue the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["td tables"]}," command if you have the ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://docs.treasuredata.com/tools/cli-and-sdks/td-toolbelt"},"children":["TD Toolbelt"]}," CLI."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"td tables\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"+------------+------------+------+-----------+\n| Database   | Table      | Type | Count     |\n+------------+------------+------+-----------+\n| production | login      | log  | 1         |\n| production | follow     | log  | 1         |\n| production | pay        | log  | 1         |\n+------------+------------+------+-----------+\n","lang":"bash"},"children":[]}]},"headings":[{"value":"Ruby SDK Data Import","id":"ruby-sdk-data-import","depth":1},{"value":"Prerequisites","id":"prerequisites","depth":3},{"value":"Install td Gem","id":"install-td-gem","depth":3},{"value":"Modify Your App","id":"modify-your-app","depth":3},{"value":"Confirming Data Import","id":"confirming-data-import","depth":3}],"frontmatter":{"seo":{"title":"Ruby SDK Data Import"}},"lastModified":"2026-06-01T09:09:59.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/ja/tools/cli-and-sdks/ruby-sdk-import","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}