@saasquatch/squatch-js 2.5.0-0 → 2.5.1-0

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/README.md CHANGED
@@ -1,144 +1,145 @@
1
- # Referral SaaSquatch Javascript SDK
2
-
3
- ## Install the library
4
-
5
- To integrate any SaaSquatch program to your website or web app, copy/paste this snippet of JavaScript above the `</head>` tag of your page:
6
-
7
- ```html
8
- <script type="text/javascript">
9
- !function(a,b){a("squatch","https://fast.ssqt.io/squatch-js@2",b)}(function(a,b,c){var d,e,f;c["_"+a]={},c[a]={},c[a].ready=function(b){c["_" + a].ready = c["_" + a].ready || [];c["_" + a].ready.push(b);},e=document.createElement("script"),e.async=1,e.src=b,f=document.getElementsByTagName("script")[0],f.parentNode.insertBefore(e,f)},this);
10
- </script>
11
- ```
12
-
13
- Or load the library synchronously from our CDN:
14
-
15
- ```html
16
- <script src="https://fast.ssqt.io/squatch-js@2" type="text/javascript"></script>
17
- ```
18
-
19
-
20
- ## Getting Started
21
- The `init` function lets you configure your global squatch instance.
22
-
23
- Note: `engagementMedium` is required in the `squatch.widgets()` functions if you want to load the widget. Otherwise, Squatch.js will look for your portal settings and render the widget that's mapped to the URL where this snippet is included.
24
-
25
- ```html
26
- <script type="text/javascript">
27
- squatch.ready(function() {
28
-
29
- // Always call init
30
- squatch.init({
31
- tenantAlias: "YOUR_TENANT_ALIAS", // String (required)
32
- });
33
-
34
- squatch.widgets().upsertUser({
35
- user: { // Object (required)
36
- id: 'USER_ID', // String (required)
37
- accountId: 'USER_ACCOUNT_ID', // String (required)
38
- email: 'USER_EMAIL', // String (optional)
39
- firstName: 'USER_FIRST_NAME', // String (optional)
40
- lastName: 'USER_LAST_NAME', // String (optional)
41
-
42
- ...
43
- },
44
- engagementMedium: 'EMBED', // String (optional: POPUP, EMBED)
45
- widgetType: 'p/PROGRAM-ID/w/referrerWidget', // Update PROGRAM-ID
46
- jwt: 'TOKEN' // String (required by default, or disable Security in the portal)
47
-
48
- });
49
- </script>
50
- ```
51
-
52
- ## Data Only Operations
53
- You can create/upsert users without loading a widget.
54
-
55
- ```html
56
- <script type="text/javascript">
57
- squatch.ready(function() {
58
-
59
- // Always call init
60
- squatch.init({
61
- tenantAlias: "YOUR_TENANT_ALIAS" // String (required)
62
- });
63
-
64
- var user;
65
-
66
- squatch.api().upsertUser({
67
- user: { // Object (required)
68
- id: 'USER_ID', // String (required)
69
- accountId: 'USER_ACCOUNT_ID', // String (required)
70
- email: 'USER_EMAIL', // String (optional)
71
- firstName: 'USER_FIRST_NAME', // String (optional)
72
- lastName: 'USER_LAST_NAME', // String (optional)
73
- ...
74
- },
75
- engagementMedium: 'EMBED', // String (optional: POPUP, EMBED)
76
- widgetType: 'p/PROGRAM-ID/w/referrerWidget', // Update PROGRAM-ID
77
- jwt: 'TOKEN' // String (required)
78
- }).then(function(response) {
79
- user = response.user;
80
- }).catch(function(err){
81
- console.log(err);
82
- });
83
-
84
- // autofill
85
- var element = document.getElementById('my_coupon');
86
- element.value = user.referredBy.code;
87
-
88
- });
89
- </script>
90
- ```
91
-
92
- ## Get Referral Cookie Code
93
- You can also use the `api()` function to call the WidgetApi methods directly.
94
-
95
- ```html
96
- <script type="text/javascript">
97
- squatch.ready(function(){
98
-
99
- // Always call init
100
- squatch.init({tenantAlias: 'YOUR_TENANT_ALIAS'});
101
-
102
-
103
- var element = document.getElementById('my_coupon');
104
-
105
- squatch.api().squatchReferralCookie().then(function(response) {
106
- /* `response.codes` looks like `{"program_id":"NEWCO", "friend_program":"BOB"}` */
107
-
108
- element.value = response.codes["program-id"];
109
- });
110
-
111
- });
112
- </script>
113
- ```
114
-
115
- Want more control? Visit our [guide](https://github.com/saasquatch/squatch-js/blob/master/docs/docs.md).
116
-
117
-
118
- ## Install via NPM and Webpack (advanced)
119
-
120
- Squatch.js can also be installed via NPM and bundled into your application with Webpack.
121
-
122
- ```ssh
123
- # via npm
124
- $ npm install @saasquatch/squatch-js
125
- ```
126
-
127
- ```js
128
- import * as squatch from "@saasquatch/squatch-js";
129
-
130
- // Always call init
131
- squatch.init({
132
- tenantAlias: "YOUR_TENANT_ALIAS" // String (required)
133
- });
134
-
135
- // Don't need to wait for .ready when importing via NPM/Webpack
136
- squatch.api().upsertUser({...});
137
-
138
- ```
139
-
140
- ## Contributing
141
- This is an open source project! If you are interested in contributing please look at [contributing guidelines](CONTRIBUTING.md) first.
142
-
143
- ## Support
144
- Shoot us an email at [support@saasqt.ch](mailto:support@saasqt.ch) if you need help!
1
+ # Referral SaaSquatch Javascript SDK
2
+
3
+ ## Install the library
4
+
5
+ To integrate any SaaSquatch program to your website or web app, copy/paste this snippet of JavaScript above the `</head>` tag of your page:
6
+
7
+ ```html
8
+ <script type="text/javascript">
9
+ !function(a,b){a("squatch","https://fast.ssqt.io/squatch-js@2",b)}(function(a,b,c){var d,e,f;c["_"+a]={},c[a]={},c[a].ready=function(b){c["_" + a].ready = c["_" + a].ready || [];c["_" + a].ready.push(b);},e=document.createElement("script"),e.async=1,e.src=b,f=document.getElementsByTagName("script")[0],f.parentNode.insertBefore(e,f)},this);
10
+ </script>
11
+ ```
12
+
13
+ Or load the library synchronously from our CDN:
14
+
15
+ ```html
16
+ <script src="https://fast.ssqt.io/squatch-js@2" type="text/javascript"></script>
17
+ ```
18
+
19
+
20
+ ## Getting Started
21
+ The `init` function lets you configure your global squatch instance.
22
+
23
+ Note: `engagementMedium` is required in the `squatch.widgets()` functions if you want to load the widget. Otherwise, Squatch.js will look for your portal settings and render the widget that's mapped to the URL where this snippet is included.
24
+
25
+ ```html
26
+ <script type="text/javascript">
27
+ squatch.ready(function() {
28
+
29
+ // Always call init
30
+ squatch.init({
31
+ tenantAlias: "YOUR_TENANT_ALIAS", // String (required)
32
+ });
33
+
34
+ squatch.widgets().upsertUser({
35
+ user: { // Object (required)
36
+ id: 'USER_ID', // String (required)
37
+ accountId: 'USER_ACCOUNT_ID', // String (required)
38
+ email: 'USER_EMAIL', // String (optional)
39
+ firstName: 'USER_FIRST_NAME', // String (optional)
40
+ lastName: 'USER_LAST_NAME', // String (optional)
41
+
42
+ ...
43
+ },
44
+ engagementMedium: 'EMBED', // String (optional: POPUP, EMBED)
45
+ widgetType: 'p/PROGRAM-ID/w/referrerWidget', // Update PROGRAM-ID
46
+ jwt: 'TOKEN' // String (required by default, or disable Security in the portal)
47
+
48
+ });
49
+ });
50
+ </script>
51
+ ```
52
+
53
+ ## Data Only Operations
54
+ You can create/upsert users without loading a widget.
55
+
56
+ ```html
57
+ <script type="text/javascript">
58
+ squatch.ready(function() {
59
+
60
+ // Always call init
61
+ squatch.init({
62
+ tenantAlias: "YOUR_TENANT_ALIAS" // String (required)
63
+ });
64
+
65
+ var user;
66
+
67
+ squatch.api().upsertUser({
68
+ user: { // Object (required)
69
+ id: 'USER_ID', // String (required)
70
+ accountId: 'USER_ACCOUNT_ID', // String (required)
71
+ email: 'USER_EMAIL', // String (optional)
72
+ firstName: 'USER_FIRST_NAME', // String (optional)
73
+ lastName: 'USER_LAST_NAME', // String (optional)
74
+ ...
75
+ },
76
+ engagementMedium: 'EMBED', // String (optional: POPUP, EMBED)
77
+ widgetType: 'p/PROGRAM-ID/w/referrerWidget', // Update PROGRAM-ID
78
+ jwt: 'TOKEN' // String (required)
79
+ }).then(function(response) {
80
+ user = response.user;
81
+ }).catch(function(err){
82
+ console.log(err);
83
+ });
84
+
85
+ // autofill
86
+ var element = document.getElementById('my_coupon');
87
+ element.value = user.referredBy.code;
88
+
89
+ });
90
+ </script>
91
+ ```
92
+
93
+ ## Get Referral Cookie Code
94
+ You can also use the `api()` function to call the WidgetApi methods directly.
95
+
96
+ ```html
97
+ <script type="text/javascript">
98
+ squatch.ready(function(){
99
+
100
+ // Always call init
101
+ squatch.init({tenantAlias: 'YOUR_TENANT_ALIAS'});
102
+
103
+
104
+ var element = document.getElementById('my_coupon');
105
+
106
+ squatch.api().squatchReferralCookie().then(function(response) {
107
+ /* `response.codes` looks like `{"program_id":"NEWCO", "friend_program":"BOB"}` */
108
+
109
+ element.value = response.codes["program-id"];
110
+ });
111
+
112
+ });
113
+ </script>
114
+ ```
115
+
116
+ Want more control? Visit our [guide](https://github.com/saasquatch/squatch-js/blob/master/docs/docs.md).
117
+
118
+
119
+ ## Install via NPM and Webpack (advanced)
120
+
121
+ Squatch.js can also be installed via NPM and bundled into your application with Webpack.
122
+
123
+ ```ssh
124
+ # via npm
125
+ $ npm install @saasquatch/squatch-js
126
+ ```
127
+
128
+ ```js
129
+ import * as squatch from "@saasquatch/squatch-js";
130
+
131
+ // Always call init
132
+ squatch.init({
133
+ tenantAlias: "YOUR_TENANT_ALIAS" // String (required)
134
+ });
135
+
136
+ // Don't need to wait for .ready when importing via NPM/Webpack
137
+ squatch.api().upsertUser({...});
138
+
139
+ ```
140
+
141
+ ## Contributing
142
+ This is an open source project! If you are interested in contributing please look at [contributing guidelines](CONTRIBUTING.md) first.
143
+
144
+ ## Support
145
+ Shoot us an email at [support@saasqt.ch](mailto:support@saasqt.ch) if you need help!
package/demo/sandbox.ts CHANGED
@@ -1,122 +1,124 @@
1
- import { getQueryStringParams } from "./util";
2
-
3
- export const tenantAlias = "test_aojsrf4r06zi0";
4
- export const domain = "https://staging.referralsaasquatch.com";
5
- export const script = "https://fast.ssqt.io/squatch-js@2";
6
-
7
- export const user = {
8
- id: "5b980d34e4b0cabee07f2cb0",
9
- accountId: "AZJZSVG0LS1LB19R",
10
- email: "chesterscott.uexwltgh@mailosaur.io",
11
- };
12
- export const badJwtUser = {
13
- ...user,
14
- firstName: "Bad JWT",
15
- };
16
- export const noIds = {
17
- firstName: "No IDs",
18
- };
19
- export const noUserId = {
20
- accountId: "abc_123",
21
- firstName: "No UserID",
22
- };
23
- export const noAccountId = {
24
- id: "abc_123",
25
- firstName: "No AccountID",
26
- };
27
-
28
- export const users = [user, badJwtUser, noIds, noUserId, noAccountId, {}];
29
-
30
- export const popup: Sandbox = {
31
- script,
32
- domain,
33
- tenantAlias,
34
- debug: true,
35
- initObj: {
36
- widgetType: "REFERRER_WIDGET",
37
- engagementMedium: "POPUP",
38
- user: user,
39
- jwt:
40
- "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkIjoiNWI5ODBkMzRlNGIwY2FiZWUwN2YyY2IwIiwiYWNjb3VudElkIjoiQVpKWlNWRzBMUzFMQjE5UiIsImVtYWlsIjoiY2hlc3RlcnNjb3R0LnVleHdsdGdoQG1haWxvc2F1ci5pbyJ9fQ.MkrO7-980M7NRJcOUcdqCO1JftqmynLMK8bTEB3WObo",
41
- },
42
- };
43
-
44
- export const embed: Sandbox = {
45
- script,
46
- domain,
47
- tenantAlias,
48
- initObj: {
49
- widgetType: "REFERRER_WIDGET",
50
- engagementMedium: "EMBED",
51
- user: {
52
- id: "5b980d34e4b0cabee07f2cb0",
53
- accountId: "AZJZSVG0LS1LB19R",
54
- email: "chesterscott.uexwltgh@mailosaur.io",
55
- },
56
- jwt:
57
- "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkIjoiNWI5ODBkMzRlNGIwY2FiZWUwN2YyY2IwIiwiYWNjb3VudElkIjoiQVpKWlNWRzBMUzFMQjE5UiIsImVtYWlsIjoiY2hlc3RlcnNjb3R0LnVleHdsdGdoQG1haWxvc2F1ci5pbyJ9fQ.MkrO7-980M7NRJcOUcdqCO1JftqmynLMK8bTEB3WObo",
58
- },
59
- };
60
-
61
- export const embedNew: Sandbox = {
62
- ...embed,
63
- initObj: {
64
- ...embed.initObj,
65
- widgetType: "p/tuesday-text/w/referrerWidget",
66
- },
67
- };
68
-
69
- export const embedReferred: Sandbox = {
70
- ...embed,
71
- initObj: {
72
- ...embed.initObj,
73
- widgetType: "CONVERSION_WIDGET",
74
- },
75
- };
76
-
77
- export const popupReferred: Sandbox = {
78
- ...popup,
79
- initObj: {
80
- ...popup.initObj,
81
- widgetType: "CONVERSION_WIDGET",
82
- },
83
- };
84
-
85
- export const popupNew: Sandbox = {
86
- ...popup,
87
- initObj: {
88
- ...popup.initObj,
89
- widgetType: "p/tuesday-test/w/referrerWidget",
90
- },
91
- };
92
-
93
- export function fromURL() {
94
- let urlSandbox;
95
- try {
96
- urlSandbox = JSON.parse(
97
- window.atob(getQueryStringParams(window.location.search).sandbox)
98
- );
99
- } catch (e) {
100
- urlSandbox = {};
101
- }
102
-
103
- const sandbox = {
104
- ...popup,
105
- ...urlSandbox,
106
- };
107
- return sandbox;
108
- }
109
-
110
- export function toURL(sandbox: Sandbox) {
111
- window.location.href = href(sandbox);
112
- }
113
-
114
- export function href(sandbox: Sandbox) {
115
- const param = window.btoa(JSON.stringify(sandbox));
116
- var url = window.location.href;
117
- if (url.indexOf("?") > 0) {
118
- url = url.substring(0, url.indexOf("?"));
119
- }
120
- url += `?sandbox=${encodeURIComponent(param)}`;
121
- return url;
122
- }
1
+ import { getQueryStringParams } from "./util";
2
+
3
+ export const tenantAlias = "test_aojsrf4r06zi0";
4
+ export const domain = "https://staging.referralsaasquatch.com";
5
+ export const script = "https://fast.ssqt.io/squatch-js@2";
6
+
7
+ export const user = {
8
+ id: "5b980d34e4b0cabee07f2cb0",
9
+ accountId: "AZJZSVG0LS1LB19R",
10
+ email: "chesterscott.uexwltgh@mailosaur.io",
11
+ };
12
+ export const badJwtUser = {
13
+ ...user,
14
+ firstName: "Bad JWT",
15
+ };
16
+ export const noIds = {
17
+ firstName: "No IDs",
18
+ };
19
+ export const noUserId = {
20
+ accountId: "abc_123",
21
+ firstName: "No UserID",
22
+ };
23
+ export const noAccountId = {
24
+ id: "abc_123",
25
+ firstName: "No AccountID",
26
+ };
27
+
28
+ export const users = [user, badJwtUser, noIds, noUserId, noAccountId, {}];
29
+
30
+ export const popup: Sandbox = {
31
+ script,
32
+ domain,
33
+ tenantAlias,
34
+ debug: true,
35
+ initObj: {
36
+ widgetType: "REFERRER_WIDGET",
37
+ engagementMedium: "POPUP",
38
+ user: user,
39
+ jwt: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkIjoiNWI5ODBkMzRlNGIwY2FiZWUwN2YyY2IwIiwiYWNjb3VudElkIjoiQVpKWlNWRzBMUzFMQjE5UiIsImVtYWlsIjoiY2hlc3RlcnNjb3R0LnVleHdsdGdoQG1haWxvc2F1ci5pbyJ9fQ.MkrO7-980M7NRJcOUcdqCO1JftqmynLMK8bTEB3WObo",
40
+ },
41
+ };
42
+
43
+ export const embed: Sandbox = {
44
+ script,
45
+ domain,
46
+ tenantAlias,
47
+ initObj: {
48
+ widgetType: "REFERRER_WIDGET",
49
+ engagementMedium: "EMBED",
50
+ user: {
51
+ id: "5b980d34e4b0cabee07f2cb0",
52
+ accountId: "AZJZSVG0LS1LB19R",
53
+ email: "chesterscott.uexwltgh@mailosaur.io",
54
+ },
55
+ jwt: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkIjoiNWI5ODBkMzRlNGIwY2FiZWUwN2YyY2IwIiwiYWNjb3VudElkIjoiQVpKWlNWRzBMUzFMQjE5UiIsImVtYWlsIjoiY2hlc3RlcnNjb3R0LnVleHdsdGdoQG1haWxvc2F1ci5pbyJ9fQ.MkrO7-980M7NRJcOUcdqCO1JftqmynLMK8bTEB3WObo",
56
+ },
57
+ };
58
+
59
+ export const embedNew: Sandbox = {
60
+ ...embed,
61
+ initObj: {
62
+ ...embed.initObj,
63
+ widgetType: "p/tuesday-text/w/referrerWidget",
64
+ },
65
+ };
66
+
67
+ export const embedReferred: Sandbox = {
68
+ ...embed,
69
+ initObj: {
70
+ ...embed.initObj,
71
+ widgetType: "CONVERSION_WIDGET",
72
+ },
73
+ };
74
+
75
+ export const popupReferred: Sandbox = {
76
+ ...popup,
77
+ initObj: {
78
+ ...popup.initObj,
79
+ widgetType: "CONVERSION_WIDGET",
80
+ },
81
+ };
82
+
83
+ export const popupNew: Sandbox = {
84
+ ...popup,
85
+ initObj: {
86
+ ...popup.initObj,
87
+ widgetType: "p/tuesday-test/w/referrerWidget",
88
+ },
89
+ };
90
+
91
+ export function fromURL() {
92
+ let urlSandbox;
93
+ try {
94
+ urlSandbox = JSON.parse(
95
+ window.atob(getQueryStringParams(window.location.search).sandbox)
96
+ );
97
+ } catch (e) {
98
+ urlSandbox = {};
99
+ }
100
+
101
+ const sandbox = {
102
+ ...popup,
103
+ ...urlSandbox,
104
+ };
105
+ return sandbox;
106
+ }
107
+
108
+ export function toURL(sandbox: Sandbox) {
109
+ window.location.href = href(sandbox);
110
+ }
111
+
112
+ export function href(sandbox: Sandbox) {
113
+ const urlParams = new URLSearchParams(window.location.search);
114
+ const param = window.btoa(JSON.stringify(sandbox));
115
+ var url = window.location.href;
116
+ if (url.indexOf("?") > 0) {
117
+ url = url.substring(0, url.indexOf("?"));
118
+ }
119
+
120
+ urlParams.delete("sandbox");
121
+
122
+ url += `?sandbox=${encodeURIComponent(param)}&${urlParams.toString()}`;
123
+ return url;
124
+ }