(function() {
  var $newsletterForm = $('.js-newsletter-form'),
      $newsletterInput = $newsletterForm.find('.js-newsletter-input'),
      errorClass = 'is-errored';

  <% if @success %>
    require(['common'], function (MAS) {
      MAS.publish('analytics:trigger', {
        category: 'Newsletter SignUp',
        event: 'Click',
        label: 'Successful'
      });
    });

    $newsletterForm
      .attr({'role':'alert', 'aria-live': 'polite'})
      .removeClass(errorClass)
      .html('<%= flash[:success] %>');

    $newsletterInput.attr({'aria-invalid' : false });
  <% else %>
    require(['common'], function (MAS) {
      MAS.publish('analytics:trigger', {
        category: 'Newsletter SignUp',
        event: 'Click',
        label: 'Not successful'
      });
    });

    var newsletterErrorID = 'newsletter_error',
        $error;

    $('p.js-newsletter-error-msg').remove();
    $error = $('<p />')
                .addClass('newsletter__text js-newsletter-error-msg')
                .text('<%= flash[:error] %>')
                .attr('id', newsletterErrorID);

    $newsletterForm.addClass(errorClass).prepend($error);
    $newsletterInput.attr({'aria-invalid' : true, 'aria-describedby' : newsletterErrorID}).focus();
  <% end %>
})();

(function() {
  var $newsletterForm = $('.js-newsletter-form'),
      $newsletterInput = $newsletterForm.find('.js-newsletter-input'),
      errorClass = 'is-errored';

  <% if @success %>
    require(['common'], function (MAS) {
      MAS.publish('analytics:trigger', {
        gaEventCat: 'Newsletter SignUp',
        gaEventAct: 'Click',
        gaEventLab: 'Successful',
        event: 'gaEvent'
      });
    });

    $newsletterForm
      .attr({'role':'alert', 'aria-live': 'polite'})
      .removeClass(errorClass)
      .html('<%= flash[:success] %>');

    $newsletterInput.attr({'aria-invalid' : false });
  <% else %>
    require(['common'], function (MAS) {
      MAS.publish('analytics:trigger', {
        gaEventCat: 'Newsletter SignUp',
        gaEventAct: 'Click',
        gaEventLab: 'Not successful',
        event: 'gaEvent'
      });
    });

    var newsletterErrorID = 'newsletter_error',
        $error;

    $('p.js-newsletter-error-msg').remove();
    $error = $('<p />')
                .addClass('newsletter__text js-newsletter-error-msg')
                .text('<%= flash[:error] %>')
                .attr('id', newsletterErrorID);

    $newsletterForm.addClass(errorClass).prepend($error);
    $newsletterInput.attr({'aria-invalid' : true, 'aria-describedby' : newsletterErrorID}).focus();
  <% end %>
})();

Fix My Account tracking as per Periscopix guide
Fix My Account tracking as per Periscopix guide
