Skip to content

Conversation

@dk1027
Copy link
Contributor

@dk1027 dk1027 commented Aug 10, 2020

Description

This PR adds an option ajsPath to override the default analytics.min.js location

Testing

Using default

snippet.max({})

The relevant bit of generated snippet:

  analytics.load = function(key, options){
    // Create an async script element based on your key.
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.async = true;
    script.src = 'https://cdn.segment.com/analytics.js/v1/' + key + '/analytics.min.js';

    // Insert our script next to the first script element.
    var first = document.getElementsByTagName('script')[0];
    first.parentNode.insertBefore(script, first);
    analytics._loadOptions = options;
  };

Setting ajsPath

snippet.max({ajsPath: '/foo/bar.min.js'})
  analytics.load = function(key, options){
    // Create an async script element based on your key.
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.async = true;
    script.src = 'https://cdn.segment.com/foo/bar.min.js';

    // Insert our script next to the first script element.
    var first = document.getElementsByTagName('script')[0];
    first.parentNode.insertBefore(script, first);
    analytics._loadOptions = options;
  };

@dk1027 dk1027 requested a review from pooyaj August 10, 2020 21:25
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

@dk1027 dk1027 requested a review from pooyaj August 10, 2020 23:32
@dk1027 dk1027 merged commit 7e244d5 into master Aug 10, 2020
@dk1027 dk1027 deleted the add-ajs-path branch August 10, 2020 23:40
JackCuthbert added a commit to JackCuthbert/snippet that referenced this pull request Oct 26, 2020
JackCuthbert added a commit to JackCuthbert/snippet that referenced this pull request Oct 26, 2020
JackCuthbert added a commit to JackCuthbert/snippet that referenced this pull request Oct 26, 2020
juliofarah pushed a commit that referenced this pull request Jun 30, 2021
* add TypeScript definitions

* document ajsPath option

From the PR #50 merged in 7119bcc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants