From 468584379b2d638d3ea091464f3e16247cd8d0fc Mon Sep 17 00:00:00 2001 From: Dipanjan Biswas Date: Wed, 11 Sep 2019 10:29:56 +0530 Subject: [PATCH] final development checkin --- rudder-client-javascript/RudderClient.js | 68 +++++++++++++++----- rudder-client-javascript/RudderClient.min.js | 2 +- 2 files changed, 54 insertions(+), 16 deletions(-) diff --git a/rudder-client-javascript/RudderClient.js b/rudder-client-javascript/RudderClient.js index 77364f6ccb..20480f7cbf 100644 --- a/rudder-client-javascript/RudderClient.js +++ b/rudder-client-javascript/RudderClient.js @@ -1324,6 +1324,47 @@ class CartSharedEvent extends ShareEvent { return this; } } + +//Class representing Product Reviewed event +class ProductReviewedEvent { + constructor(){ + this.product_id = ""; + this.review_id = ""; + this.review_body = ""; + this.rating = ""; + } + + event(){ + return ECommerceEvents.PRODUCT_REVIEWED; + } + + build(){ + var eventProperty = new RudderProperty(); + eventProperty.setPropertyMap(this); + return eventProperty; + } + + //Setter methods in accordance with Builder pattern + setProductId(productId){ + this.product_id = productId; + return this; + } + + setReviewId(reviewId){ + this.review_id = reviewId; + return this; + } + + setReviewBody(reviewBody){ + this.review_body = reviewBody; + return this; + } + + setRating(rating){ + this.rating = rating; + return this; + } +} //Rudder configration class var RudderConfig = (function () { @@ -1953,11 +1994,12 @@ var RudderClient = (function () { -//Test code +//Sample Usage +/* var client = RudderClient.getInstance("dummykey", RudderConfig.getDefaultConfig().setFlushQueueSize(1)); -/* + var props = new RudderProperty(); props.setProperty("title","How to create a tracking plan"); props.setProperty("course", "Intro to Analytics"); @@ -2281,36 +2323,32 @@ client.track(new RudderElementBuilder(). setCoupon("Dummy Product Coupon 23")). build().getPropertyMap()). build()); -*/ client.track(new RudderElementBuilder(). setEvent(ECommerceEvents.CART_SHARED). setProperty(new CartSharedEvent(). setShareVia("Dummy Share Via 2"). setShareMessage("Dummy Message 2"). setRecipient("Dummy Recipient 2"). + setCartId("Dummy Shared Cart Id 1"). addProduct(new ECommerceProductBase(). setProductId("Dummy Product Id 255")). addProduct(new ECommerceProductBase(). setProductId("Dummy Product Id 522")). build().getPropertyMap()). build()); - -/* client.track(new RudderElementBuilder(). - setEvent(ECommerceEvents.ORDER_COMPLETED). - setProperty(new CheckoutStartedEvent(). - setOrder(new ECommerceOrder().setOrderId("Dummy Order 4"). - addProduct(new ECommerceProduct().setName("Dummy Product 4")). - addProduct(new ECommerceProduct().setName("Dummy Product 5"))). + setEvent(ECommerceEvents.PRODUCT_REVIEWED). + setProperty(new ProductReviewedEvent(). + setProductId("Dummy Review Propduct Id 67"). + setReviewId("Dummy Review ID 1"). + setReviewBody("Dummy Review Body 1"). + setRating("Excellent"). build().getPropertyMap()). - build()); - - - - + build()); */ + \ No newline at end of file diff --git a/rudder-client-javascript/RudderClient.min.js b/rudder-client-javascript/RudderClient.min.js index 17b4f6c06e..7ebae92326 100644 --- a/rudder-client-javascript/RudderClient.min.js +++ b/rudder-client-javascript/RudderClient.min.js @@ -1 +1 @@ -function generateUUID(){var t=new Date.getTime();typeof performance!=='undefined'&&typeof performance.now==='function'&&(t+=performance.now());return'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,function(r){var e=(t+Math.random()*16)%16|0;t=Math.floor(t/16);return(r==='x'?e:e&3|8).toString(16)})}function getCurrentTimeFormatted(){var t=new Date.toISOString(),r=t.split('T')[0],e=t.split('T')[1].split('Z')[0].split('.')[0],n=t.split('Z')[0].split('.')[1];return r+" "+e+"+"+n}function getJSON(t,r){if(typeof window==='undefined')var e=require("xmlhttprequest").XMLHttpRequest;var n=new e;n.open('get',t,!0);n.responseType='json';n.onload=function(){var t=n.status;t==200?r(null,n.response):r(t)};n.send()}var MessageType={TRACK:"track",PAGE:"page",IDENTIFY:"identify"},ECommerceParamNames={QUERY:"query",PRICE:"price",PRODUCT_ID:"product_id",CATEGORY:"category",CURRENCY:"currency",LIST_ID:"list_id",PRODUCTS:"products",WISHLIST_ID:"wishlist_id",WISHLIST_NAME:"wishlist_name",QUANTITY:"quantity",CART_ID:"cart_id",CHECKOUT_ID:"checkout_id",TOTAL:"total",REVENUE:"revenue",ORDER_ID:"order_id"},ECommerceEvents={PRODUCTS_SEARCHED:"Products Searched",PRODUCT_LIST_VIEWED:"Product List Viewed",PRODUCT_LIST_FILTERED:"Product List Filtered",PROMOTION_VIEWED:"Promotion Viewed",PROMOTION_CLICKED:"Promotion Clicked",PRODUCT_CLICKED:"Product Clicked",PRODUCT_VIEWED:"Product Viewed",PRODUCT_ADDED:"Product Added",PRODUCT_REMOVED:"Product Removed",CART_VIEWED:"Cart Viewed",CHECKOUT_STARTED:"Checkout Started",CHECKOUT_STEP_VIEWED:"Checkout Step Viewed",CHECKOUT_STEP_COMPLETED:"Checkout Step Completed",PAYMENT_INFO_ENTERED:"Payment Info Entered",ORDER_UPDATED:"Order Updated",ORDER_COMPLETED:"Order Completed",ORDER_REFUNDED:"Order Refunded",ORDER_CANCELLED:"Order Cancelled",COUPON_ENTERED:"Coupon Entered",COUPON_APPLIED:"Coupon Applied",COUPON_DENIED:"Coupon Denied",COUPON_REMOVED:"Coupon Removed",PRODUCT_ADDED_TO_WISHLIST:"Product Added to Wishlist",PRODUCT_REMOVED_FROM_WISHLIST:"Product Removed from Wishlist",WISH_LIST_PRODUCT_ADDED_TO_CART:"Wishlist Product Added to Cart",PRODUCT_SHARED:"Product Shared",CART_SHARED:"Cart Shared",PRODUCT_REVIEWED:"Product Reviewed"},RudderIntegrationPlatform={RUDDERLABS:"rudderlabs",GA:"ga",AMPLITUDE:"amplitude"};let BASE_URL="https://rudderlabs.com",FLUSH_QUEUE_SIZE=30;class RudderProperty{constructor(){this.propertyMap={}}getPropertyMap(){return this.propertyMap}getProperty(t){return this.propertyMap[t]}setProperty(t,r){this.propertyMap[t]=r}setPropertyMap(t){this.propertyMap?Object.keys(t).forEach(r=>{this.propertyMap[r]=t[r]}):(this.propertyMap=t)}}class PagePropertyBuilder{constructor(){this.title="";this.url="";this.path="";this.referrer="";this.search="";this.keywords=""}build(){if(!this.url||0===this.url.length){throw new Error("Page url cannot be null or empty")}var t=new RudderProperty;t.setProperty("title",this.title);t.setProperty("url",this.url);t.setProperty("path",this.path);t.setProperty("referrer",this.referrer);t.setProperty("search",this.search);t.setProperty("keywords",this.keywords);return t}setTitle(t){this.title=t;return this}setUrl(t){this.url=t;return this}setPath(t){this.path=t;return this}setReferrer(t){this.referrer=t;return this}setSearch(t){this.search=t;return t}setKeywords(t){this.keywords=t;return this}}class ScreenPropertyBuilder{constructor(){this.name=""}build(){if(!this.name||0===this.name){throw new Error("Screen name cannot be null or empty")}var t=new RudderProperty;t.setProperty("name",this.name);return t}}class ECommerceOrder{contructor(){this.order_id="";this.affiliation="";this.value=0;this.revenue=0;this.shipping=0;this.tax=0;this.discount=0;this.coupon="";this.currency="";this.products=[]}setOrderId(t){this.order_id=t;console.log(JSON.stringify(this));return this}setAffiliation(t){this.affiliation=t;return this}setValue(t){this.value=t;return this}setRevenue(t){this.revenue=t;return this}setShipping(t){this.shipping=t;return!0}setTax(t){this.tax=t;return this}setDiscount(t){this.discount=t;return this}setCoupon(t){this.coupon=t;return this}setCurrency(t){this.currency=t;return this}addProducts(t){t&&(this.products||(this.products=[]),this.products.pushValues(t));return this}addProduct(t){t&&(this.products||(this.products=[]),this.products.push(t));return this}}class ECommerceProduct{constructor(){this.product_id="";this.sku="";this.category="";this.name="";this.brand="";this.variant="";this.price=0;this.currency="";this.quantity=0;this.coupon="";this.position=0;this.url="";this.image_url=""}setProductId(t){this.product_id=t;return this}setSku(t){this.sku=t;return this}setCategory(t){this.category=t;return this}setName(t){this.name=t;return this}setBrand(t){this.brand=t;return this}setVariant(t){this.variant=t;return this}setPrice(t){this.price=t;return this}setCurrency(t){this.currency=t;return this}setQuantity(t){this.quantity=t;return this}setCoupon(t){this.coupon=t;return t}setPosition(t){this.position=t;return this}setUrl(t){this.url=t;return this}setImageUrl(t){this.image_url=t;return this}}class ECommercePromotion{constructor(){this.promotion_id="";this.creative="";this.name="";this.position=0}}class ECommerceCart{constructor(){this.cart_id="";this.products=[]}addProducts(t){t&&this.products.pushValues(t);return this}addProduct(t){t&&this.products.push(t);return this}}class ECommerceCoupon{constructor(){this.cart_id="";this.order_id="";this.coupon_id="";this.coupon_name="";this.discount=0;this.reason=""}}class ECommerceWishList{constructor(){this.wishlist_id="";this.wishlist_name=""}setWishlistId(t){this.wishlist_id=t;return this}setWishlistName(t){this.wishlist_name=t;return this}}class ECommerceCheckout{constructor(){this.checkout_id="";this.order_id="";this.step="";this.shipping_method="";this.payment_method=""}}class CheckoutStartedEvent{constructor(){this.order=null}event(){return ECommerceEvents.CHECKOUT_STARTED}build(){var t=new RudderProperty;t.setPropertyMap(this.order);return t}setOrder(t){this.order=t;return this}}class OrderCompletedEvent{constructor(){this.order=null}event(){return ECommerceEvents.ORDER_COMPLETED}build(){var t=new RudderProperty;t.setProperty(this.order)}}class ProductAddedToCartEvent{contructor(){this.product=null;this.cartId=null}event(){return ECommerceEvents.PRODUCT_ADDED}build(){var t=new RudderProperty;t.setPropertyMap(this.product);t.setProperty(ECommerceParamNames.CART_ID,this.cartId);return t}setProduct(t){this.product=t;return this}setCartId(t){this.cartId=t;return this}}class ProductAddedToWishlistEvent{contructor(){this.product=null;this.wishlist=null}event(){return ECommerceEvents.PRODUCT_ADDED_TO_WISHLIST}build(){var t=new RudderProperty;t.setPropertyMap(this.product);t.setProperty(ECommerceParamNames.WISHLIST_ID,this.wishlist.wishlist_id);t.setProperty(ECommerceParamNames.WISHLIST_NAME,this.wishlist.wishlist_name);return t}setProduct(t){this.product=t;console.log(JSON.stringify(this.product));return this}setWishlist(t){this.wishlist=t;return this}}class ProductListViewedEvent{constructor(){this.listId=null;this.category=null;this.products=[]}addProducts(t){this.products?this.products.pushValues(t):(this.products=t)}addProduct(t){this.products||(this.products=[]);this.products.push(t)}event(){return ECommerceEvents.PRODUCT_LIST_VIEWED}build(){var t=new RudderProperty;t.setProperty(ECommerceParamNames.LIST_ID,this.listId);t.setProperty(ECommerceParamNames.CATEGORY,this.category);t.setProperty(ECommerceParamNames.PRODUCTS,this.products);return t}}class CartViewedEvent{constructor(){this.cartId=null;this.products=[]}addProducts(t){this.products?this.products.pushValues(t):(this.products=t);return this}addProduct(t){this.products||(this.products=[]);this.products.push(t);return this}setCartId(t){this.cartId=t;return this}event(){return ECommerceEvents.CART_VIEWED}build(){var t=new RudderProperty;t.setProperty(ECommerceParamNames.CART_ID,this.cartId);t.setProperty(ECommerceParamNames.PRODUCTS,this.products);return t}}class ProductRemovedFromCartEvent{constructor(){this.product=null;this.cartId=null}event(){return ECommerceEvents.PRODUCT_REMOVED}build(){var t=new RudderProperty;t.setPropertyMap(this.product);t.setProperty(ECommerceParamNames.CART_ID,this.cartId);return t}setProduct(t){this.product=t;return this}setCartId(t){this.cartId=t;return this}}class ProductSearchedEvent{constructor(){this.query=null}event(){return ECommerceEvents.PRODUCTS_SEARCHED}build(){var t=new RudderProperty;t.setProperty(ECommerceParamNames.QUERY,this.query);return t}}class ProductViewedEvent{constructor(){this.product=null}event(){return ECommerceEvents.PRODUCT_VIEWED}build(){var t=new RudderProperty;t.setProperty(this.product);return t}}var RudderConfig=(function(){var t;function r(){var t=BASE_URL;[];return{getDefaultIntegrations:function(){return[]},getEndPointUri:function(){return t},getFlushQueueSize:function(){return this.flushQueueSize},getIntegrations:function(){return this.integrations},setIntegrations:function(t){this.integrations=t;return this},setFlushQueueSize:function(t){this.flushQueueSize=t;return this},setEndPointUri:function(t){this.endPointUri=t;return this}}}return{getDefaultConfig:function(){t||(t=r());return t}}})();class EventRepository{constructor(t,r){this.eventsBuffer=[];this.write_key=t;this.rudderConfig=r}flush(t){this.eventsBuffer=[];this.eventsBuffer.push(t);var r=new RudderPayload;r.batch=this.eventsBuffer;r.write_key=this.write_key;r.sent_at=getCurrentTimeFormatted();if(typeof window==='undefined')var e=require("xmlhttprequest").XMLHttpRequest;var n=new e;console.log(JSON.stringify(r));n.open("POST",this.rudderConfig.getEndPointUri(),!0);n.setRequestHeader("Content-Type","application/json");n.onreadystatechange=function(){n.readyState===4&&n.status===200&&(this.eventsBuffer=[])};n.send(JSON.stringify(r))}}class RudderPayload{constructor(){this.batch=null;this.write_key=null}}class RudderElement{constructor(){this.rl_message=new RudderMessage}setType(t){this.rl_message.rl_type=t}setProperty(t){this.rl_message.rl_properties=t}setUserId(t){this.rl_message.rl_user_id=t}setEventName(t){this.rl_message.rl_event=t}updateTraits(t){this.rl_message.rl_context.rl_traits=t}}class RudderElementBuilder{constructor(){this.rudderProperty=null;this.event=null;this.userId=null;this.channel=null}setProperty(t){this.rudderProperty=t;return this}setPropertyBuilder(t){this.rudderProperty=t.build();return this}setEvent(t){this.event=t;return this}setUserId(t){this.userId=t;return this}setChannel(t){this.channel=t;return this}build(){var t=new RudderElement;t.setUserId(this.userId);t.setEventName(this.event);t.setProperty(this.rudderProperty);return t}}class RudderMessage{constructor(){this.rl_channel="web";this.rl_context=new RudderContext;this.rl_type=null;this.rl_action=null;this.rl_message_id=generateUUID().toString();this.rl_timestamp=new Date.getTime();this.rl_anonymous_id=generateUUID().toString();this.rl_user_id=null;this.rl_event=null;this.rl_properties={};this.rl_integrations={};this.rl_integrations.all=!0}getProperty(t){return this.rl_properties[t]}addProperty(t,r){this.rl_properties[t]=r}validateFor(t){if(!this.rl_properties){throw new Error("Key rl_properties is required")}switch(t){case MessageType.TRACK:if(!this.rl_event){throw new Error("Key rl_event is required for track event")};if(this.rl_event in Object.values(ECommerceEvents)){switch(rl_event){case ECommerceEvents.CHECKOUT_STEP_VIEWED:;case ECommerceEvents.CHECKOUT_STEP_COMPLETED:;case ECommerceEvents.PAYMENT_INFO_ENTERED:checkForKey("checkout_id");checkForKey("step");break;case ECommerceEvents.PROMOTION_VIEWED:;case ECommerceEvents.PROMOTION_CLICKED:checkForKey("promotion_id");break;case ECommerceEvents.ORDER_REFUNDED:checkForKey("order_id");break;default:}}else this.rl_properties.category||(this.rl_properties.category=this.rl_event);break;case MessageType.PAGE:break;case MessageType.SCREEN:if(!this.rl_properties.name){throw new Error("Key 'name' is required in rl_properties")};break}}checkForKey(t){if(!this.rl_properties[t]){throw new Error("Key '"+t+"' is required in rl_properties")}}}class RudderContext{constructor(){this.rl_app=new RudderApp;this.rl_traits=null;this.rl_library=new RudderLibraryInfo;var t=new RudderOSInfo;t.rl_version="";var r=new RudderScreenInfo;typeof window==='undefined'?(r.rl_width=0,r.rl_height=0,r.rl_density=0,t.rl_version="",t.rl_name="",this.rl_user_agent=null,this.rl_locale=null):(r.rl_width=window.width,r.rl_height=window.height,r.rl_density=window.devicePixelRatio,this.rl_user_agent=navigator.userAgent,this.rl_locale=navigator.language||navigator.browserLanguage);this.screen=r;this.rl_device=null;this.rl_network=null}}class RudderApp{constructor(){this.rl_build="1.0.0";this.rl_name="RudderLabs JavaScript SDK";this.rl_namespace="com.rudderlabs.javascript";this.rl_version="1.0.0"}}class RudderTraits{constructor(){this.rl_address=null;this.rl_age=null;this.rl_birthday=null;this.rl_company=null;this.rl_createdat=null;this.rl_description=null;this.rl_email=null;this.rl_firstname=null;this.rl_gender=null;this.rl_id=null;this.rl_lastname=null;this.rl_name=null;this.rl_phone=null;this.rl_title=null;this.rl_username=null}setAddress(t){this.rl_address=t;return this}setAge(t){this.rl_age=t;return this}setBirthday(t){this.rl_birthday=t;return this}setCompany(t){this.rl_company=t;return this}setCreatedAt(t){this.rl_createdat=createdAt;return this}setDescription(t){this.rl_description=t;return this}setEmail(t){this.rl_email=t;return this}setFirstname(t){this.rl_firstname=t;return this}setId(t){this.rl_id=t;return this}setLastname(t){this.rl_lastname=t;return this}setName(t){this.rl_name=t;return this}setPhone(t){this.rl_phone=t;return this}setTitle(t){this.rl_title=t;return this}setUsername(t){this.rl_username=t;return this}}class TraitsAddress{constructor(){this.rl_city="";this.rl_country="";this.rl_postalcode="";this.rl_state="";this.rl_street=""}}class TraitsCompany{constructor(){this.rl_name="";this.rl_id="";this.rl_industry=""}}class RudderLibraryInfo{constructor(){this.rl_name="RudderLabs JavaScript SDK";this.rl_version="1.0.0"}}class RudderOSInfo{constructor(){this.rl_name="";this.rl_version=""}}class RudderScreenInfo{constructor(){this.rl_density=0;this.rl_width=0;this.rl_height=0}}class RudderDeviceInfo{constructor(){this.rl_id="";this.rl_manufacturer="";this.rl_model="";this.rl_name=""}}class RudderNetwork{constructor(){this.rl_carrier=""}}var RudderClient=(function(){var t,r;function e(t){t.rl_message&&(t.rl_message.validateFor(MessageType.TRACK),t.rl_message.rl_type=MessageType.TRACK,t.rl_message.rl_properties.category||(t.rl_message.rl_properties.category=t.rl_message.rl_event),r.flush(t))}function n(t){t.rl_message&&(t.rl_message.validateFor(MessageType.PAGE),t.rl_message.rl_type=MessageType.PAGE,r.flush(t))}function u(t){var e=new RudderElementBuilder.setEvent(MessageType.IDENTIFY).setUserId(t.rl_id).build();e.updateTraits(t);e.setType(MessageType.IDENTIFY);r.flush(e)}function o(){return{track:e,page:n,identify:u}}return{getInstance:function(e,n){if(!t){if(!e||0===e.length){throw new Error("writeKey cannot be null or empty")}if(!n){throw new Error("rudderConfig cannot be null")}t=o();r=new EventRepository(e,n);this.rudderConfig=n}return t}}})(),client=RudderClient.getInstance("dummykey",RudderConfig.getDefaultConfig().setFlushQueueSize(1));console.log(JSON.stringify(new ECommerceOrder.setOrderId("dummy"))) +function replacer(t,r){if(!r||r==""){return void 0}else{return r}}function generateUUID(){var t=new Date.getTime();typeof performance!=='undefined'&&typeof performance.now==='function'&&(t+=performance.now());return'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,function(r){var e=(t+Math.random()*16)%16|0;t=Math.floor(t/16);return(r==='x'?e:e&3|8).toString(16)})}function getCurrentTimeFormatted(){var t=new Date.toISOString(),r=t.split('T')[0],e=t.split('T')[1].split('Z')[0].split('.')[0],n=t.split('Z')[0].split('.')[1];return r+" "+e+"+"+n}function getJSON(t,r){if(typeof window==='undefined')var e=require("xmlhttprequest").XMLHttpRequest;var n=new e;n.open('get',t,!0);n.responseType='json';n.onload=function(){var t=n.status;t==200?r(null,n.response):r(t)};n.send()}var MessageType={TRACK:"track",PAGE:"page",IDENTIFY:"identify"},ECommerceParamNames={QUERY:"query",PRICE:"price",PRODUCT_ID:"product_id",CATEGORY:"category",CURRENCY:"currency",LIST_ID:"list_id",PRODUCTS:"products",WISHLIST_ID:"wishlist_id",WISHLIST_NAME:"wishlist_name",QUANTITY:"quantity",CART_ID:"cart_id",CHECKOUT_ID:"checkout_id",TOTAL:"total",REVENUE:"revenue",ORDER_ID:"order_id",FILTERS:"filters",SORTS:"sorts",SHARE_VIA:"share_via",SHARE_MESSAGE:"share_message",RECIPIENT:"recipient"},ECommerceEvents={PRODUCTS_SEARCHED:"Products Searched",PRODUCT_LIST_VIEWED:"Product List Viewed",PRODUCT_LIST_FILTERED:"Product List Filtered",PROMOTION_VIEWED:"Promotion Viewed",PROMOTION_CLICKED:"Promotion Clicked",PRODUCT_CLICKED:"Product Clicked",PRODUCT_VIEWED:"Product Viewed",PRODUCT_ADDED:"Product Added",PRODUCT_REMOVED:"Product Removed",CART_VIEWED:"Cart Viewed",CHECKOUT_STARTED:"Checkout Started",CHECKOUT_STEP_VIEWED:"Checkout Step Viewed",CHECKOUT_STEP_COMPLETED:"Checkout Step Completed",PAYMENT_INFO_ENTERED:"Payment Info Entered",ORDER_UPDATED:"Order Updated",ORDER_COMPLETED:"Order Completed",ORDER_REFUNDED:"Order Refunded",ORDER_CANCELLED:"Order Cancelled",COUPON_ENTERED:"Coupon Entered",COUPON_APPLIED:"Coupon Applied",COUPON_DENIED:"Coupon Denied",COUPON_REMOVED:"Coupon Removed",PRODUCT_ADDED_TO_WISHLIST:"Product Added to Wishlist",PRODUCT_REMOVED_FROM_WISHLIST:"Product Removed from Wishlist",WISH_LIST_PRODUCT_ADDED_TO_CART:"Wishlist Product Added to Cart",PRODUCT_SHARED:"Product Shared",CART_SHARED:"Cart Shared",PRODUCT_REVIEWED:"Product Reviewed"},RudderIntegrationPlatform={RUDDERLABS:"rudderlabs",GA:"ga",AMPLITUDE:"amplitude"};let BASE_URL="https://rudderlabs.com",FLUSH_QUEUE_SIZE=30;class RudderProperty{constructor(){this.propertyMap={}}getPropertyMap(){return this.propertyMap}getProperty(t){return this.propertyMap[t]}setProperty(t,r){this.propertyMap[t]=r}setPropertyMap(t){this.propertyMap?Object.keys(t).forEach(r=>{this.propertyMap[r]=t[r]}):(this.propertyMap=t)}}class PagePropertyBuilder{constructor(){this.title="";this.url="";this.path="";this.referrer="";this.search="";this.keywords=""}build(){if(!this.url||0===this.url.length){throw new Error("Page url cannot be null or empty")}var t=new RudderProperty;t.setProperty("title",this.title);t.setProperty("url",this.url);t.setProperty("path",this.path);t.setProperty("referrer",this.referrer);t.setProperty("search",this.search);t.setProperty("keywords",this.keywords);return t}setTitle(t){this.title=t;return this}setUrl(t){this.url=t;return this}setPath(t){this.path=t;return this}setReferrer(t){this.referrer=t;return this}setSearch(t){this.search=t;return t}setKeywords(t){this.keywords=t;return this}}class ScreenPropertyBuilder{constructor(){this.name=""}build(){if(!this.name||0===this.name){throw new Error("Screen name cannot be null or empty")}var t=new RudderProperty;t.setProperty("name",this.name);return t}}class ECommerceOrder{constructor(){this.order_id="";this.affiliation="";this.total=0;this.value=0;this.revenue=0;this.shipping=0;this.tax=0;this.discount=0;this.coupon="";this.currency="";this.products=[]}setOrderId(t){this.order_id=t;return this}setAffiliation(t){this.affiliation=t;return this}setTotal(t){this.value=t;this.total=t;return this}setValue(t){this.value=t;this.total=t;return this}setRevenue(t){this.revenue=t;return this}setShipping(t){this.shipping=t;return this}setTax(t){this.tax=t;return this}setDiscount(t){this.discount=t;return this}setCoupon(t){this.coupon=t;return this}setCurrency(t){this.currency=t;return this}addProducts(t){t&&(this.products||(this.products=[]),this.products.pushValues(t));return this}addProduct(t){t&&(this.products||(this.products=[]),this.products.push(t));return this}}class ECommerceCompletedOrder extends ECommerceOrder{constructor(){super();this.checkout_id=""}setCheckoutId(t){this.checkout_id=t;return this}}class ECommerceCoupon{constructor(){this.order_id="";this.cart_id="";this.coupon_id=""}setOrderId(t){this.order_id=t;return this}setCartId(t){this.cart_id=t;return this}setCouponId(t){this.coupon_id=t;return this}}class ECommerceProductFilter{constructor(){this.type="";this.value=""}setType(t){this.type=t;return this}setValue(t){this.value=t;return this}}class ECommerceProductSort{constructor(){this.type="";this.value=""}setType(t){this.type=t;return this}setValue(t){this.value=t;return this}}class ECommerceProductBase{constructor(){this.product_id=""}setProductId(t){this.product_id=t;return this}}class ECommerceProduct extends ECommerceProductBase{constructor(){super();this.sku="";this.category="";this.name="";this.brand="";this.variant="";this.price=0;this.currency="";this.quantity=0;this.coupon="";this.position=0;this.url="";this.image_url=""}setSku(t){this.sku=t;return this}setCategory(t){this.category=t;return this}setName(t){this.name=t;return this}setBrand(t){this.brand=t;return this}setVariant(t){this.variant=t;return this}setPrice(t){this.price=t;return this}setCurrency(t){this.currency=t;return this}setQuantity(t){this.quantity=t;return this}setCoupon(t){this.coupon=t;return this}setPosition(t){this.position=t;return this}setUrl(t){this.url=t;return this}setImageUrl(t){this.image_url=t;return this}}class ECommercePromotion{constructor(){this.promotion_id="";this.creative="";this.name="";this.position=0}setPromotionId(t){this.promotion_id=t;return this}setCreative(t){this.creative=t;return this}setName(t){this.name=t;return this}setPosition(t){this.position=t;return this}}class ECommerceCart{constructor(){this.cart_id="";this.products=[]}addProducts(t){t&&this.products.pushValues(t);return this}addProduct(t){t&&this.products.push(t);return this}}class ECommerceExtendedCoupon extends ECommerceCoupon{constructor(){super();this.coupon_name=""}setCouponName(t){this.coupon_name=t;return this}}class ECommerceAppliedOrRemovedCoupon extends ECommerceExtendedCoupon{constructor(){super();this.discount=0}setDiscount(t){this.discount=t;return this}}class ECommerceDeniedCoupon extends ECommerceExtendedCoupon{constructor(){super();this.reason=""}setReason(t){this.reason=t;return this}}class ECommerceWishList{constructor(){this.wishlist_id="";this.wishlist_name=""}setWishlistId(t){this.wishlist_id=t;return this}setWishlistName(t){this.wishlist_name=t;return this}}class ECommerceCheckout{constructor(){this.checkout_id="";this.step=-1;this.shipping_method="";this.payment_method=""}setCheckoutId(t){this.checkout_id=t;return this}setStep(t){this.step=t;return this}setShippingMethod(t){this.shipping_method=t;return this}setPaymentMethod(t){this.payment_method=t;return this}}class ECommercePaymentInfo extends ECommerceCheckout{constructor(){super();this.order_id=""}setOrderId(t){this.order_id=t;return this}}class PromotionEvent{constructor(){this.promotion=null}setPromotion(t){this.promotion=t;return this}build(){var t=new RudderProperty;t.setPropertyMap(this.promotion);return t}}class PromotionViewedEvent extends PromotionEvent{event(){return ECommerceEvents.PROMOTION_VIEWED}}class PromotionClickedEvent extends PromotionEvent{event(){return ECommerceEvents.PROMOTION_CLICKED}}class CheckoutEvent{constructor(){this.checkout=null}build(){var t=new RudderProperty;t.setPropertyMap(this.checkout);return t}setCheckout(t){this.checkout=t;return this}}class CheckoutStepViewedEvent extends CheckoutEvent{event(){return ECommerceEvents.CHECKOUT_STEP_VIEWED}}class CheckoutStepCompletedEvent extends CheckoutEvent{event(){return ECommerceEvents.CHECKOUT_STEP_COMPLETED}}class OrderEvent{constructor(){this.order=null}build(){var t=new RudderProperty;t.setPropertyMap(this.order);return t}setOrder(t){this.order=t;return this}}class CheckoutStartedEvent extends OrderEvent{event(){return ECommerceEvents.CHECKOUT_STARTED}}class OrderCompletedEvent extends OrderEvent{event(){return ECommerceEvents.ORDER_COMPLETED}}class OrderUpdatedEvent extends OrderEvent{event(){return ECommerceEvents.ORDER_UPDATED}}class OrderRefundedEvent extends OrderEvent{event(){return ECommerceEvents.ORDER_REFUNDED}}class OrderCancelledEvent extends OrderEvent{event(){return ECommerceEvents.ORDER_CANCELLED}}class PaymentInfoEnteredEvent{constructor(){this.paymentInfo=null}event(){return ECommerceEvents.PAYMENT_INFO_ENTERED}build(){var t=new RudderProperty;t.setPropertyMap(this.paymentInfo);return t}setPaymentInfo(t){this.paymentInfo=t;return this}}class ProductEvent{constructor(){this.product=null}build(){var t=new RudderProperty;t.setPropertyMap(this.product);return t}setProduct(t){this.product=t;return this}}class ProductClickedEvent extends ProductEvent{event(){return ECommerceEvents.PRODUCT_CLICKED}}class ProductViewedEvent extends ProductEvent{event(){return ECommerceEvents.PRODUCT_VIEWED}}class ProductCartEvent{constructor(){this.product=null;this.cartId=null}build(){var t=new RudderProperty;t.setPropertyMap(this.product);t.setProperty(ECommerceParamNames.CART_ID,this.cartId);return t}setProduct(t){this.product=t;return this}setCartId(t){this.cartId=t;return this}}class ProductAddedToCartEvent extends ProductCartEvent{event(){return ECommerceEvents.PRODUCT_ADDED}}class ProductRemovedFromCartEvent extends ProductCartEvent{event(){return ECommerceEvents.PRODUCT_REMOVED}}class ProductWishlistEvent{constructor(){this.product=null;this.wishlist=null}build(){var t=new RudderProperty;t.setPropertyMap(this.product);t.setProperty(ECommerceParamNames.WISHLIST_ID,this.wishlist.wishlist_id);t.setProperty(ECommerceParamNames.WISHLIST_NAME,this.wishlist.wishlist_name);return t}setProduct(t){this.product=t;return this}setWishlist(t){this.wishlist=t;return this}}class ProductAddedToWishlistEvent extends ProductWishlistEvent{event(){return ECommerceEvents.PRODUCT_ADDED_TO_WISHLIST}}class ProductRemovedFromWishlistEvent extends ProductWishlistEvent{event(){return ECommerceEvents.PRODUCT_REMOVED_FROM_WISHLIST}}class WishlistProductAddedToCartEvent extends ProductWishlistEvent{constructor(){super();this.cart_id=""}event(){return ECommerceEvents.WISH_LIST_PRODUCT_ADDED_TO_CART}build(){var t=super.build();t.setProperty(ECommerceParamNames.CART_ID,this.cart_id);return t}setCartId(t){this.cart_id=t;return this}}class ProductListViewedEvent{constructor(){this.listId=null;this.category=null;this.products=[]}setListId(t){this.listId=t;return this}setCategory(t){this.category=t;return this}addProducts(t){this.products?this.products.pushValues(t):(this.products=t);return this}addProduct(t){this.products||(this.products=[]);this.products.push(t);return this}event(){return ECommerceEvents.PRODUCT_LIST_VIEWED}build(){var t=new RudderProperty;t.setProperty(ECommerceParamNames.LIST_ID,this.listId);t.setProperty(ECommerceParamNames.CATEGORY,this.category);t.setProperty(ECommerceParamNames.PRODUCTS,this.products);return t}}class ProductListFilteredEvent{constructor(){this.listId=null;this.filters=[];this.sorts=[];this.products=[]}setListId(t){this.listId=t;return this}addProducts(t){this.products?this.products.pushValues(t):(this.products=t);return this}addProduct(t){this.products||(this.products=[]);this.products.push(t);return this}addFilters(t){this.filters?this.filters.pushValues(t):(this.filters=t);return this}addFilter(t){this.filters||(this.filters=[]);this.filters.push(t);return this}addSorts(t){this.sorts?this.sorts.pushValues(t):(this.sorts=t);return this}addSort(t){this.sorts||(this.sorts=[]);this.sorts.push(t);return this}event(){return ECommerceEvents.PRODUCT_LIST_FILTERED}build(){var t=new RudderProperty;t.setProperty(ECommerceParamNames.LIST_ID,this.listId);t.setProperty(ECommerceParamNames.FILTERS,this.filters);t.setProperty(ECommerceParamNames.PRODUCTS,this.products);t.setProperty(ECommerceParamNames.SORTS,this.sorts);return t}}class CartViewedEvent{constructor(){this.cartId=null;this.products=[]}addProducts(t){this.products?this.products.pushValues(t):(this.products=t);return this}addProduct(t){this.products||(this.products=[]);this.products.push(t);return this}setCartId(t){this.cartId=t;return this}event(){return ECommerceEvents.CART_VIEWED}build(){var t=new RudderProperty;t.setProperty(ECommerceParamNames.CART_ID,this.cartId);t.setProperty(ECommerceParamNames.PRODUCTS,this.products);return t}}class ProductSearchedEvent{constructor(){this.query=null}event(){return ECommerceEvents.PRODUCTS_SEARCHED}build(){var t=new RudderProperty;t.setProperty(ECommerceParamNames.QUERY,this.query);return t}setQuery(t){this.query=t;return this}}class CouponEvent{contructor(){this.coupon=null}build(){var t=new RudderProperty;t.setPropertyMap(this.coupon);return t}setCoupon(t){this.coupon=t;return this}}class CouponAppliedEvent extends CouponEvent{event(){return ECommerceEvents.COUPON_APPLIED}}class CouponRemovedEvent extends CouponEvent{event(){return ECommerceEvents.COUPON_REMOVED}}class CouponDeniedEvent extends CouponEvent{event(){return ECommerceEvents.COUPON_DENIED}}class ShareEvent{constructor(){this.share_via="";this.share_message="";this.recipient=""}build(){var t=new RudderProperty;t.setProperty(ECommerceParamNames.SHARE_VIA,this.share_via);t.setProperty(ECommerceParamNames.SHARE_MESSAGE,this.share_message);t.setProperty(ECommerceParamNames.RECIPIENT,this.recipient);return t}setShareVia(t){this.share_via=t;return this}setShareMessage(t){this.share_message=t;return this}setRecipient(t){this.recipient=t;return this}}class ProductSharedEvent extends ShareEvent{constructor(){super();this.product=null}build(){var t=super.build();t.setPropertyMap(this.product);return t}event(){return ECommerceEvents.PRODUCT_SHARED}setProduct(t){this.product=t;return this}}class CartSharedEvent extends ShareEvent{constructor(){super();this.cart_id="";this.products=[]}event(){return ECommerceEvents.CART_SHARED}build(){var t=super.build();t.setProperty(ECommerceParamNames.CART_ID,this.cart_id);t.setProperty(ECommerceParamNames.PRODUCTS,this.products);return t}setCartId(t){this.cart_id=t;return this}addProduct(t){this.products||(this.products=[]);this.products.push(t);return this}}class ProductReviewedEvent{constructor(){this.product_id="";this.review_id="";this.review_body="";this.rating=""}event(){return ECommerceEvents.PRODUCT_REVIEWED}build(){var t=new RudderProperty;t.setPropertyMap(this);return t}setProductId(t){this.product_id=t;return this}setReviewId(t){this.review_id=t;return this}setReviewBody(t){this.review_body=t;return this}setRating(t){this.rating=t;return this}}var RudderConfig=(function(){var t;function r(){var t=BASE_URL;[];return{getDefaultIntegrations:function(){return[]},getEndPointUri:function(){return t},getFlushQueueSize:function(){return this.flushQueueSize},getIntegrations:function(){return this.integrations},setIntegrations:function(t){this.integrations=t;return this},setFlushQueueSize:function(t){this.flushQueueSize=t;return this},setEndPointUri:function(t){this.endPointUri=t;return this}}}return{getDefaultConfig:function(){t||(t=r());return t}}})();class EventRepository{constructor(t,r){this.eventsBuffer=[];this.write_key=t;this.rudderConfig=r}flush(t){this.eventsBuffer=[];this.eventsBuffer.push(t);var r=new RudderPayload;r.batch=this.eventsBuffer;r.write_key=this.write_key;r.sent_at=getCurrentTimeFormatted();if(typeof window==='undefined')var e=require("xmlhttprequest").XMLHttpRequest;var n=new e;console.log(JSON.stringify(r,replacer));n.open("POST",this.rudderConfig.getEndPointUri(),!0);n.setRequestHeader("Content-Type","application/json");n.onreadystatechange=function(){n.readyState===4&&n.status===200&&(this.eventsBuffer=[])};n.send(JSON.stringify(r,replacer))}}class RudderPayload{constructor(){this.batch=null;this.write_key=null}}class RudderElement{constructor(){this.rl_message=new RudderMessage}setType(t){this.rl_message.rl_type=t}setProperty(t){this.rl_message.rl_properties=t}setUserId(t){this.rl_message.rl_user_id=t}setEventName(t){this.rl_message.rl_event=t}updateTraits(t){this.rl_message.rl_context.rl_traits=t}}class RudderElementBuilder{constructor(){this.rudderProperty=null;this.event=null;this.userId=null;this.channel=null}setProperty(t){this.rudderProperty=t;return this}setPropertyBuilder(t){this.rudderProperty=t.build();return this}setEvent(t){this.event=t;return this}setUserId(t){this.userId=t;return this}setChannel(t){this.channel=t;return this}build(){var t=new RudderElement;t.setUserId(this.userId);t.setEventName(this.event);t.setProperty(this.rudderProperty);return t}}class RudderMessage{constructor(){this.rl_channel="web";this.rl_context=new RudderContext;this.rl_type=null;this.rl_action=null;this.rl_message_id=generateUUID().toString();this.rl_timestamp=new Date.getTime();this.rl_anonymous_id=generateUUID().toString();this.rl_user_id=null;this.rl_event=null;this.rl_properties={};this.rl_integrations={};this.rl_integrations.all=!0}getProperty(t){return this.rl_properties[t]}addProperty(t,r){this.rl_properties[t]=r}validateFor(t){if(!this.rl_properties){throw new Error("Key rl_properties is required")}switch(t){case MessageType.TRACK:if(!this.rl_event){throw new Error("Key rl_event is required for track event")};if(this.rl_event in Object.values(ECommerceEvents)){switch(rl_event){case ECommerceEvents.CHECKOUT_STEP_VIEWED:;case ECommerceEvents.CHECKOUT_STEP_COMPLETED:;case ECommerceEvents.PAYMENT_INFO_ENTERED:checkForKey("checkout_id");checkForKey("step");break;case ECommerceEvents.PROMOTION_VIEWED:;case ECommerceEvents.PROMOTION_CLICKED:checkForKey("promotion_id");break;case ECommerceEvents.ORDER_REFUNDED:checkForKey("order_id");break;default:}}else this.rl_properties.rl_category||(this.rl_properties.rl_category=this.rl_event);break;case MessageType.PAGE:break;case MessageType.SCREEN:if(!this.rl_properties.name){throw new Error("Key 'name' is required in rl_properties")};break}}checkForKey(t){if(!this.rl_properties[t]){throw new Error("Key '"+t+"' is required in rl_properties")}}}class RudderContext{constructor(){this.rl_app=new RudderApp;this.rl_traits=null;this.rl_library=new RudderLibraryInfo;var t=new RudderOSInfo;t.rl_version="";var r=new RudderScreenInfo;typeof window==='undefined'?(r.rl_width=0,r.rl_height=0,r.rl_density=0,t.rl_version="",t.rl_name="",this.rl_user_agent=null,this.rl_locale=null):(r.rl_width=window.width,r.rl_height=window.height,r.rl_density=window.devicePixelRatio,this.rl_user_agent=navigator.userAgent,this.rl_locale=navigator.language||navigator.browserLanguage);this.screen=r;this.rl_device=null;this.rl_network=null}}class RudderApp{constructor(){this.rl_build="1.0.0";this.rl_name="RudderLabs JavaScript SDK";this.rl_namespace="com.rudderlabs.javascript";this.rl_version="1.0.0"}}class RudderTraits{constructor(){this.rl_address=null;this.rl_age=null;this.rl_birthday=null;this.rl_company=null;this.rl_createdat=null;this.rl_description=null;this.rl_email=null;this.rl_firstname=null;this.rl_gender=null;this.rl_id=null;this.rl_lastname=null;this.rl_name=null;this.rl_phone=null;this.rl_title=null;this.rl_username=null}setAddress(t){this.rl_address=t;return this}setAge(t){this.rl_age=t;return this}setBirthday(t){this.rl_birthday=t;return this}setCompany(t){this.rl_company=t;return this}setCreatedAt(t){this.rl_createdat=createdAt;return this}setDescription(t){this.rl_description=t;return this}setEmail(t){this.rl_email=t;return this}setFirstname(t){this.rl_firstname=t;return this}setId(t){this.rl_id=t;return this}setLastname(t){this.rl_lastname=t;return this}setName(t){this.rl_name=t;return this}setPhone(t){this.rl_phone=t;return this}setTitle(t){this.rl_title=t;return this}setUsername(t){this.rl_username=t;return this}}class TraitsAddress{constructor(){this.rl_city="";this.rl_country="";this.rl_postalcode="";this.rl_state="";this.rl_street=""}}class TraitsCompany{constructor(){this.rl_name="";this.rl_id="";this.rl_industry=""}}class RudderLibraryInfo{constructor(){this.rl_name="RudderLabs JavaScript SDK";this.rl_version="1.0.0"}}class RudderOSInfo{constructor(){this.rl_name="";this.rl_version=""}}class RudderScreenInfo{constructor(){this.rl_density=0;this.rl_width=0;this.rl_height=0}}class RudderDeviceInfo{constructor(){this.rl_id="";this.rl_manufacturer="";this.rl_model="";this.rl_name=""}}class RudderNetwork{constructor(){this.rl_carrier=""}}var RudderClient=(function(){var t,r;function e(t){t.rl_message&&(t.rl_message.validateFor(MessageType.TRACK),t.rl_message.rl_type=MessageType.TRACK,t.rl_message.rl_properties.rl_category||(t.rl_message.rl_properties.rl_category=t.rl_message.rl_event),r.flush(t))}function n(t){t.rl_message&&(t.rl_message.validateFor(MessageType.PAGE),t.rl_message.rl_type=MessageType.PAGE,r.flush(t))}function u(t){var e=new RudderElementBuilder.setEvent(MessageType.IDENTIFY).setUserId(t.rl_id).build();e.updateTraits(t);e.setType(MessageType.IDENTIFY);r.flush(e)}function o(){return{track:e,page:n,identify:u}}return{getInstance:function(e,n){if(!t){if(!e||0===e.length){throw new Error("writeKey cannot be null or empty")}if(!n){throw new Error("rudderConfig cannot be null")}t=o();r=new EventRepository(e,n);this.rudderConfig=n}return t}}})()