Skip to content

Commit 0b29331

Browse files
mzogheibJulio Farah
andauthored
Add load options (#66)
* Support load options * Add load options type Co-authored-by: Julio Farah <[email protected]>
1 parent 7013654 commit 0b29331

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

lib/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,11 @@ function renderPage(page) {
8787
function renderLoad(settings) {
8888
if (!settings.load) return '';
8989

90+
if (typeof settings.load !== 'boolean') {
91+
// eslint-disable-next-line no-restricted-globals
92+
var loadOptions = JSON.stringify(settings.load);
93+
return 'analytics.load("' + settings.apiKey + '", ' + loadOptions + ');';
94+
}
95+
9096
return 'analytics.load("' + settings.apiKey + '");';
9197
}

test/render.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ describe('snippet', function() {
3434
'analytics.load("key")');
3535
});
3636

37+
it('should set the load options', function() {
38+
assertContains(
39+
snippet.max({ apiKey: 'key', load: { integrations: { All: false } } }),
40+
'analytics.load("key", {"integrations":{"All":false}})');
41+
});
42+
3743
it('should set the _writekey', function() {
3844
assertContains(
3945
snippet.max({ apiKey: 'foo' }),
@@ -101,6 +107,12 @@ describe('snippet', function() {
101107
'analytics.load("key")');
102108
});
103109

110+
it('should set the load options', function() {
111+
assertContains(
112+
snippet.max({ apiKey: 'key', load: { integrations: { All: false } } }),
113+
'analytics.load("key", {"integrations":{"All":false}})');
114+
});
115+
104116
it('should set the _writekey', function() {
105117
assertContains(
106118
snippet.min({ apiKey: 'foo' }),

types.d.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ declare module '@segment/snippet' {
77
}
88
}
99

10+
interface LoadOptions {
11+
integrations?: {
12+
All?: boolean
13+
[key: string]: boolean
14+
}
15+
}
16+
1017
interface Options {
1118
/** The domain name where the analytics.js script is hosted. */
1219
host?: string
@@ -23,7 +30,7 @@ declare module '@segment/snippet' {
2330
* you want dynamically control the load process on the client-side for
2431
* things like GDPR.
2532
*/
26-
load?: boolean
33+
load?: boolean | LoadOptions
2734
}
2835

2936
/**

0 commit comments

Comments
 (0)