File: examples/worker.js

Recommend this page to a friend!
  Classes of Arturs Sosins   Countly Web SDK   examples/worker.js   Download  
File: examples/worker.js
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: Countly Web SDK
Track site accesses and errors the Countly API
Author: By
Last change: [Web] Add warnings to all SDK example apps that would check if propper credentials have been set or it still has the defaults. (#473)

* feat: add warning for defaults

* Delete screenlog.0

* feat: warn

* Update index.html

* Update index.js

* Update example_ga_adapter.html

* Update example_async.html

* Update example_apm_async.html
Date: 7 months ago
Size: 1,272 bytes
 

Contents

Class file image Download
importScripts("../lib/countly.js"); const STORE={}; // in-memory storage for worker const COUNTLY_SERVER_KEY = "https://your.server.ly"; const COUNTLY_APP_KEY = "YOUR_APP_KEY"; if(COUNTLY_APP_KEY === "YOUR_APP_KEY" || COUNTLY_SERVER_KEY === "https://your.server.ly"){ console.warn("Please do not use default set of app key and server url") } Countly.init({ app_key: COUNTLY_APP_KEY, url: COUNTLY_SERVER_KEY, debug: true, clear_stored_id: true, // Resets the stored device ID on init storage: { getItem: function (key) { return STORE[key]; }, setItem: function (key, value) { STORE[key] = value; }, removeItem: function (key) { delete STORE[key]; } } }); onmessage = function (e) { console.log(`Worker: Message received from main script:[${JSON.stringify(e.data)}]`); const data = e.data.data; const type = e.data.type; if (type === "event") { Countly.add_event(data); } else if (type === "view") { Countly.track_pageview(data); } else if (type === "session") { if (data === "begin_session") { Countly.begin_session(); return; } Countly.end_session(null, true); } }