How to use the @shopgate/tracking-core/core/Core.getScannerEvents function in @shopgate/tracking-core

To help you get started, we’ve selected a few @shopgate/tracking-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github shopgate / pwa / libraries / tracking / subscriptions / scanner.spec.js View on Github external
/* eslint-disable extra-rules/no-single-line-objects */
import core from '@shopgate/tracking-core/core/Core';
import { mainSubject } from '@shopgate/pwa-common/store/middelwares/streams';
import { ROUTE_DID_ENTER, ROUTE_DID_LEAVE } from '@shopgate/pwa-common/constants/ActionTypes';
import { SCANNER_SCOPE_DEFAULT } from '@shopgate/pwa-core/constants/Scanner';
import { SCANNER_PATH, SUCCESS_HANDLE_SCANNER } from '@shopgate/pwa-common-commerce/scanner/constants';
import { scanActivated$, scanFail$, scanSuccess$ } from '../streams/scanner';
import * as helpers from '../helpers';
import subscription from './scanner';

const { createScannerEventData } = helpers;
const scannerEvents = core.getScannerEvents();

describe('Scanner subscriptions', () => {
  const mockedState = {};
  const subscribe = jest.fn();
  const getState = jest.fn().mockReturnValue(mockedState);
  const trackSpy = jest.spyOn(helpers, 'track');

  const format = 'QR_CODE';
  const payload = 'some.payload';

  beforeEach(() => {
    jest.clearAllMocks();
    subscription(subscribe);
  });

  it('should call subscribe as expected', () => {
github shopgate / pwa / libraries / tracking / helpers / index.spec.js View on Github external
import { i18n } from '@shopgate/engage/core';
import {
  createScannerEventData,
  buildScannerUtmUrl,
  createCategoryData,
  createRootCategoryData,
  createPageviewData,
} from './index';

jest.mock('@shopgate/engage/core', () => ({
  i18n: {
    text: jest.fn(),
  },
}));

const scannerEvents = core.getScannerEvents();

describe('Tracking helpers', () => {
  const formatQrCode = 'QR_CODE';
  const defaultEvent = scannerEvents.SCAN_SUCCESS;

  describe('createScannerEventData()', () => {
    it('should create data when there was no user interaction', () => {
      const result = createScannerEventData({
        event: defaultEvent,
        type: formatQrCode,
        userInteraction: false,
      });

      expect(result).toEqual({
        eventAction: defaultEvent,
        userInteraction: false,
github shopgate / pwa / libraries / tracking / subscriptions / scanner.js View on Github external
export default function scanner(subscribe) {
  const events = core.getScannerEvents();

  subscribe(scanActivated$, ({ action, getState }) => {
    const { format } = action;
    track('qrScanner', createScannerEventData({
      event: events.SCAN_ACTIVATED,
      userInteraction: false,
      format,
    }), getState());
  });

  subscribe(scanSuccess$, ({ action, getState }) => {
    const { format, payload } = action;
    track('qrScanner', createScannerEventData({
      event: events.SCAN_SUCCESS,
      format,
      payload,