Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 0 additions & 60 deletions src/lib/ddl/event-handlers.js

This file was deleted.

42 changes: 0 additions & 42 deletions src/lib/ddl/shopping-ddl.js

This file was deleted.

85 changes: 7 additions & 78 deletions src/lib/shopping-analytics.js
Original file line number Diff line number Diff line change
@@ -1,84 +1,13 @@
/* @flow */
// $FlowFixMe
import 'whatwg-fetch'; // eslint-disable-line import/no-unassigned-import

import type { Config } from '../types/config';
import type { ContainerSummary } from '../types';
import type { VisitorInfo } from '../types/user';

import { setupTrackers } from './shopping-trackers';
import { setupUserDetails } from './user-configuration';
import { setupContainer } from './get-property-id';
// $FlowFixMe
import { capturePageData } from './tag-parsers/capture-page-data';
import { debugLogger } from './debug-console-logger';

// $FlowFixMe
export const shoppingAnalyticsSetup = (config : Config = {}) => {
const shoppingTracker = setupTrackers(config);
let identityFetchCompleted : boolean = false;
let containerFetchCompleted : boolean = false;
let eventQueue = [];
let inMemoryIdentity: VisitorInfo = null;
const queue_limit = 100;

function isReadyToPublish() : boolean {
return identityFetchCompleted && containerFetchCompleted;
}

function flushEventQueueIfReady () {
if (isReadyToPublish()) {
for (const params of eventQueue) {
shoppingTracker.send(...params, inMemoryIdentity);
}
eventQueue = [];
}
}

function onUserIdentityFetch(identity: VisitorInfo) {
inMemoryIdentity = identity;
debugLogger.log('[shopping-analytics:onUserIdentityFetch] Received identity fetch notification.');
identityFetchCompleted = true;
flushEventQueueIfReady();
}

// $FlowFixMe
function onContainerFetch(containerSummary : ContainerSummary) : void {
debugLogger.log('[shopping-analytics:onUserIdentityFetch] Received container fetch notification. Container summary: ', containerSummary);
config.propertyId = config.propertyId || (containerSummary && containerSummary.id);
config.containerSummary = containerSummary;
containerFetchCompleted = true;
flushEventQueueIfReady();
}

function enqueueEvent(...args) {
debugLogger.log('[shopping-analytics:enqueueEvent] Event is enqueued (wating on initialization). Event(s):', args);
eventQueue.push(args);
if (eventQueue.length > queue_limit) {
eventQueue.shift();
}
}

// $FlowFixMe
function sendOrEnqueue(...args) {
if (!isReadyToPublish()) {
enqueueEvent(...args);
} else {
shoppingTracker.send(...args);
}
}

debugLogger.log('[shopping-analytics:shoppingAnalyticsSetup] Initialized shopping analytics with the following configuration', config);

setupUserDetails(config, onUserIdentityFetch);
setupContainer(config, onContainerFetch);
const noop = () => {};

export const shoppingAnalyticsSetup = () => {
// return publicly accessible
return {
send: sendOrEnqueue,
set: shoppingTracker.set,
getPageSkuData: capturePageData,
enableDebugLogging: () => { debugLogger.setDebugEnabled(true); },
disableDebugLogging: () => { debugLogger.setDebugEnabled(false); }
send: noop,
set: noop,
getPageSkuData: noop,
enableDebugLogging: noop,
disableDebugLogging: noop
};
};
21 changes: 0 additions & 21 deletions src/lib/shopping-attributes.js

This file was deleted.

159 changes: 0 additions & 159 deletions src/lib/shopping-fpti/event-handlers.js

This file was deleted.

Loading
Loading