Skip to content

Commit 90a2d17

Browse files
committed
feat: add countly types
1 parent cd4772a commit 90a2d17

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed

Diff for: src/countly.d.ts

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
declare module 'countly-sdk-web' {
2+
/**
3+
* From https://support.count.ly/hc/en-us/articles/360037441932-Web-analytics-JavaScript-#minimal-setup
4+
*/
5+
interface CountlyEventData {
6+
key: string
7+
count: number
8+
sum: number
9+
segmentation: Record<string, string | number>
10+
}
11+
interface CountlyEvent {
12+
// name or id of the event
13+
key: string
14+
// how many times did event occur
15+
count?: number
16+
// sum to report with event (if any)
17+
sum?: number
18+
// duration to report with event (if any)
19+
dur?: number
20+
// object with segments key /values
21+
segmentation?: Segments
22+
}
23+
24+
type Segments = Record<string, string>
25+
type IgnoreList = Array<string | RegExp>
26+
type CountlyEventQueueItem = [string, CountlyEventData] | [eventName: string, key: string] | [eventName: string]
27+
interface CountlyWebSdk {
28+
group_features: (arg0: Record<string, string[]>) => unknown
29+
add_consent: (consentFeature: string | string[]) => void
30+
require_consent: boolean
31+
init: (configOptions?: Partial<CountlyWebSdk>) => void
32+
/**
33+
* Report custom event
34+
*
35+
*/
36+
add_event: (event: CountlyEvent) => void
37+
app_key: string
38+
url: string
39+
q?: CountlyEventQueueItem[]
40+
track_domains: boolean
41+
/**
42+
* For the track_* functions below, @see https://github.com/Countly/countly-sdk-web/blob/1c72a3b5d4c1e66031e3ecc5779adfe030ab21e0/lib/countly.js
43+
*/
44+
45+
/**
46+
* Automatically track javascript errors that happen on the website and report them to the server
47+
*
48+
* @param {Segments} segments - additional key value pairs you want to provide with error report, like versions of libraries used, etc.
49+
*/
50+
track_errors: (segments?: Segments) => void
51+
52+
/**
53+
* Track user sessions automatically, including time user spent on your website
54+
*/
55+
track_sessions: () => void
56+
57+
/**
58+
* Track page views user visits
59+
*
60+
* @param {string} page - optional name of the page, by default uses current url path
61+
* @param {IgnoreList} ignoreList - optional array of strings or regexps to test for the url/view name to ignore and not report
62+
* @param {Segments} viewSegments - optional key value object with segments to report with the view
63+
*/
64+
track_pageview: (page?: string, ignoreList?: IgnoreList, viewSegments?: Segments) => void
65+
66+
/**
67+
* Track page views user visits. Alias of {@link track_pageview} method for compatibility with NodeJS SDK
68+
*
69+
* @param {string} page - optional name of the page, by default uses current url path
70+
* @param {IgnoreList} ignoreList - optional array of strings or regexps to test for the url/view name to ignore and not report
71+
* @param {Segments} segments - optional view segments to track with the view
72+
*/
73+
track_view: (page?: string, ignoreList?: IgnoreList, viewSegments?: Segments) => void
74+
75+
/**
76+
* Track all clicks on this page
77+
*
78+
* @param {HTMLElement} parent - DOM object which children to track, by default it is document body
79+
*/
80+
track_clicks: (parent = document.body) => void
81+
82+
/**
83+
* Track all scrolls on this page
84+
*
85+
* @param {HTMLElement} parent - DOM object which children to track, by default it is document body
86+
*/
87+
track_scrolls: (parent = document.body) => void
88+
/**
89+
* Generate custom event for all links that were clicked on this page
90+
*
91+
* @param {HTMLElement} parent - DOM object which children to track, by default it is document body
92+
*/
93+
track_links: (parent = document.body) => void
94+
/**
95+
* Generate custom event for all forms that were submitted on this page
96+
*
97+
* @param {HTMLElement} parent - DOM object which children to track, by default it is document body
98+
* @param {boolean} trackHidden - provide true to also track hidden inputs, default false
99+
* */
100+
track_forms: (parent = document.body, trackHidden = false) => void
101+
}
102+
declare const Countly: CountlyWebSdk
103+
export default Countly
104+
}

0 commit comments

Comments
 (0)