{"id":20129325,"url":"https://github.com/aicore/core-analytics-client-lib","last_synced_at":"2025-10-16T07:32:43.477Z","repository":{"id":39270854,"uuid":"455874338","full_name":"aicore/core-analytics-client-lib","owner":"aicore","description":"analytics client library for https://github.com/aicore/Core-Analytics-Server","archived":false,"fork":false,"pushed_at":"2025-09-25T14:47:33.000Z","size":216,"stargazers_count":0,"open_issues_count":14,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-25T16:38:25.350Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aicore.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-02-05T13:15:29.000Z","updated_at":"2022-02-05T13:16:05.000Z","dependencies_parsed_at":"2023-02-08T18:45:28.001Z","dependency_job_id":"71960c1e-b9d4-4228-a727-ba639d818c7e","html_url":"https://github.com/aicore/core-analytics-client-lib","commit_stats":{"total_commits":70,"total_committers":4,"mean_commits":17.5,"dds":0.2571428571428571,"last_synced_commit":"42a5ebe277df4efe2f9a5c6d891d9bdb4357d1bd"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":"aicore/template-nodejs","purl":"pkg:github/aicore/core-analytics-client-lib","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aicore%2Fcore-analytics-client-lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aicore%2Fcore-analytics-client-lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aicore%2Fcore-analytics-client-lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aicore%2Fcore-analytics-client-lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aicore","download_url":"https://codeload.github.com/aicore/core-analytics-client-lib/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aicore%2Fcore-analytics-client-lib/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279014111,"owners_count":26085463,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T20:33:34.774Z","updated_at":"2025-10-16T07:32:43.455Z","avatar_url":"https://github.com/aicore.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Core Analytics Client Lib - JS\nThe Javascript client library to be used from browser/nodejs to raise analytics\nevents for [Core-Analytics-Server](https://github.com/aicore/Core-Analytics-Server).\n\n## Code Guardian\n[![\u003capp\u003e build verification](https://github.com/aicore/core-analytics-client-lib/actions/workflows/build_verify.yml/badge.svg)](https://github.com/aicore/core-analytics-client-lib/actions/workflows/build_verify.yml)\n\n\u003ca href=\"https://sonarcloud.io/summary/new_code?id=aicore_core-analytics-client-lib\"\u003e\n  \u003cimg src=\"https://sonarcloud.io/api/project_badges/measure?project=aicore_core-analytics-client-lib\u0026metric=alert_status\" alt=\"Sonar code quality check\" /\u003e\n  \u003cimg src=\"https://sonarcloud.io/api/project_badges/measure?project=aicore_core-analytics-client-lib\u0026metric=security_rating\" alt=\"Security rating\" /\u003e\n  \u003cimg src=\"https://sonarcloud.io/api/project_badges/measure?project=aicore_core-analytics-client-lib\u0026metric=vulnerabilities\" alt=\"vulnerabilities\" /\u003e\n  \u003cimg src=\"https://sonarcloud.io/api/project_badges/measure?project=aicore_core-analytics-client-lib\u0026metric=coverage\" alt=\"Code Coverage\" /\u003e\n  \u003cimg src=\"https://sonarcloud.io/api/project_badges/measure?project=aicore_core-analytics-client-lib\u0026metric=bugs\" alt=\"Code Bugs\" /\u003e\n  \u003cimg src=\"https://sonarcloud.io/api/project_badges/measure?project=aicore_core-analytics-client-lib\u0026metric=reliability_rating\" alt=\"Reliability Rating\" /\u003e\n  \u003cimg src=\"https://sonarcloud.io/api/project_badges/measure?project=aicore_core-analytics-client-lib\u0026metric=sqale_rating\" alt=\"Maintainability Rating\" /\u003e\n  \u003cimg src=\"https://sonarcloud.io/api/project_badges/measure?project=aicore_core-analytics-client-lib\u0026metric=ncloc\" alt=\"Lines of Code\" /\u003e\n  \u003cimg src=\"https://sonarcloud.io/api/project_badges/measure?project=aicore_core-analytics-client-lib\u0026metric=sqale_index\" alt=\"Technical debt\" /\u003e\n\u003c/a\u003e\n\n# Usage\n\n## Load the Library\nEmbed the script in your HTML file and replace `your_analytics_account_ID` and `appName`\nin the `initAnalyticsSession` call below: \n```html\n\u003c!-- Global window.analytics object - core.ai analytics services --\u003e\n\u003cscript async src=\"https://unpkg.com/@aicore/core-analytics-client-lib/src/analytics.js\"\n        onload=\"analyticsLibLoaded()\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n    if(!window.analytics){ window.analytics = {\n        _initData : [], loadStartTime: new Date().getTime(),\n        event: function (){window.analytics._initData.push(arguments);}\n    };}\n    function analyticsLibLoaded() {\n        initAnalyticsSession('your_analytics_account_ID', 'appName');\n        analytics.event(\"core-analytics\", \"client-lib\", \"loadTime\", 1, (new Date().getTime())-analytics.loadStartTime);\n    }\n\u003c/script\u003e\n```\nThis will create a global `analytics` variable which can be used to access the analytics APIs. \n\nNB: The script is loaded async, so it will not block other js scripts. `analytics.event` api can be called anytime\nafter the above code and need not wait for the script load to complete.\n\n## Raising analytics events\nWe can now start logging analytics events by calling `analytics.event` API.\nThe events will be aggregated and send to the analytics server periodically.\n\n```javascript\n// analyticsEvent(eventType, eventCategory, subCategory, eventCount, eventValue);\n\n// Eg: event without counts and values\nanalytics.event(\"platform\", \"os\", \"linux\");\n\n// Eg: event with count, here it logs that html file is opened 100 times\nanalytics.event(\"file\", \"opened\", \"html\", 100);\n\n// Eg: event with count and value, here it logs that the startup time is 250 milliseconds. \n// Note that the value is unitless from analytics perspective. unit is deduced from subCategory name\nanalytics.event(\"platform\", \"performance\", \"startupTimeMs\", 1, 250);\n\n// Eg: event with fractional value.\nanalytics.event(\"platform\", \"CPU\", \"utilization\", 1, .45);\n// Eg. Here we register that the system has 8 cores with each core having 2300MHz frequency.\nanalytics.event(\"platform\", \"CPU\", \"coreCountsAndFrequencyMhz\", 8, 2300);\n```\n### API parameters\n* `eventType` - A string, required\n* `eventCategory` - A string, required\n* `subCategory` - A string, required\n* `eventCount` (_Optional_) : A non-negative number indicating the number of times the event (or an event with a\n  particular value if a value is specified) happened. defaults to 1.\n* `eventValue` (_Optional_) : A number value associated with the event. defaults to 0\n\n\n## Advanced Usages\n\n### Pure JS loading instead of HTML scripts\n\nThere may be cases where you would want to load the script from JS alone. For Eg. you\nmay want to delay library loading till user consents GDPR. For such use cases, use the below code.\n\n```js\nfunction _initCoreAnalytics() {\n    // Load core analytics scripts\n    if(!window.analytics){ window.analytics = {\n        _initData: [], loadStartTime: new Date().getTime(),\n        event: function (){window.analytics._initData.push(arguments);}\n    };}\n    let script = document.createElement('script');\n    script.type = 'text/javascript';\n    script.async = true;\n    script.onload = function(){\n        // replace `your_analytics_account_ID` and `appName` below with your values \n        window.initAnalyticsSession('your_analytics_account_ID', 'appName'); // if you have a custom analytics server\n        window.analytics.event(\"core-analytics\", \"client-lib\", \"loadTime\", 1,\n            (new Date().getTime())- window.analytics.loadStartTime);\n    };\n    script.src = 'https://unpkg.com/@aicore/core-analytics-client-lib/dist/analytics.min.js';\n    document.getElementsByTagName('head')[0].appendChild(script);\n}\n_initCoreAnalytics();\n```\nTo load the library, just call `_initCoreAnalytics()` from JS. Note that you may not be able\nto use `analytics.event()` APIs before `_initCoreAnalytics()` call is made.\n\n### initAnalyticsSession: modify when, where and how analytics lib sends events\n If you want to modify how analytics library collects and sends information, it is recommended to do so\nwith analytics server [accountConfig](https://github.com/aicore/Core-Analytics-Server#accountconfig-configuration).\n\nAlternatively for one off development time uses, the behavior of the library can be configured\nduring the `initAnalyticsSession` call. `initAnalyticsSession()` takes the following parameters:\n\n* `accountID`: Your analytics account id as configured in the server or core.ai analytics\n* `appName`: The app name to log the events against. Eg: \"phoenixCode\"\n* `analyticsURL` (_Optional_): Provide your own analytics server address if you self-hosted the server.\n* `postIntervalSeconds` (_Optional_): This defines the interval between sending analytics events to the server. Default is 1 minutes or server controlled.\n* `granularitySec` (_Optional_): The smallest time period under which the events can be distinguished. Multiple\nevents happening during this time period is aggregated to a count. The default granularity is 3 Seconds or server controlled,\nwhich means that any events that happen within 3 seconds cannot be distinguished in ordering.\n\n#### usageExample\n```javascript\n// Init with default values and server controlled config. use the following `analyticsLibLoaded` function\nfunction analyticsLibLoaded() {\n    initAnalyticsSession('your_analytics_account_ID', 'appName');\n    analytics.event(\"core-analytics\", \"client-lib\", \"loadTime\", 1, (new Date().getTime())-analytics.loadStartTime);\n}\n\n//Replace initAnalyticsSession in analyticsLibLoaded function for the below use cases.\n\n// Example for custom initSession where the analytics aggregated data \n// is posted to custom server https://localhost:3000 every 600 secs\n// with a granularity(resolution) of 5 seconds.\ninitAnalyticsSession(\"accountID\", \"appName\", \"https://localhost:3000\", 600, 5);\n```\n\n### Debug logs\n If you want to see detailed logs on what is happening inside analytics lib, use the below code:\n```js\n// Just before initAnalyticsSession call, set or unset window.analytics.debugMode\nwindow.analytics.debugMode = true;\ninitAnalyticsSession(\"accountID\", \"appName\");\n```\n\n# Contribute to core-analytics-client-lib\n\n## Building\nSince this is a pure JS template project, build command just runs test with coverage.\n```shell\n\u003e npm install   # do this only once.\n\n# Before raising a pull request, run release script and add the generated\n# minified files in dist folder to commits .\n# WARNING!!!: If the minified files are not checked in git push will fail. \n\u003e npm run release\n```\n\n## Linting\nTo lint the files in the project, run the following command:\n```shell\n\u003e npm run lint\n```\nTo Automatically fix lint errors:\n```shell\n\u003e npm run lint:fix\n```\n\n## Testing\nTo run tests, open the file `test/unit-test.html` in the browser.\n\n# Publishing packages to NPM\nTo publish a package to npm, raise a pull request against `npm` branch.\n\n# Dependency updates\n  We use Rennovate for dependency updates: https://blog.logrocket.com/renovate-dependency-updates-on-steroids/\n  * By default, dep updates happen on sunday every week.\n  * The status of dependency updates can be viewed here if you have this repo permissions in github: https://app.renovatebot.com/dashboard#github/aicore/template-nodejs\n  * To edit rennovate options, edit the rennovate.json file in root, see https://docs.renovatebot.com/configuration-options/\n  Refer \n  \n# Code Guardian\nSeveral automated workflows that check code integrity are integrated into this template.\nThese include:\n1. GitHub actions that runs build/test/coverage flows when a contributor raises a pull request\n2. [Sonar cloud](https://sonarcloud.io/) integration using `.sonarcloud.properties`\n   1. In sonar cloud, enable Automatic analysis from `Administration\n      Analysis Method` for the first time ![image](https://user-images.githubusercontent.com/5336369/148695840-65585d04-5e59-450b-8794-54ca3c62b9fe.png)\n\n## IDE setup\nSonarLint is currently available as a free plugin for jetbrains, eclipse, vscode and visual studio IDEs.\nUse sonarLint plugin for webstorm or any of the available\nIDEs from this link before raising a pull request: https://www.sonarlint.org/ .\n\nSonarLint static code analysis checker is not yet available as a Brackets\nextension.\n\n## Internals\n### Testing framework: Mocha , assertion style: chai\n See https://mochajs.org/#getting-started on how to write tests\n Use chai for BDD style assertions (expect, should etc..). See move here: https://www.chaijs.com/guide/styles/#expect\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faicore%2Fcore-analytics-client-lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faicore%2Fcore-analytics-client-lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faicore%2Fcore-analytics-client-lib/lists"}