(function(FS) {
  var session = FS.getCurrentSession(), sessionUrl = FS.getCurrentSessionURL();
  function retryWithBackoff(condition, callback, maxWait, failureMsg, timeoutCallback) {
    var totalTimeExpired = 0;
    var wait = 64;
    var resultFn = function() {
      if (condition()) {
        callback();
        return;
      }
      wait = Math.min(wait * 2, 1024);
      if (totalTimeExpired > maxWait) {
        FS.log('warn', failureMsg);
        !!timeoutCallback && timeoutCallback(failureMsg);
        return;
      }
      totalTimeExpired += wait
      setTimeout(resultFn, wait);
    };
    return resultFn;
  }
  function loadSession(key) {
	var lastSession = window['localStorage'].getItem(key);
    if (!lastSession) {
      lastSession = FS._cookies()[key];
    }
    return lastSession
  }
  function saveSession(key, session) {
    window['localStorage'].setItem(key, session);
  }

	window['_dlo_appender'] = 'fullstory';
	window['_dlo_telemetryExporter'] = (function(FS) {
		const eventNameMap = {
			dlo_init_span: 'INIT_DURATION',
			dlo_rule_registration_span: 'RULE_REGISTRATION_DURATION',
			dlo_handle_event_span: 'HANDLE_EVENT_DURATION',
			dlo_client_error: 'CLIENT_ERROR_COUNT',
		};

		function sendEvent(evt, value) {
			const metricName = eventNameMap[evt.name];
			if (!metricName) {
				return;
			}
			const eventStatus = evt.name === 'dlo_client_error' ? 'FAILURE' : 'SUCCESS';
			const metadata = evt.attributes || {};
			metadata.name = metricName;
			metadata.value = value;
			FS('stat', {
				eventType: 'INTEGRATION_METRIC',
				payload: {
					provider_id: 'dlo',
					org_id: window['_fs_org'],
					event_status: eventStatus,
					metadata: metadata,
				},
			});
		}

		return {
			sendSpan: function(spanEvent) {
				sendEvent(spanEvent, spanEvent.duration.toString());
			},
			sendCount: function(countEvent) {
				sendEvent(countEvent, countEvent.value.toString());
			},
		};
	}(FS));
	window['_dlo_logLevel'] = -1;
	window['_dlo_beforeDestination'] = Array.isArray(window['_dlo_beforeDestination']) ? window['_dlo_beforeDestination'] : [{ name: 'convert', enumerate: true, preserveArray: true, index: -1 },{ name: 'suffix' },{ name: 'insert', value: 'dlo', position: -1 }];
	window['_dlo_previewMode'] =  false;
	window['_dlo_readOnLoad'] = true;
	window['_dlo_validateRules'] = false;
	window['_dlo_enable_restart'] = false;
	window['_dlo_rules_google_ec'] = [
    {
      "id": "fs-ga-pageview", "source": "dataLayer",
      "operators": [
        { "name": "query", "select": "$[?(pageType, pageName)]" },
        { "name": "insert", "value": "pageview" }
      ],
      "destination": "FS.event"
    },
    {
      "id": "fs-ga-e-commerce-detail-action",
      "source": "dataLayer",
      "operators": [
        { "name": "query", "select": "$.ecommerce.detail.actionField" },
        { "name": "insert", "value": "detail" }
      ],
      "destination": "FS.event"
    },
    {
      "id": "fs-ga-e-commerce-detail-product",
      "source": "dataLayer",
      "operators": [
        { "name": "query", "select": "$.ecommerce.detail.products[0]" },
        { "name": "insert", "value": "detail_product" }
      ],
      "destination": "FS.event"
    },
    {
      "id": "fs-ga-e-commerce-click-action",
      "source": "dataLayer",
      "operators": [
        { "name": "query", "select": "$.ecommerce.click.actionField" },
        { "name": "insert", "value": "click" }
      ],
      "destination": "FS.event"
    },
    {
      "id": "fs-ga-e-commerce-click-product",
      "source": "dataLayer",
      "operators": [
        { "name": "query", "select": "$.ecommerce.click.products[0]" },
        { "name": "insert", "value": "click_product" }
      ],
      "destination": "FS.event"
    },
    {
      "id": "fs-ga-e-commerce-add-action",
      "source": "dataLayer",
      "operators": [
        { "name": "query", "select": "$.ecommerce.add.actionField" },
        { "name": "insert", "value": "add" }
      ],
      "destination": "FS.event"
    },
    {
      "id": "fs-ga-e-commerce-add-product",
      "source": "dataLayer",
      "operators": [
        { "name": "query", "select": "$.ecommerce.add.products[0]" },
        { "name": "insert", "value": "add_product" }
      ],
      "destination": "FS.event"
    },
    {
      "id": "fs-ga-e-commerce-remove-action",
      "source": "dataLayer",
      "operators": [
        { "name": "query", "select": "$.ecommerce.remove.actionField" },
        { "name": "insert", "value": "remove" }
      ],
      "destination": "FS.event"
    },
    {
      "id": "fs-ga-e-commerce-remove-product",
      "source": "dataLayer",
      "operators": [
        { "name": "query", "select": "$.ecommerce.remove.products[0]" },
        { "name": "insert", "value": "remove_product" }
      ],
      "destination": "FS.event"
    },
    {
      "id": "fs-ga-e-commerce-promo_click-action",
      "source": "dataLayer",
      "operators": [
        { "name": "query", "select": "$.ecommerce.promoClick.actionField" },
        { "name": "insert", "value": "promo_click" }
      ],
      "destination": "FS.event"
    },
    {
      "id": "fs-ga-e-commerce-promo_click-promotion",
      "source": "dataLayer",
      "operators": [
        { "name": "query", "select": "$.ecommerce.promoClick.promotions[0]" },
        { "name": "insert", "value": "promo_click_promotion" }
      ],
      "destination": "FS.event"
    },
    {
      "id": "fs-ga-e-commerce-checkout-action",
      "source": "dataLayer",
      "operators": [
        { "name": "query", "select": "$.ecommerce.checkout.actionField" },
        { "name": "insert", "value": "checkout" }
      ],
      "destination": "FS.event"
    },
    {
      "id": "fs-ga-e-commerce-checkout-product",
      "source": "dataLayer",
      "operators": [
        { "name": "query", "select": "$.ecommerce.checkout.products" },
        { "name": "fan-out" },
        { "name": "insert", "value": "checkout_product" }
      ],
      "destination": "FS.event"
    },
    {
      "id": "fs-ga-e-commerce-purchase-action",
      "source": "dataLayer",
      "operators": [
        { "name": "query", "select": "$.ecommerce.purchase.actionField" },
        { "name": "insert", "value": "purchase" }
      ],
      "destination": "FS.event"
    },
    {
      "id": "fs-ga-e-commerce-purchase-product",
      "source": "dataLayer",
      "operators": [
        { "name": "query", "select": "$.ecommerce.purchase.products" },
        { "name": "fan-out" },
        { "name": "insert", "value": "purchase_product" }
      ],
      "destination": "FS.event"
    },
    {
      "id": "fs-ga-e-commerce-refund-action",
      "source": "dataLayer",
      "operators": [
        { "name": "query", "select": "$.ecommerce.refund.actionField" },
        { "name": "insert", "value": "refund" }
      ],
      "destination": "FS.event"
    },
    {
      "id": "fs-ga-e-commerce-refund-product",
      "source": "dataLayer",
      "operators": [
        { "name": "query", "select": "$.ecommerce.refund.products" },
        { "name": "fan-out" },
        { "name": "insert", "value": "refund_product" }
      ],
      "destination": "FS.event"
    }
	]
  ;window['_dlo_rules_google_ec_ga4'] = [
    {
      "id": "fs-ga4-e-commerce-select_item",
      "source": "dataLayer",
      "operators": [
        { "name": "query", "select": "$[?(event=select_item)]" },
        { "name": "query", "select": "$.ecommerce.items[0]" },
        { "name": "convert", "enumerate": true },
        { "name": "insert", "value": "select_item" }
      ],
      "destination": "FS.event"
    },
    {
      "id": "fs-ga4-e-commerce-view_item",
      "source": "dataLayer",
      "operators": [
        { "name": "query", "select": "$[?(event=view_item)]" },
        { "name": "query", "select": "$.ecommerce.items[0]" },
        { "name": "convert", "enumerate": true },
        { "name": "insert", "value": "view_item" }
      ],
      "destination": "FS.event"
    },
    {
      "id": "fs-ga4-e-commerce-add_to_cart",
      "source": "dataLayer",
      "operators": [
        { "name": "query", "select": "$[?(event=add_to_cart)]" },
        { "name": "query", "select": "$.ecommerce.items[0]" },
        { "name": "convert", "enumerate": true },
        { "name": "insert", "value": "add_to_cart" }
      ],
      "destination": "FS.event"
    },
    {
      "id": "fs-ga4-e-commerce-remove_from_cart",
      "source": "dataLayer",
      "operators": [
        { "name": "query", "select": "$[?(event=remove_from_cart)]" },
        { "name": "query", "select": "$.ecommerce.items[0]" },
        { "name": "convert", "enumerate": true },
        { "name": "insert", "value": "remove_from_cart" }
      ],
      "destination": "FS.event"
    },
    {
      "id": "fs-ga4-e-commerce-view_promotion",
      "source": "dataLayer",
      "operators": [
        { "name": "query", "select": "$[?(event=view_promotion)]" },
        { "name": "query", "select": "$.ecommerce.items[0]" },
        { "name": "convert", "enumerate": true },
        { "name": "insert", "value": "view_promotion" }
      ],
      "destination": "FS.event"
    },
    {
      "id": "fs-ga4-e-commerce-select_promotion",
      "source": "dataLayer",
      "operators": [
        { "name": "query", "select": "$[?(event=select_promotion)]" },
        { "name": "query", "select": "$.ecommerce.items[0]" },
        { "name": "convert", "enumerate": true },
        { "name": "insert", "value": "select_promotion" }
      ],
      "destination": "FS.event"
    },
    {
      "id": "fs-ga4-e-commerce-purchase",
      "source": "dataLayer",
      "operators": [
        { "name": "query", "select": "$[?(event=purchase)]" },
        { "name": "query", "select": "$.ecommerce" },
        { "name": "rename", "properties": { "items": "products" } },
        { "name": "convert", "enumerate": true },
        { "name": "insert", "value": "Order Completed" }
      ],
      "destination": "FS.event"
    },
    {
      "id": "fs-gtg4-e-commerce-select_item",
      "source": "dataLayer",
      "operators": [
        { "name": "query", "select": "$[(0,1,2)]" },
        { "name": "query", "select": "$[?(1=select_item)]" },
        { "name": "query", "select": "$[2].items[0]" },
        { "name": "convert", "enumerate": true },
        { "name": "insert", "value": "select_item" }
      ],
      "destination": "FS.event"
    },
    {
      "id": "fs-gtg4-e-commerce-view_item",
      "source": "dataLayer",
      "operators": [
        { "name": "query", "select": "$[(0,1,2)]" },
        { "name": "query", "select": "$[?(1=view_item)]" },
        { "name": "query", "select": "$[2].items[0]" },
        { "name": "convert", "enumerate": true },
        { "name": "insert", "value": "view_item" }
      ],
      "destination": "FS.event"
    },
    {
      "id": "fs-gtg4-e-commerce-add_to_cart",
      "source": "dataLayer",
      "operators": [
        { "name": "query", "select": "$[(0,1,2)]" },
        { "name": "query", "select": "$[?(1=add_to_cart)]" },
        { "name": "query", "select": "$[2].items[0]" },
        { "name": "convert", "enumerate": true },
        { "name": "insert", "value": "add_to_cart" }
      ],
      "destination": "FS.event"
    },
    {
      "id": "fs-gtg4-e-commerce-remove_from_cart",
      "source": "dataLayer",
      "operators": [
        { "name": "query", "select": "$[(0,1,2)]" },
        { "name": "query", "select": "$[?(1=remove_from_cart)]" },
        { "name": "query", "select": "$[2].items[0]" },
        { "name": "convert", "enumerate": true },
        { "name": "insert", "value": "remove_from_cart" }
      ],
      "destination": "FS.event"
    },
    {
      "id": "fs-gtg4-e-commerce-view_promotion",
      "source": "dataLayer",
      "operators": [
        { "name": "query", "select": "$[(0,1,2)]" },
        { "name": "query", "select": "$[?(1=view_promotion)]" },
        { "name": "query", "select": "$[2].items[0]" },
        { "name": "convert", "enumerate": true },
        { "name": "insert", "value": "view_promotion" }
      ],
      "destination": "FS.event"
    },
    {
      "id": "fs-gtg4-e-commerce-select_promotion",
      "source": "dataLayer",
      "operators": [
        { "name": "query", "select": "$[(0,1,2)]" },
        { "name": "query", "select": "$[?(1=select_promotion)]" },
        { "name": "query", "select": "$[2].items[0]" },
        { "name": "convert", "enumerate": true },
        { "name": "insert", "value": "select_promotion" }
      ],
      "destination": "FS.event"
    },
    {
      "id": "fs-gtg4-e-commerce-purchase",
      "source": "dataLayer",
      "operators": [
        { "name": "query", "select": "$[(0,1,2)]" },
        { "name": "query", "select": "$[?(1=purchase)]" },
        { "name": "query", "select": "$[2]" },
        { "name": "rename", "properties": { "items": "products" } },
        { "name": "convert", "enumerate": true },
        { "name": "insert", "value": "Order Completed" }
      ],
      "destination": "FS.event"
    }
	]
  ;window['_dlo_rules_google_em'] = [
    {
      "id": "fs-ga-event",
      "source": "dataLayer",
      "operators": [
        { "name": "query", "select": "$[?(event!^gtm)]" },
        { "name": "query", "select": "$[?(event!=optimize.domChange)]" },
        { "name": "query", "select": "$[!(ecommerce,gtm.uniqueEventId)]" },
        { "name": "insert", "select": "event" }
      ],
      "destination": "FS.event"
    }
	]
  ;window['_dlo_rules_google_em_ga4'] = [
    {
      "id": "fs-gtg-event",
      "source": "dataLayer",
      "operators": [
        { "name": "query", "select": "$[(0,1,2)]" },
        { "name": "query", "select": "$[?(0=event)]" },
        { "name": "flatten" },
        { "name": "rename", "properties": { "0": "gtgCommand", "1": "gtgAction" } },
        { "name": "query", "select": "$[?(gtgAction!^gtm)]" },
        { "name": "query", "select": "$[?(gtgAction!=optimize.domChange)]" },
        { "name": "query", "select": "$[?(items=undefined)]" },
        { "name": "insert", "select": "gtgAction" }
      ],
      "destination": "FS.event"
    }
	]
  ;
	var dloScriptTag = document.createElement('script');
	dloScriptTag.type = 'text/javascript';
	dloScriptTag.async = true;
	var recSettingsHost = window['_fs_rec_settings_host'];
	var host = typeof recSettingsHost === 'string' ? recSettingsHost : 'edge.fullstory.com';
	dloScriptTag.src = 'https://' + host + '/datalayer/v4/latest.js';
	var firstScriptTag = document.getElementsByTagName('script')[0];
	firstScriptTag.parentNode.insertBefore(dloScriptTag,firstScriptTag);
	
})(window['_fs_namespace'] ? window[window['_fs_namespace']] : window['FS'])