Migrating from previous version
A previous version (deprecated) of JavaScript SDK is mostly compatible with new SDK. However, it has a few differences:
- Client from npm package should be initialized differently: instead of
eventN.init({...opts})
jitsuClient({...opts})
should be called. The constructed object will have the same API - The data structure sent to sever will be a slightly different which can break database structure and queries
(unless you pass
compat_mode: true
to initialization options) - If you embed Jitsu with HTML snippet you need to use a new one
Migrating npm package#
In order to upgrade an existing npm package (@jitsu/eventnative
) remove an old version
yarn remove @jitsu/eventnative
Add a new package (@jitsu/sdk-js
)
npm install --save @jitsu/sdk-js
Replace eventN.init({...opts})
with let eventN = jitsuClient({...opts})
and use the same methods to send the data. Example
import { eventN } from '@ksense/eventnative';
//init
eventN.init({
key: "${key}",
tracking_host: "https://${host}"
});
//identify user
eventN.id({
"email": getEmail(),
"internal_id": getId()
});
//track page views
eventN.track('app_page');
Migrating snippet#
If you use HTML snippet just migrate it on a new api
Migrating database schema#
New API sends a different JSON to the server unless compat_mode parameter is set to true
. If you want to keep
JSON structure intact use the following pattern:
<script src="%%SERVER%%/s/lib.js"
data-compat-mode="true"
...other params></script>
Otherwise the JSON sent by new SDK will have a little different structure
{
"api_key": "Test",
"src": "jitsu",
"event_type": "pageview",
"event_id": "",
"user": {
"anonymous_id": "sasa7qj2fg"
},
"ids": {},
"user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_3) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/90.0.4430.0 Safari/537.36",
"utc_time": "2021-04-27T16:30:40.759000Z",
"local_tz_offset": -180,
"referer": "",
"url": "http://localhost:60226/test-case/embed.html?gclid=1",
"page_title": "",
"doc_path": "/test-case/embed.html",
"doc_host": "localhost",
"doc_search": "?gclid=1",
"screen_resolution": "1280x720",
"vp_size": "1280x720",
"user_language": "en-US",
"doc_encoding": "UTF-8",
"utm": {},
"click_id": {
"gclid": "1"
}
}
eventn_ctx
node present in old structure, but it's not present in a new one. All children of eventn_ctx
is moved to the root of the object. If you have any
mappings settings that that relies on an old structure (presence of eventn_ctx
node), or have user recognition enabled
you need to make following changes in your configuration
Retroactive users recognition changes#
Jitsu saves each anonymous event JSON in Redis. On each identification event server gets saved events by event id from Redis and updates them in Data warehouse. If you have already had configured users recognition then you should change it in eventnative.yaml according to a new format:
users_recognition:
enabled: true
anonymous_id_node: /eventn_ctx/user/anonymous_id||/user/anonymous_id
identification_nodes:
- /eventn_ctx/user/id||/user/id
- /eventn_ctx/user/email||/user/email
or just:
users_recognition:
enabled: true