Skip to content

Commit a1e4589

Browse files
committed
docs: update readme
1 parent 86faa3d commit a1e4589

File tree

1 file changed

+44
-22
lines changed

1 file changed

+44
-22
lines changed

README.md

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ in the `initAnalyticsSession` call below:
3333
};}
3434
function analyticsLibLoaded() {
3535
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);
3737
}
3838
</script>
3939
```
@@ -43,34 +43,56 @@ NB: The script is loaded async, so it will not block other js scripts. `analytic
4343
after the above code and need not wait for the script load to complete.
4444

4545
## 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.
4851

4952
```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.
5171

52-
// Eg: event without counts and values
53-
analytics.event("platform", "os", "linux");
72+
```javascript
73+
// valueEvent(eventType, eventCategory, subCategory, eventValue, count)
5474

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);
5778

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);
6181

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);
6684
```
67-
### API parameters
85+
86+
#### Parameters
6887
* `eventType` - A string, required
6988
* `eventCategory` - A string, required
7089
* `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`.
7496

7597

7698
## Advanced Usages
@@ -91,9 +113,9 @@ function _initCoreAnalytics() {
91113
script.type = 'text/javascript';
92114
script.async = true;
93115
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
95117
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",
97119
(new Date().getTime())- window.analytics.loadStartTime);
98120
};
99121
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
124146
// Init with default values and server controlled config. use the following `analyticsLibLoaded` function
125147
function analyticsLibLoaded() {
126148
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);
128150
}
129151

130152
//Replace initAnalyticsSession in analyticsLibLoaded function for the below use cases.

0 commit comments

Comments
 (0)