From cef13485c02f46c8f192e4dae95c6efc1b61d4d2 Mon Sep 17 00:00:00 2001 From: Marwan Zogheib Date: Sat, 12 Jun 2021 11:31:37 +1000 Subject: [PATCH 1/2] Support load options --- lib/index.js | 6 ++++++ test/render.test.js | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/index.js b/lib/index.js index 892da77..31bfe93 100644 --- a/lib/index.js +++ b/lib/index.js @@ -87,5 +87,11 @@ function renderPage(page) { function renderLoad(settings) { if (!settings.load) return ''; + if (typeof settings.load !== 'boolean') { + // eslint-disable-next-line no-restricted-globals + var loadOptions = JSON.stringify(settings.load); + return 'analytics.load("' + settings.apiKey + '", ' + loadOptions + ');'; + } + return 'analytics.load("' + settings.apiKey + '");'; } diff --git a/test/render.test.js b/test/render.test.js index 03f1e2f..bbcae11 100644 --- a/test/render.test.js +++ b/test/render.test.js @@ -34,6 +34,12 @@ describe('snippet', function() { 'analytics.load("key")'); }); + it('should set the load options', function() { + assertContains( + snippet.max({ apiKey: 'key', load: { integrations: { All: false } } }), + 'analytics.load("key", {"integrations":{"All":false}})'); + }); + it('should set the _writekey', function() { assertContains( snippet.max({ apiKey: 'foo' }), @@ -101,6 +107,12 @@ describe('snippet', function() { 'analytics.load("key")'); }); + it('should set the load options', function() { + assertContains( + snippet.max({ apiKey: 'key', load: { integrations: { All: false } } }), + 'analytics.load("key", {"integrations":{"All":false}})'); + }); + it('should set the _writekey', function() { assertContains( snippet.min({ apiKey: 'foo' }), From c07112795c6838ce3b5e641ac6e8af55f5c2cea6 Mon Sep 17 00:00:00 2001 From: Marwan Zogheib Date: Sun, 4 Jul 2021 11:03:42 +1000 Subject: [PATCH 2/2] Add load options type --- types.d.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/types.d.ts b/types.d.ts index f1fba22..eb9e4ec 100644 --- a/types.d.ts +++ b/types.d.ts @@ -7,6 +7,13 @@ declare module '@segment/snippet' { } } + interface LoadOptions { + integrations?: { + All?: boolean + [key: string]: boolean + } + } + interface Options { /** The domain name where the analytics.js script is hosted. */ host?: string @@ -23,7 +30,7 @@ declare module '@segment/snippet' { * you want dynamically control the load process on the client-side for * things like GDPR. */ - load?: boolean + load?: boolean | LoadOptions } /**