Skip to content

Commit ca82bf5

Browse files
committed
new version 1.0.20
1 parent a0074af commit ca82bf5

File tree

6 files changed

+156
-11
lines changed

6 files changed

+156
-11
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "breinify-api",
3-
"version": "1.0.19",
3+
"version": "1.0.20",
44
"description": "This is a JavaScript library simplifying the usage of the Breinify API",
55
"authors": [
66
"Philipp Meisen <philipp@breinify.com>",

dist/breinify-api.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* breinify-api
3-
* v1.0.19
3+
* v1.0.20
44
**/
55
/*
66
* We inject a dependencyScope variable, which will be used
@@ -12900,7 +12900,7 @@ dependencyScope.jQuery = $;;
1290012900
});
1290112901

1290212902
var BreinifyConfig = function (config) {
12903-
this.version = '1.0.19';
12903+
this.version = '1.0.20';
1290412904

1290512905
/*
1290612906
* Validate the passed config-parameters.
@@ -13091,7 +13091,7 @@ dependencyScope.jQuery = $;;
1309113091

1309213092
var BreinifyUser = function (user, onReady) {
1309313093
var instance = this;
13094-
instance.version = '1.0.19';
13094+
instance.version = '1.0.20';
1309513095

1309613096
// set the values provided
1309713097
instance.setAll(user);
@@ -13593,8 +13593,21 @@ dependencyScope.jQuery = $;;
1359313593
},
1359413594

1359513595
parseGetParameter: function (name, value) {
13596+
13597+
var base64;
13598+
if (typeof value !== 'string' || value === null) {
13599+
return null;
13600+
} else if (value.charAt(0) === '.') {
13601+
base64 = value.substr(1)
13602+
.replace('/~/g', '+')
13603+
.replace('/-/g', '/')
13604+
.replace('/_/g', '=');
13605+
} else {
13606+
base64 = decodeURIComponent(value);
13607+
}
13608+
1359613609
try {
13597-
return JSON.parse(atob(decodeURIComponent(value)));
13610+
return JSON.parse(atob(base64));
1359813611
} catch (e) {
1359913612
return null;
1360013613
}
@@ -13605,7 +13618,7 @@ dependencyScope.jQuery = $;;
1360513618
* The one and only instance of the library.
1360613619
*/
1360713620
var Breinify = {
13608-
version: '1.0.19',
13621+
version: '1.0.20',
1360913622
jQueryVersion: $.fn.jquery
1361013623
};
1361113624

dist/breinify-api.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

specs/Breinify-spec.js

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,123 @@ describe('Breinify', function () {
117117
done();
118118
});
119119
});
120+
121+
122+
//noinspection JSUnresolvedFunction
123+
it('handlesGetParameters', function () {
124+
var oldParams = Breinify.UTL.loc.params;
125+
var oldActivity = Breinify.activity;
126+
127+
var test = [];
128+
var value = {};
129+
130+
Breinify.activity = function (user, type, category, description, tags, sign, onReady) {
131+
132+
// create a unique new identifier for the test
133+
test.push(true);
134+
135+
// add the information
136+
value[test.length] = {
137+
user: user,
138+
type: type,
139+
category: category,
140+
description: description,
141+
tags: tags,
142+
sign: sign
143+
};
144+
};
145+
146+
// use some old configuration without any marker
147+
Breinify.UTL.loc.params = function (done) {
148+
return {
149+
'brec': 'eyJ1c2VyIjogeyJlbWFpbCI6ICJwaGlsaXBwQG1laXNlbi5uZXQiLCJ1c2VySWQiOiAiNDAyODAxOTMxNTQifSwiYWN0aXZpdHkiOiB7InRhZ3MiOiB7InByb2R1Y3RQcmljZXMiOiBbMzkuOTldLCJwcm9kdWN0SWRzIjogWyIyMTg2Il0sIndpZGdldElkIjogIm1heUxpa2UyIiwid2lkZ2V0VHlwZSI6ICJpbWFnZSIsImNhbXBhaWduSWQiOiAiYmV2bW9GcmlkYXlFbWFpbHwyMDE5LTA0LTEyIiwiY2FtcGFpZ25UeXBlIjogImJldm1vRnJpZGF5RW1haWwifX19'
150+
};
151+
};
152+
Breinify.setConfig({
153+
'apiKey': '5555-064C-F007-4F92-A8DC-D06B-56B4-FAD8',
154+
'category': 'other',
155+
'handleParameters': true
156+
});
157+
158+
// another old configuration without marker
159+
Breinify.UTL.loc.params = function (done) {
160+
return {
161+
'brec': 'eyJ1c2VyIjogeyJlbWFpbCI6ICJwaGlsaXBwQG1laXNlbi5uZXQiLCJ1c2VySWQiOiAiNDAyODAxOTMxNTQifSwiYWN0aXZpdHkiOiB7InRhZ3MiOiB7InByb2R1Y3RQcmljZXMiOiBbMjYuOTldLCJwcm9kdWN0SWRzIjogWyI1MTIwNCJdLCJ3aWRnZXRJZCI6ICJtYXlMaWtlNCIsIndpZGdldFR5cGUiOiAiaW1hZ2UiLCJjYW1wYWlnbklkIjogImJldm1vRnJpZGF5RW1haWx8MjAxOS0wNC0xMiIsImNhbXBhaWduVHlwZSI6ICJiZXZtb0ZyaWRheUVtYWlsIn19fQ%3D%3D'
162+
};
163+
};
164+
Breinify.setConfig({
165+
'apiKey': '5555-064C-F007-4F92-A8DC-D06B-56B4-FAD8',
166+
'category': 'other',
167+
'handleParameters': true
168+
});
169+
170+
// use some new configuration with the marker
171+
Breinify.UTL.loc.params = function (done) {
172+
return {
173+
'brec': '.eyJhY3Rpdml0eSI6eyJ0eXBlIjoiY2xpY2tlZFJlY29tbWVuZGF0aW9uIiwidGFncyI6eyJwcm9kdWN0SWRzIjpbIjU0MTIzIl19fSwidXNlciI6eyJlbWFpbCI6InBoaWxpcHBAYnJlaW5pZnkuY29tIn19'
174+
};
175+
};
176+
Breinify.setConfig({
177+
'apiKey': '5555-064C-F007-4F92-A8DC-D06B-56B4-FAD8',
178+
'category': 'other',
179+
'handleParameters': true
180+
});
181+
182+
// reset everything
183+
Breinify.UTL.loc.params = oldParams;
184+
Breinify.activity = oldActivity;
185+
186+
//noinspection JSUnresolvedFunction
187+
expect(value).toEqual({
188+
"1": {
189+
"user": {
190+
"email": "philipp@meisen.net",
191+
"userId": "40280193154"
192+
},
193+
"type": "clickedRecommendation",
194+
"category": null,
195+
"description": null,
196+
"tags": {
197+
"productPrices": [39.99],
198+
"productIds": ["2186"],
199+
"widgetId": "mayLike2",
200+
"widgetType": "image",
201+
"campaignId": "bevmoFridayEmail|2019-04-12",
202+
"campaignType": "bevmoFridayEmail"
203+
},
204+
"sign": null
205+
},
206+
"2": {
207+
"user": {
208+
"email": "philipp@meisen.net",
209+
"userId": "40280193154"
210+
},
211+
"type": "clickedRecommendation",
212+
"category": null,
213+
"description": null,
214+
"tags": {
215+
"productPrices": [26.99],
216+
"productIds": ["51204"],
217+
"widgetId": "mayLike4",
218+
"widgetType": "image",
219+
"campaignId": "bevmoFridayEmail|2019-04-12",
220+
"campaignType": "bevmoFridayEmail"
221+
},
222+
"sign": null
223+
},
224+
"3": {
225+
"user": {
226+
"email": "philipp@breinify.com"
227+
},
228+
"type": "clickedRecommendation",
229+
"category": null,
230+
"description": null,
231+
"tags": {
232+
"productIds": ["54123"]
233+
},
234+
"sign": null
235+
}
236+
});
237+
});
238+
120239
});

src/Breinify.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,21 @@
303303
},
304304

305305
parseGetParameter: function (name, value) {
306+
307+
var base64;
308+
if (typeof value !== 'string' || value === null) {
309+
return null;
310+
} else if (value.charAt(0) === '.') {
311+
base64 = value.substr(1)
312+
.replace('/~/g', '+')
313+
.replace('/-/g', '/')
314+
.replace('/_/g', '=');
315+
} else {
316+
base64 = decodeURIComponent(value);
317+
}
318+
306319
try {
307-
return JSON.parse(atob(decodeURIComponent(value)));
320+
return JSON.parse(atob(base64));
308321
} catch (e) {
309322
return null;
310323
}

0 commit comments

Comments
 (0)