import Bugsnag from '@bugsnag/js';

const gtmEvents = require.context('./gtmEvents', true, /\.js$/, 'lazy');

export const gtmPush = (eventType, eventObject) => {
  try {
    gtmEvents(`./${eventType}.js`)
      .then((event) => {
        event.default(eventObject);
      })
      .catch((err) => {
        if (err) {
          Bugsnag.notify(err);
        }
      });
  } catch (e) {
    if (e) {
      Bugsnag.notify(e);
    }
  }
};
