ng-optimizely icon indicating copy to clipboard operation
ng-optimizely copied to clipboard

Optimizely-updated-snippet-script-request

Open abilashgundala11 opened this issue 7 years ago • 1 comments

I came across a new change in optimizely, where the script should be changed from https://cdn.optimizely.com/js/key.js to https://cdn-pci.optimizely.com/js/key.js (the difference here is cdn-pci).

We should only have the PCI one that is what I was informed by our testing folks who helping us in having optimizely on our web site. Would request you to remove/update the non-PCI compliant snippet and add PCI snippet. script.src = 'https://cdn-pci.optimizely.com/js/' + key + '.js';

angular.module('ng-optimizely', ['ng']) .provider('optimizely', function() { var key; var activationEventName = '$viewContentLoaded'; this.setKey = function(val) { key = val; }; this.setActivationEventName = function(val) { activationEventName = val; }; this.$get = ['$rootScope', '$window', '$timeout', '$q' , function($rootScope, $window, $timeout, $q) { var service = $window.optimizely = $window.optimizely || [];

service.loadProject = function() {
  var deferred = $q.defer();

  if (document.getElementById('optimizely-js')) {
    deferred.reject(new Error({message: 'Optimizely already activated'}));

  } else if (key == void 0) {
    deferred.reject(new Error({message: 'Key not provided'}));

  } else {
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.id = 'optimizely-js';
    script.async = true;
    script.src = 'https://cdn-pci.optimizely.com/js/' + key + '.js';
    script.onload = script.onreadystatechange = function () {
      deferred.resolve($window.optimizely);
    };
    script.onerror = script.onreadystatechange = function (error) {
      deferred.reject(error);
    };

    var first = document.getElementsByTagName('script')[0];
    first.parentNode.insertBefore(script, first);

    deferred.promise.then(function() {
      if (!activationEventName) {
        $window.optimizely.push(['activate']);
      } else {
        $rootScope.$on(activationEventName, function() {
          $timeout(function() {
            $window.optimizely.push(['activate']);
          });
        });
      }
    });
  }

  return deferred.promise;
};

return service;

}]});

abilashgundala11 avatar Jan 23 '18 04:01 abilashgundala11

i would really appreciate a PR if you could make one. otherwise it's gonna take me a little bit to get to this.

jacopotarantino avatar Feb 26 '18 17:02 jacopotarantino