From 7119bcc210c17960862b7fefeaea4bfab8bb5ae1 Mon Sep 17 00:00:00 2001 From: King Long Tse Date: Mon, 10 Aug 2020 14:13:12 -0700 Subject: [PATCH] added ajsPath option --- lib/index.js | 1 + template/snippet.js | 3 +-- test/render.test.js | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index c21ff70..5172806 100644 --- a/lib/index.js +++ b/lib/index.js @@ -53,6 +53,7 @@ function defaults(options) { options || (options = {}); options.apiKey || (options.apiKey = 'YOUR_API_KEY'); options.host || (options.host = 'cdn.segment.com'); + options.ajsPath || (options.ajsPath = '/analytics.js/v1/\' + key + \'/analytics.min.js'); if (!has.call(options, 'page')) options.page = true; if (!has.call(options, 'load')) options.load = true; return options; diff --git a/template/snippet.js b/template/snippet.js index 8b3d3c9..9b97ded 100644 --- a/template/snippet.js +++ b/template/snippet.js @@ -68,8 +68,7 @@ var script = document.createElement('script'); script.type = 'text/javascript'; script.async = true; - script.src = 'https://<%= settings.host %>/analytics.js/v1/' - + key + '/analytics.min.js'; + script.src = 'https://<%= settings.host %><%= settings.ajsPath %>'; // Insert our script next to the first script element. var first = document.getElementsByTagName('script')[0]; diff --git a/test/render.test.js b/test/render.test.js index b627c34..ea1b8eb 100644 --- a/test/render.test.js +++ b/test/render.test.js @@ -19,6 +19,15 @@ describe('snippet', function() { 'example.com/analytics.js/v1'); }); + it('should set the ajs path', function() { + assertContains( + snippet.max({ + host: 'example.com', + ajsPath: '/something/else.min.js' + }), + 'example.com/something/else.min.js'); + }); + it('should set the api key', function() { assertContains( snippet.max({ apiKey: 'key' }),