Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dk1027 is key a known variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pooyaj key is a variable in the scope of where settings.ajsPath is renderered: https://github.com/segmentio/snippet/pull/50/files#diff-7ca0ae40f9ef9562ed8a5fcdce4f82d2R71

if (!has.call(options, 'page')) options.page = true;
if (!has.call(options, 'load')) options.load = true;
return options;
Expand Down
3 changes: 1 addition & 2 deletions template/snippet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
9 changes: 9 additions & 0 deletions test/render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' }),
Expand Down