Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimizely-updated-snippet-script-request #19

Open
abilashgundala11 opened this issue Jan 23, 2018 · 1 comment
Open

Optimizely-updated-snippet-script-request #19

abilashgundala11 opened this issue Jan 23, 2018 · 1 comment

Comments

@abilashgundala11
Copy link

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;

}]});

@jacopotarantino
Copy link
Owner

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

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

No branches or pull requests

2 participants