Skip to content

Commit 0c5c5b2

Browse files
authored
Add TypeScript definitions (#55)
* add TypeScript definitions * document ajsPath option From the PR #50 merged in 7119bcc
1 parent f8142ff commit 0c5c5b2

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

Readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ var contents = snippet.max({
3838
* `apiKey`: the `apiKey` to load in the snippet.
3939
* `page`: the options to pass to `analytics.page`. if `page` is `false`, then the `page()` call will be omitted.
4040
* `load`: if set to `false` the `load()` call will be omitted. This is useful for if you want dynamically control the load process on the client-side for things like GDPR.
41+
* `ajsPath`: override the default analytics.min.js location
4142

4243

4344
### snippet.min(options)

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"description": "Templating methods for rendering the analytics.js snippet.",
77
"main": "lib/index.js",
88
"license": "MIT",
9+
"typings": "./types.d.ts",
910
"dependencies": {
1011
"@ndhoule/map": "^2.0.1"
1112
},

types.d.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
declare module '@segment/snippet' {
2+
interface PageOptions {
3+
category?: string
4+
name?: string
5+
properties?: {
6+
[key: string]: string | number
7+
}
8+
}
9+
10+
interface Options {
11+
/** The domain name where the analytics.js script is hosted. */
12+
host?: string
13+
/** The apiKey to load in the snippet. */
14+
apiKey?: string
15+
ajsPath?: string
16+
/**
17+
* The options to pass to `analytics.page`. if page is false, then the
18+
* `page()` call will be omitted.
19+
*/
20+
page?: boolean | PageOptions
21+
/**
22+
* If set to false the `load()` call will be omitted. This is useful for if
23+
* you want dynamically control the load process on the client-side for
24+
* things like GDPR.
25+
*/
26+
load?: boolean
27+
}
28+
29+
/**
30+
* Returns the maxified version of the analytics.js snippet given a set of
31+
* options.
32+
*/
33+
export function max(options?: Options): string
34+
35+
/**
36+
* Returns the minified version of the snippet.
37+
*/
38+
export function min(options?: Options): string
39+
}
40+

0 commit comments

Comments
 (0)