-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBBjPendo.bbj
89 lines (63 loc) · 2.3 KB
/
BBjPendo.bbj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use ::WebKit/util/ClientUtil.bbj::ClientUtil
use java.util.HashMap
use com.google.gson.Gson
class public BBjPendo
field private HashMap userInfo! = new HashMap()
field private HashMap accountInfo! = new HashMap()
field private BBjString apiKey!
method public BBjPendo()
methodend
method public void setApiKey(BBjString apiKey!)
if apiKey! = null() or apiKey! = "" then throw "Key can't be null or empty",785
#apiKey! = apiKey!
methodend
method private BBjString buildPendoInitScript()
declare BBjString script!
declare Gson gson!
gson! = new Gson()
script! = "pendo.initialize({ visitor: "
json! = gson!.toJson(#userInfo!)
script! = script! + json! + ","
script! = script! + " account: "
json! = gson!.toJson(#accountInfo!)
script! = script! + json! + "});"
methodret script!
methodend
method public void initPendo()
declare BBjString script!
declare BBjString pendo!
if #apiKey! = null() or #apiKey!.isEmpty() then throw "No ApiKey found", 404
pendo! = #readFile("BBjPendo/pendoScript.js")
pendo! = pendo! + "('"+ #apiKey! +"');"
script! = pendo!
script! = script! + #buildPendoInitScript()
ClientUtil.executeJavascript(script!)
methodend
method public void setUserInformation(BBjString visitorId$)
#userInfo!.put("id",visitorId$)
methodend
method public void setAccountInformation(BBjString accountId$)
#accountInfo!.put("id", accountId$)
methodend
method public void setCustomAccountInfo(BBjString key!, Object value!)
#accountInfo!.put(key!,value!)
methodend
method public void setCustomUserInfo(BBjString key!, Object value!)
#userInfo!.put(key!,value!)
methodend
rem /**
rem * Read the content of the given file as a String.
rem *
rem * @param file! The file's path
rem *
rem * @return The file's content
rem */
method protected BBjString readFile(BBjString file$)
content$ = ""
ch=unt
open (ch)file$
read record (ch,siz=5512000)content$
close (ch)
methodret content$
methodend
classend