@aicore/core-analytics-client-lib 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +44 -22
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -33,7 +33,7 @@ in the `initAnalyticsSession` call below:
33
33
  };}
34
34
  function analyticsLibLoaded() {
35
35
  initAnalyticsSession('your_analytics_account_ID', 'appName');
36
- analytics.event("core-analytics", "client-lib", "loadTime", 1, (new Date().getTime())-analytics.loadStartTime);
36
+ analytics.valueEvent("core-analytics", "client-lib", "loadTime", (new Date().getTime())-analytics.loadStartTime);
37
37
  }
38
38
  </script>
39
39
  ```
@@ -43,34 +43,56 @@ NB: The script is loaded async, so it will not block other js scripts. `analytic
43
43
  after the above code and need not wait for the script load to complete.
44
44
 
45
45
  ## Raising analytics events
46
- We can now start logging analytics events by calling `analytics.event` API.
47
- The events will be aggregated and send to the analytics server periodically.
46
+ Events are aggregated and sent to the analytics server periodically.
47
+ Two APIs are available depending on your use case:
48
+
49
+ ### `analytics.countEvent` - Count occurrences
50
+ Use this to track how many times something happens.
48
51
 
49
52
  ```javascript
50
- // analyticsEvent(eventType, eventCategory, subCategory, eventCount, eventValue);
53
+ // countEvent(eventType, eventCategory, subCategory, eventCount)
54
+
55
+ // Count a single occurrence
56
+ analytics.countEvent("platform", "os", "linux");
57
+
58
+ // Count multiple occurrences at once (e.g., html file opened 100 times)
59
+ analytics.countEvent("file", "opened", "html", 100);
60
+ ```
61
+
62
+ #### Parameters
63
+ * `eventType` - A string, required
64
+ * `eventCategory` - A string, required
65
+ * `subCategory` - A string, required
66
+ * `eventCount` (_Optional_) : A non-negative number indicating the number of times the event happened. Defaults to 1.
67
+
68
+ ### `analytics.valueEvent` - Track values
69
+ Use this to measure quantities like latencies, durations, sizes, or anything where you need
70
+ running averages and distributions.
51
71
 
52
- // Eg: event without counts and values
53
- analytics.event("platform", "os", "linux");
72
+ ```javascript
73
+ // valueEvent(eventType, eventCategory, subCategory, eventValue, count)
54
74
 
55
- // Eg: event with count, here it logs that html file is opened 100 times
56
- analytics.event("file", "opened", "html", 100);
75
+ // Track startup time of 250 milliseconds
76
+ // Note that the value is unitless from analytics perspective. Unit is deduced from subCategory name.
77
+ analytics.valueEvent("platform", "performance", "startupTimeMs", 250);
57
78
 
58
- // Eg: event with count and value, here it logs that the startup time is 250 milliseconds.
59
- // Note that the value is unitless from analytics perspective. unit is deduced from subCategory name
60
- analytics.event("platform", "performance", "startupTimeMs", 1, 250);
79
+ // Track fractional values (e.g., CPU utilization)
80
+ analytics.valueEvent("platform", "CPU", "utilization", .45);
61
81
 
62
- // Eg: event with fractional value.
63
- analytics.event("platform", "CPU", "utilization", 1, .45);
64
- // Eg. Here we register that the system has 8 cores with each core having 2300MHz frequency.
65
- analytics.event("platform", "CPU", "coreCountsAndFrequencyMhz", 8, 2300);
82
+ // Track that a system has 8 cores with each core having 2300MHz frequency
83
+ analytics.valueEvent("platform", "CPU", "coreCountsAndFrequencyMhz", 2300, 8);
66
84
  ```
67
- ### API parameters
85
+
86
+ #### Parameters
68
87
  * `eventType` - A string, required
69
88
  * `eventCategory` - A string, required
70
89
  * `subCategory` - A string, required
71
- * `eventCount` (_Optional_) : A non-negative number indicating the number of times the event (or an event with a
72
- particular value if a value is specified) happened. defaults to 1.
73
- * `eventValue` (_Optional_) : A number value associated with the event. defaults to 0
90
+ * `eventValue` (_Optional_) : A numeric value associated with the event. Defaults to 0.
91
+ * `count` (_Optional_) : A non-negative number indicating how many times this value occurred. Defaults to 1.
92
+
93
+ ### Deprecated: `analytics.event`
94
+ The legacy `analytics.event(eventType, eventCategory, subCategory, eventCount, eventValue)` API is still
95
+ available for backwards compatibility but is deprecated. Please migrate to `countEvent` or `valueEvent`.
74
96
 
75
97
 
76
98
  ## Advanced Usages
@@ -91,9 +113,9 @@ function _initCoreAnalytics() {
91
113
  script.type = 'text/javascript';
92
114
  script.async = true;
93
115
  script.onload = function(){
94
- // replace `your_analytics_account_ID` and `appName` below with your values
116
+ // replace `your_analytics_account_ID` and `appName` below with your values
95
117
  window.initAnalyticsSession('your_analytics_account_ID', 'appName'); // if you have a custom analytics server
96
- window.analytics.event("core-analytics", "client-lib", "loadTime", 1,
118
+ window.analytics.valueEvent("core-analytics", "client-lib", "loadTime",
97
119
  (new Date().getTime())- window.analytics.loadStartTime);
98
120
  };
99
121
  script.src = 'https://unpkg.com/@aicore/core-analytics-client-lib/dist/analytics.min.js';
@@ -124,7 +146,7 @@ which means that any events that happen within 3 seconds cannot be distinguished
124
146
  // Init with default values and server controlled config. use the following `analyticsLibLoaded` function
125
147
  function analyticsLibLoaded() {
126
148
  initAnalyticsSession('your_analytics_account_ID', 'appName');
127
- analytics.event("core-analytics", "client-lib", "loadTime", 1, (new Date().getTime())-analytics.loadStartTime);
149
+ analytics.valueEvent("core-analytics", "client-lib", "loadTime", (new Date().getTime())-analytics.loadStartTime);
128
150
  }
129
151
 
130
152
  //Replace initAnalyticsSession in analyticsLibLoaded function for the below use cases.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aicore/core-analytics-client-lib",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "Analytics client library for https://github.com/aicore/Core-Analytics-Server",
5
5
  "main": "dist/analytics.min.js",
6
6
  "type": "module",