@surfside/surfside-events 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +29 -0
- package/README.md +45 -0
- package/dist/index.module.d.ts +245 -0
- package/dist/index.module.js +298 -0
- package/dist/index.module.js.map +1 -0
- package/dist/index.umd.d.ts +245 -0
- package/dist/index.umd.js +621 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/index.umd.min.d.ts +245 -0
- package/dist/index.umd.min.js +7 -0
- package/dist/index.umd.min.js.map +1 -0
- package/package.json +53 -0
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { BrowserPlugin } from '@surfside/browser-core';
|
|
2
|
+
import { CommonEventProperties } from '@surfside/digital-core';
|
|
3
|
+
declare function SurfsideCommercePlugin(): BrowserPlugin;
|
|
4
|
+
/**
|
|
5
|
+
* A Commerce Action
|
|
6
|
+
* Used when tracking an Surfside Commerce Action with all stored Commerce contexts
|
|
7
|
+
*/
|
|
8
|
+
interface commerceAction {
|
|
9
|
+
/** Actions specify how to interpret product and promotion data */
|
|
10
|
+
action?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Track a Commerce Action with all stored Commerce contexts
|
|
14
|
+
*
|
|
15
|
+
* @param event
|
|
16
|
+
* @param trackers
|
|
17
|
+
*/
|
|
18
|
+
declare function setCommerceAction(event?: commerceAction & CommonEventProperties, trackers?: Array<string>): void;
|
|
19
|
+
/**
|
|
20
|
+
* The Commerce Transaction Context
|
|
21
|
+
* Represents information about an ecommerce related action that has taken place.
|
|
22
|
+
*/
|
|
23
|
+
interface commerceTransactionContext {
|
|
24
|
+
/** The transaction id */
|
|
25
|
+
id?: string;
|
|
26
|
+
/** The store of affiliation from which this transaction occured */
|
|
27
|
+
affiliation?: string;
|
|
28
|
+
/** Specifies the total revenue or grand total associated with the transaction */
|
|
29
|
+
revenue?: string;
|
|
30
|
+
/** The total tax associated with the transaction. */
|
|
31
|
+
tax?: number;
|
|
32
|
+
/** The shipping cost associated with the transaction. */
|
|
33
|
+
shipping?: number;
|
|
34
|
+
/** The transaction coupon redeemed with the transaction. */
|
|
35
|
+
coupon?: string;
|
|
36
|
+
/** The list that the associated products belong to. */
|
|
37
|
+
list?: string;
|
|
38
|
+
/** A number representing a step in the checkout process. Optional on `checkout` actions. */
|
|
39
|
+
step?: number;
|
|
40
|
+
/** Additional field for checkout and checkout_option actions that can describe option information on the checkout page, like selected payment method. */
|
|
41
|
+
option?: string;
|
|
42
|
+
/** The currency of the transactoin */
|
|
43
|
+
currency?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Adds a Commerce Transaction Context to an Action
|
|
47
|
+
*
|
|
48
|
+
* @param context - The context to be stored
|
|
49
|
+
* @param trackers - The tracker identifiers which the context will be stored against
|
|
50
|
+
*/
|
|
51
|
+
declare function addTransaction(context?: commerceTransactionContext, trackers?: Array<string>): void;
|
|
52
|
+
/**
|
|
53
|
+
* A Commerce Impression Context
|
|
54
|
+
*/
|
|
55
|
+
interface commerceImpressionContext {
|
|
56
|
+
/** The product ID or SKU */
|
|
57
|
+
id?: string;
|
|
58
|
+
/** The name of the product */
|
|
59
|
+
name?: string;
|
|
60
|
+
/** The list or collection to which the product belongs */
|
|
61
|
+
list?: string;
|
|
62
|
+
/** The brand associated with the product */
|
|
63
|
+
brand?: string;
|
|
64
|
+
/** The category to which the product belongs */
|
|
65
|
+
category?: string;
|
|
66
|
+
/** The variant of the product */
|
|
67
|
+
variant?: string;
|
|
68
|
+
/** The product's position in a list or collection */
|
|
69
|
+
position?: number;
|
|
70
|
+
/** The price of a product */
|
|
71
|
+
price?: string;
|
|
72
|
+
/** The currency of a product */
|
|
73
|
+
currency?: string;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Adds a Commerce Impression Context
|
|
77
|
+
*
|
|
78
|
+
* @param context - The context to be stored
|
|
79
|
+
* @param trackers - The tracker identifiers which the context will be stored against
|
|
80
|
+
*/
|
|
81
|
+
declare function addImpression(context?: commerceImpressionContext, trackers?: Array<string>): void;
|
|
82
|
+
/**
|
|
83
|
+
* A Commerce Product Context
|
|
84
|
+
*/
|
|
85
|
+
interface commerceProductContext {
|
|
86
|
+
/** The product ID or SKU */
|
|
87
|
+
id?: string;
|
|
88
|
+
/** The name of the product */
|
|
89
|
+
name?: string;
|
|
90
|
+
/** The list or collection to which the product belongs */
|
|
91
|
+
list?: string;
|
|
92
|
+
/** The brand associated with the product */
|
|
93
|
+
brand?: string;
|
|
94
|
+
/** The category to which the product belongs */
|
|
95
|
+
category?: string;
|
|
96
|
+
/** The variant of the product */
|
|
97
|
+
variant?: string;
|
|
98
|
+
/** The price of a product */
|
|
99
|
+
price?: number;
|
|
100
|
+
/** The quantity of a product */
|
|
101
|
+
quantity?: number;
|
|
102
|
+
/** The coupon code associated with a product */
|
|
103
|
+
coupon?: string;
|
|
104
|
+
/** The product's position in a list or collection */
|
|
105
|
+
position?: number;
|
|
106
|
+
/** The currency of the product */
|
|
107
|
+
currency?: string;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Adds a Commerce Product Context
|
|
111
|
+
*
|
|
112
|
+
* @param context - The context to be stored
|
|
113
|
+
* @param trackers - The tracker identifiers which the context will be stored against
|
|
114
|
+
*/
|
|
115
|
+
declare function addProduct(context?: commerceProductContext, trackers?: Array<string>): void;
|
|
116
|
+
/**
|
|
117
|
+
* A Commerce Promotion Context
|
|
118
|
+
*/
|
|
119
|
+
interface commercePromoContext {
|
|
120
|
+
/** The promotion ID */
|
|
121
|
+
id?: string;
|
|
122
|
+
/** The name of the promotion */
|
|
123
|
+
name?: string;
|
|
124
|
+
/** The creative associated with the promotion */
|
|
125
|
+
creative?: string;
|
|
126
|
+
/** The position of the creative */
|
|
127
|
+
position?: string;
|
|
128
|
+
/** The currency of the product */
|
|
129
|
+
currency?: string;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Adds a Commerce Promotion Context
|
|
133
|
+
*
|
|
134
|
+
* @param context - The context to be stored
|
|
135
|
+
* @param trackers - The tracker identifiers which the context will be stored against
|
|
136
|
+
*/
|
|
137
|
+
declare function addPromotion(context?: commercePromoContext, trackers?: Array<string>): void;
|
|
138
|
+
/** SURFSIDE CORE CONTEXTS **/
|
|
139
|
+
/**
|
|
140
|
+
* A Surfside Source Context
|
|
141
|
+
*/
|
|
142
|
+
interface sourceContext {
|
|
143
|
+
/** The Account ID */
|
|
144
|
+
accountId?: string;
|
|
145
|
+
/** The Source ID */
|
|
146
|
+
sourceId?: string;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Adds a Surfside Source Context
|
|
150
|
+
*
|
|
151
|
+
* @param context - The context to be stored
|
|
152
|
+
* @param trackers - The tracker identifiers which the context will be stored against
|
|
153
|
+
*/
|
|
154
|
+
declare function source(context?: sourceContext, trackers?: Array<string>): void;
|
|
155
|
+
/**
|
|
156
|
+
* A Surfside Segment Context
|
|
157
|
+
*/
|
|
158
|
+
interface segmentContext {
|
|
159
|
+
/** The Segment ID */
|
|
160
|
+
segmentId?: string;
|
|
161
|
+
/** The Segment Value */
|
|
162
|
+
segmentVal?: string;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Adds a Surfside Segment Context
|
|
166
|
+
*
|
|
167
|
+
* @param context - The context to be stored
|
|
168
|
+
* @param trackers - The tracker identifiers which the context will be stored against
|
|
169
|
+
*/
|
|
170
|
+
declare function segment(context?: segmentContext, trackers?: Array<string>): void;
|
|
171
|
+
/**
|
|
172
|
+
* A Surfside User Context
|
|
173
|
+
*/
|
|
174
|
+
interface userContext {
|
|
175
|
+
/** The address of the user */
|
|
176
|
+
address?: string;
|
|
177
|
+
/** The age of the user */
|
|
178
|
+
age?: string;
|
|
179
|
+
/** The company of the user */
|
|
180
|
+
company?: string;
|
|
181
|
+
/** The created timstamp of the user */
|
|
182
|
+
createdAt?: string;
|
|
183
|
+
/** The date of birth of the user */
|
|
184
|
+
dateOfBirth?: string;
|
|
185
|
+
/** The email of the user */
|
|
186
|
+
email?: string;
|
|
187
|
+
/** The first name of the user */
|
|
188
|
+
firstName?: string;
|
|
189
|
+
/** The gender of the user */
|
|
190
|
+
gender?: string;
|
|
191
|
+
/** The user ID of the user */
|
|
192
|
+
userId?: string;
|
|
193
|
+
/** The last name of the user */
|
|
194
|
+
lastName?: string;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Adds a Surfside User Context
|
|
198
|
+
*
|
|
199
|
+
* @param context - The context to be stored
|
|
200
|
+
* @param trackers - The tracker identifiers which the context will be stored against
|
|
201
|
+
*/
|
|
202
|
+
declare function setUser(context?: userContext, trackers?: Array<string>): void;
|
|
203
|
+
/**
|
|
204
|
+
* A Surfside User Context
|
|
205
|
+
*/
|
|
206
|
+
interface identifyUserContext {
|
|
207
|
+
/** The ID of the user */
|
|
208
|
+
id?: string;
|
|
209
|
+
/** The address of the user */
|
|
210
|
+
address?: string;
|
|
211
|
+
/** The age of the user */
|
|
212
|
+
age?: string;
|
|
213
|
+
/** The company of the user */
|
|
214
|
+
company?: string;
|
|
215
|
+
/** The created timstamp of the user */
|
|
216
|
+
createdAt?: string;
|
|
217
|
+
/** The date of birth of the user */
|
|
218
|
+
dateOfBirth?: string;
|
|
219
|
+
/** The email of the user */
|
|
220
|
+
email?: string;
|
|
221
|
+
/** The first name of the user */
|
|
222
|
+
firstName?: string;
|
|
223
|
+
/** The gender of the user */
|
|
224
|
+
gender?: string;
|
|
225
|
+
/** The user ID of the user */
|
|
226
|
+
userId?: string;
|
|
227
|
+
/** The last name of the user */
|
|
228
|
+
lastName?: string;
|
|
229
|
+
/** The name of the user */
|
|
230
|
+
name?: string;
|
|
231
|
+
/** The phone of the user */
|
|
232
|
+
phone?: string;
|
|
233
|
+
/** The title of the user */
|
|
234
|
+
title?: string;
|
|
235
|
+
/** The username of the user */
|
|
236
|
+
username?: string;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Adds a Surfside Context
|
|
240
|
+
*
|
|
241
|
+
* @param context - The context to be stored
|
|
242
|
+
* @param trackers - The tracker identifiers which the context will be stored against
|
|
243
|
+
*/
|
|
244
|
+
declare function identifyUser(context?: identifyUserContext, trackers?: Array<string>): void;
|
|
245
|
+
export { SurfsideCommercePlugin, commerceAction, setCommerceAction, commerceTransactionContext, addTransaction, commerceImpressionContext, addImpression, commerceProductContext, addProduct, commercePromoContext, addPromotion, sourceContext, source, segmentContext, segment, userContext, setUser, identifyUserContext, identifyUser };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Surfside Digital Analytics v0.0.1 (https://surfside.io)
|
|
3
|
+
* Copyright 2022 Surfside Solutions Inc, Snowplow Analytics Ltd, 2010 Anthon Pang
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).snowplowEnhancedEcommerce={})}(this,(function(e){function n(e,n,o){if(o||2===arguments.length)for(var t,r=0,i=n.length;r<i;r++)!t&&r in n||(t||(t=Array.prototype.slice.call(n,0,r)),t[r]=n[r]);return e.concat(t||Array.prototype.slice.call(n))}function o(e){return e=parseInt(e),isNaN(e)?void 0:e}function t(e){return e=parseFloat(e),isNaN(e)?void 0:e}function r(e,n,o){try{var t=null!=e?e:Object.keys(n);e=[];for(var r=0;r<t.length;r++){var i=t[r];n.hasOwnProperty(i)?e.push(n[i]):c.warn(i+" not configured")}e.forEach(o)}catch(e){c.error("Function failed",e)}}var i,a;(a=i||(i={}))[a.none=0]="none",a[a.error=1]="error",a[a.warn=2]="warn",a[a.debug=3]="debug",a[a.info=4]="info";var c=function(e){return void 0===e&&(e=i.warn),{setLogLevel:function(n){e=i[n]?n:i.warn},warn:function(o,t){for(var r=[],a=2;a<arguments.length;a++)r[a-2]=arguments[a];e>=i.warn&&"undefined"!=typeof console&&(a="Snowplow: "+o,t?console.warn.apply(console,n([a+"\n",t],r,!1)):console.warn.apply(console,n([a],r,!1)))},error:function(o,t){for(var r=[],a=2;a<arguments.length;a++)r[a-2]=arguments[a];e>=i.error&&"undefined"!=typeof console&&(a="Snowplow: "+o+"\n",t?console.error.apply(console,n([a+"\n",t],r,!1)):console.error.apply(console,n([a],r,!1)))},debug:function(o){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];e>=i.debug&&"undefined"!=typeof console&&console.debug.apply(console,n(["Snowplow: "+o],t,!1))},info:function(o){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];e>=i.info&&"undefined"!=typeof console&&console.info.apply(console,n(["Snowplow: "+o],t,!1))}}}(),s={},d={};e.SurfsideCommercePlugin=function(){return{activateBrowserPlugin:function(e){s[e.id]=e,d[e.id]=[]}}},e.addImpression=function(e,n){void 0===e&&(e={}),void 0===n&&(n=Object.keys(s));var r=e.id,i=e.name,a=e.list,c=e.brand,u=e.category,f=e.variant,l=e.position,p=e.price,m=e.currency;n.forEach((function(e){d[e]&&d[e].push({schema:"iglu:io.surfside.commerce/impression/jsonschema/1-0-0",data:{id:r,name:i,list:a,brand:c,category:u,variant:f,position:o(l),price:t(p),currency:m}})}))},e.addProduct=function(e,n){void 0===e&&(e={}),void 0===n&&(n=Object.keys(s));var r=e.id,i=e.name,a=e.list,c=e.brand,u=e.category,f=e.variant,l=e.price,p=e.quantity,m=e.coupon,h=e.position,y=e.currency;n.forEach((function(e){d[e]&&d[e].push({schema:"iglu:io.surfside.commerce/product/jsonschema/1-0-0",data:{id:r,name:i,list:a,brand:c,category:u,variant:f,price:t(l),quantity:o(p),coupon:m,position:o(h),currency:y}})}))},e.addPromotion=function(e,n){void 0===e&&(e={}),void 0===n&&(n=Object.keys(s));var o=e.id,t=e.name,r=e.creative,i=e.position,a=e.currency;n.forEach((function(e){d[e]&&d[e].push({schema:"iglu:io.surfside.commerce/promotion/jsonschema/1-0-0",data:{id:o,name:t,creative:r,position:i,currency:a}})}))},e.addTransaction=function(e,n){void 0===e&&(e={}),void 0===n&&(n=Object.keys(s));var r=e.id,i=e.affiliation,a=e.revenue,c=e.tax,u=e.shipping,f=e.coupon,l=e.list,p=e.step,m=e.option,h=e.currency;n.forEach((function(e){d[e]&&d[e].push({schema:"iglu:io.surfside.commerce/transaction/jsonschema/1-0-0",data:{id:r,affiliation:i,revenue:t(a),tax:t(c),shipping:t(u),coupon:f,list:l,step:o(p),option:m,currency:h}})}))},e.identifyUser=function(e,n){void 0===e&&(e={}),void 0===n&&(n=Object.keys(s));var o=e.id,t=e.address,r=e.age,i=e.company,a=e.createdAt,c=e.dateOfBirth,u=e.email,f=e.firstName,l=e.gender,p=e.userId,m=e.lastName,h=e.name,y=e.phone,v=e.title,g=e.username;n.forEach((function(e){d[e]&&d[e].push({schema:"iglu:io.surfside.identity/user/jsonschema/1-0-0",data:{id:o,address:t,age:r,company:i,createdAt:a,dateOfBirth:c,email:u,firstName:f,gender:l,userId:p,lastName:m,name:h,phone:y,title:v,username:g}})}))},e.segment=function(e,n){void 0===e&&(e={}),void 0===n&&(n=Object.keys(s));var o=e.segmentId,t=e.segmentVal;r(n,s,(function(e){d[e.id].length=0,e.core.addGlobalContexts([{schema:"iglu:io.surfside/segment/jsonschema/1-0-0",data:{segmentId:o,segmentVal:t}}])}))},e.setCommerceAction=function(e,n){void 0===e&&(e={}),void 0===n&&(n=Object.keys(s)),r(n,s,(function(n){var o=d[n.id].concat(e.context||[]);d[n.id].length=0;var t=(n=n.core).track,r={action:e},i=function(){var e,n={},o=[],t=[],r=function(e,o){null!=o&&""!==o&&(n[e]=o)};return{add:r,addDict:function(e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&r(n,e[n])},addJson:function(e,n,r){var i;if(i=r)e:{if(null!=r&&(r.constructor==={}.constructor||r.constructor===[].constructor))for(var a in r)if(Object.prototype.hasOwnProperty.call(r,a)){i=!0;break e}i=!1}i&&(e={keyIfEncoded:e,keyIfNotEncoded:n,json:r},t.push(e),o.push(e))},getPayload:function(){return n},getJson:function(){return o},withJsonProcessor:function(n){e=n},build:function(){return null==e||e(this,t),n}}}();r={schema:"iglu:com.snowplowanalytics.snowplow/unstruct_event/jsonschema/1-0-0",data:{schema:"iglu:io.surfside.commerce/action/jsonschema/1-0-0",data:r}},i.add("e","ue"),i.addJson("ue_px","ue_pr",r),t.call(n,i,o,e.timestamp)}))},e.setUser=function(e,n){void 0===e&&(e={}),void 0===n&&(n=Object.keys(s));var o=e.address,t=e.age,r=e.company,i=e.createdAt,a=e.dateOfBirth,c=e.email,u=e.firstName,f=e.gender,l=e.userId,p=e.lastName;n.forEach((function(e){d[e]&&d[e].push({schema:"iglu:io.surfside.identity/user/jsonschema/1-0-0",data:{address:o,age:t,company:r,createdAt:i,dateOfBirth:a,email:c,firstName:u,gender:f,userId:l,lastName:p}})}))},e.source=function(e,n){void 0===e&&(e={}),void 0===n&&(n=Object.keys(s));var o=e.accountId,t=e.sourceId;r(n,s,(function(e){d[e.id].length=0,e.core.addGlobalContexts([{schema:"iglu:io.surfside/context/jsonschema/1-0-0",data:{accountId:o,sourceId:t}}])}))},Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
7
|
+
//# sourceMappingURL=index.umd.min.js.map
|