posthog-js 1.32.1 → 1.32.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/es.js CHANGED
@@ -881,7 +881,7 @@ var LZString = {
881
881
  }
882
882
  };
883
883
 
884
- var version = "1.32.1";
884
+ var version = "1.32.2";
885
885
 
886
886
  // e.g. Config.DEBUG = Config.DEBUG || instance.get_config('debug')
887
887
 
@@ -4056,33 +4056,39 @@ var Decide = /*#__PURE__*/function () {
4056
4056
  this.instance['compression'] = {};
4057
4057
  }
4058
4058
 
4059
- if (response['inject'] && this.instance.get_config('opt_in_web_app_injection')) {
4060
- var _iterator2 = _createForOfIteratorHelper(response['inject']),
4061
- _step2;
4059
+ if (response['inject']) {
4060
+ if (this.instance.get_config('opt_in_web_app_injection')) {
4061
+ var apiHost = this.instance.get_config('api_host');
4062
4062
 
4063
- try {
4064
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
4065
- var _step2$value = _step2.value,
4066
- id = _step2$value.id,
4067
- source = _step2$value.source,
4068
- config = _step2$value.config;
4069
-
4070
- try {
4071
- var _window$eval, _window$eval2, _window$eval2$inject;
4072
-
4073
- var apiHost = this.instance.get_config('api_host');
4074
- (_window$eval = window.eval(source)) === null || _window$eval === void 0 ? void 0 : (_window$eval2 = _window$eval(apiHost)) === null || _window$eval2 === void 0 ? void 0 : (_window$eval2$inject = _window$eval2.inject) === null || _window$eval2$inject === void 0 ? void 0 : _window$eval2$inject.call(_window$eval2, {
4075
- config: config,
4076
- posthog: this.instance
4077
- });
4078
- } catch (e) {
4079
- console.error("[POSTHOG-JS] Error while initializing PostHog app with config id ".concat(id), e);
4063
+ var _iterator2 = _createForOfIteratorHelper(response['inject']),
4064
+ _step2;
4065
+
4066
+ try {
4067
+ var _loop = function _loop() {
4068
+ var _step2$value = _step2.value,
4069
+ id = _step2$value.id,
4070
+ url = _step2$value.url;
4071
+ var script = document.createElement('script');
4072
+ script.src = [apiHost, apiHost[apiHost.length - 1] === '/' && url[0] === '/' ? url.substring(1) : url].join('');
4073
+
4074
+ script.onerror = function (e) {
4075
+ console.error("Error while initializing PostHog app with config id ".concat(id), e);
4076
+ };
4077
+
4078
+ window["__$$ph_web_js_".concat(id)] = _this2.instance;
4079
+ document.body.appendChild(script);
4080
+ };
4081
+
4082
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
4083
+ _loop();
4080
4084
  }
4085
+ } catch (err) {
4086
+ _iterator2.e(err);
4087
+ } finally {
4088
+ _iterator2.f();
4081
4089
  }
4082
- } catch (err) {
4083
- _iterator2.e(err);
4084
- } finally {
4085
- _iterator2.f();
4090
+ } else if (response['inject'].length > 0) {
4091
+ console.error('PostHog app injection was requested, but is disabled. Enable the "opt_in_web_app_injection" config to proceed.');
4086
4092
  }
4087
4093
  }
4088
4094
  }