/* eslint-disable no-undef */
import { takeEvery } from 'redux-saga';
import { select, take } from 'redux-saga/effects'
import * as deps from '../deps';

export function launchGTMEventsSaga({ type }) {
  window.dataLayer.push({
    event: type,
  });
}

export default function* gtmSagas() {
  yield take(deps.types.SITE_ID_CHANGED);
  const isPreview = yield select(deps.selectors.getPreview);

  if (!isPreview) {
    window.dataLayer = window.dataLayer || [];
    yield takeEvery('*', launchGTMEventsSaga);
  }
}

/* eslint-disable no-undef */
import { takeEvery } from 'redux-saga';
import { select, take } from 'redux-saga/effects'
import * as deps from '../deps';

export function launchGTMEventsSaga({ type, ...props }) {
  window.dataLayer.push({
    event: type,
    props,
  });
}

export default function* gtmSagas() {
  yield take(deps.types.SITE_ID_CHANGED);
  const isPreview = yield select(deps.selectors.getPreview);

  if (!isPreview) {
    window.dataLayer = window.dataLayer || [];
    yield takeEvery('*', launchGTMEventsSaga);
  }
}

Revert "Don't send props to dataLayer."
Revert "Don't send props to dataLayer."

This reverts commit a104558a48e158e77226e1a635bf34fce9262259.