Skip to content
Last updated

About Javascript SDK Version 3.1

Starting from JavaScript SDK v3.1, a new ingestion endpoint is supported in order to improve security and removes ingestion bottlenecks. By using this new endpoint, the following enhancements and changes are introduced:

Visible Changes

  • These values will not be populated anymore, customers needs to obtain them using TD_PARSE_AGENT function by Presto and Hive from td_user_agent :

  • td_browser: client browser

    • td_browser_version: client browser version
    • td_os: client operating system
    • td_os_version: client operating system version
    • NOTE: td_user_agent is populated using JavaScript via navigator.userAgent API
  • JSSDK/version will be added to the end of td_user_agent property

    • i.e. td_user_agent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36;JSSDK/3.1.1"
  • The new endpoint will validate APIKEY once a request is received. If APIKEY is invalid, it will return 401 error immediately.

    • {"code":401,"message":"Credentials are required to access this resource."}

Treasure Data JavaScript SDK Version 3.1 Log Parameters

The TD JS SDK uses the function trackPageview to log the following parameters.

ParameterDescriptionDefault
td_versiontd-js-sdk's versionX
td_client_idclient's uuidNO
td_charsetcharacter setX
td_descriptiondescription meta tagX
td_languagebrowser languageX
td_colorscreen color depthX
td_screenscreen resolutionX
td_viewportviewport sizeX
td_titledocument titleX
td_urldocument urlX
td_user_agentbrowser user agentX
td_platformbrowser platformX
td_hostdocument hostX
td_pathdocument pathnameX
td_referrerdocument referrerX
td_iprequest IP (server)NO
td_browserclient browser (server)X
td_browser_versionclient browser version (server)X
td_osclient operating system (server)X
td_os_versionclient operating system version (server)X
td_global_id3rd party cookieNO
td_ssc_idServer Side CookieNO

Default parameters tracked do not include td_client_id , td.ip , and td_global_id in order to ensure compliance with global privacy laws. You can enable them by calling the td.set command.

How to use a new endpoint

We introduce a new option to opt-in to our new JavaScript endpoint, named useNewJavaScriptEndpoint , which has a true or false value. When you enable this option, you need to change the host configuration as well, so that it will point to our new endpoint.

The host configuration should have the following value, depending on the environment that will be used:

When you opt-out of this feature by either setting the useNewJavaScriptEndpoint to false or not setting it, make sure that you update the host to the old configuration.

var td = new Treasure({
  database: 'foo',
  writeKey: 'your_write_only_key',
  useNewJavaScriptEndpoint: true,
  host: 'us01.records.in.treasuredata.com'
});  

FAQ

  • Can I use existing functions that are supported by previous versions?
    • Yes. The functionalities are same as-is.
  • How can I retrieve td_browser, td_browser_version, td_os, td_os_version by queries?
-- Presto
-- element_at can handle even if the key is missing.
SELECT 
  element_at(
    td_parse_agent(td_user_agent) ,
    'name'
  ) AS td_browser,
  element_at(
    td_parse_agent(td_user_agent) ,
    'version'
  ) AS td_browser_version,
  element_at(
    td_parse_agent(td_user_agent) ,
    'os'
  ) AS td_os,
  element_at(
    td_parse_agent(td_user_agent) ,
    'os_version'
  ) AS td_os_version
FROM
  web_access
  
  -- OR, The following works for both Hive and Presto
  SELECT 
    td_parse_agent(td_user_agent) ['name'] AS td_browser,
    td_parse_agent(td_user_agent) ['version'] AS td_browser_version,
    td_parse_agent(td_user_agent) ['os'] AS td_os,
    td_parse_agent(td_user_agent) ['os_version'] AS td_os_version
  FROM
    web_access

Limitations & Changed Behavior

Using Real-time segmentation requires routing enablement from the Backend. Please reach out to Treasure Data Support and give us the account, database, and table to enable routing for, and we can do that from the backend. We will remove this limitation in the future release.