-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathus-functions.v1.6.3.js
286 lines (237 loc) · 10.1 KB
/
us-functions.v1.6.3.js
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
function isCookieSizeExceeded(){
let c_size = 15;
var h_cookie = read_cookie("v_history");
if (h_cookie == null) return;
if(h_cookie.length >= c_size){
h_cookie.shift();
bake_cookie("v_history", h_cookie);
}
}
function isDuplicateCookie(utm_params, recent_visit){
if((utm_params['utm_source'] == recent_visit['utm_source']) &&
(utm_params['utm_medium'] == recent_visit['utm_medium']) &&
(utm_params['utm_campaign'] == recent_visit['utm_campaign']) &&
(utm_params['utm_adset'] == recent_visit['utm_adset']) &&
(utm_params['utm_content'] == recent_visit['utm_content']) &&
(utm_params['utm_term'] == recent_visit['utm_term']) &&
(utm_params['fbclid'] == recent_visit['fbclid']))
{
return true;
}
else{return false;}
}
function bake_cookie_history(name, value) {
isCookieSizeExceeded();
var visits_history = [];
var iksutmhistory = read_cookie(name);
var utmstring = value;
utmstring.timestamp = $.now();
utmstring.ip = v_ip;
utmstring.region = v_region;
utmstring.landing_page = window.location.pathname;
utmstring.userAgent = encodeURIComponent(navigator.userAgent);
utmstring.city = v_city;
utmstring.device = getDeviceType();
utmstring.visitor_id = visitor_id;
utmstring.referrer = referrer;
value = utmstring;
if(iksutmhistory == "" || iksutmhistory == null){
visits_history.push(utmstring);
var cookie = [name, '=', JSON.stringify(visits_history), ';expires','=', expdate.toGMTString(), '; domain=.', window.location.host.toString(), '; path=/;'].join('');
document.cookie = cookie;
}
else
{
var result = document.cookie.match(new RegExp(name + '=([^;]+)'));
result && (result = JSON.parse(result[1]));
var newhistoryobj = result.push(value);
var cookie = [name, '=', JSON.stringify(result), ';expires','=', expdate.toGMTString(), '; domain=.', window.location.host.toString(), '; path=/;'].join('');
document.cookie = cookie;
}
}
function bake_organic_cookie(){
var organicobj = {
"utm_source":"",
"utm_medium":"",
"utm_campaign":"",
"utm_adset":"",
"utm_content":"",
"utm_term":"",
"timestamp":$.now(),
"ip": v_ip,
"region": v_region,
"landing_page": window.location.pathname,
"userAgent": encodeURIComponent(navigator.userAgent),
"city": v_city,
"device": getDeviceType(),
"visitor_id": visitor_id,
"referrer": referrer
};
if(referrer == null || referrer.indexOf(window.location.host.toString()) == -1){
bake_cookie_history("v_history", organicobj);
bake_cookie("v_latest", organicobj);
}
}
function bake_cookie(name, value) {
var utmstring = value;
utmstring.timestamp = $.now();
utmstring.ip = v_ip;
utmstring.region = v_region;
utmstring.landing_page = window.location.pathname;
utmstring.userAgent = encodeURIComponent(navigator.userAgent);
utmstring.city = v_city;
utmstring.device = getDeviceType();
utmstring.visitor_id = visitor_id;
utmstring.referrer = referrer;
var cookie = [name, '=', JSON.stringify(utmstring), ';expires','=', expdate.toGMTString(),'; domain=.', window.location.host.toString(), '; path=/;'].join('');
document.cookie = cookie;
}
function read_cookie(name) {
var result = document.cookie.match(new RegExp(name + '=([^;]+)'));
result && (result = JSON.parse(result[1]));
return result;
}
function setCookie(cname, cvalue) {
var d = new Date();
d.setTime(d.getTime() + (365*24*60*60*1000));
var expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function showCalendly(cv){
var curl = generateCalendlyLink("calendly",cv)+"&hide_event_type_details=1";
Calendly.initPopupWidget({
url: curl
});
}
$('.request-info-close').click(function(e){
$('.request-info-wrap').css("display","none");
$('.request-info-wrap').css("opacity",0);
});
function generateCalendlyLink(platform,cv){
var calendlyurl;
if(platform == "hubspot"){
calendlyurl = "https://meetings.hubspot.com/ik/admissions?embed=true&";
}else{
if(cv == "v2"){
calendlyurl = "https://calendly.com/team-ik/how-to-nail-your-next-interview-dsw?";
}else{
calendlyurl = "https://calendly.com/interviewkickstart/enrollment-workshop?";
}
}
var active_visit = read_cookie("v_latest");
var visit_history = read_cookie("v_history");
var gaid = getCookie("_ga");
visitor_id = visitor_id + gaid;
var utm_medium_str = "utm_medium=";
for (const property in active_visit) {
if (`${property}` == "utm_medium") {
utm_medium_str = utm_medium_str + `${active_visit[property]}`;
}
}
utm_medium_str = utm_medium_str + ":";
for (const property in active_visit) {
if (`${property}` == "gclid") {
utm_medium_str = utm_medium_str + "gclid:" + `${active_visit[property]}`;
} else if (`${property}` == "msclkid") {
utm_medium_str = utm_medium_str + "msclkid:" + `${active_visit[property]}`;
} else if (`${property}` == "fbclid") {
utm_medium_str = utm_medium_str + "fbclid:" + `${active_visit[property]}`;
}
}
if ( (utm_medium_str.indexOf("gclid") == -1) && (utm_medium_str.indexOf("msclkid") == -1) && (utm_medium_str.indexOf("fbclid") == -1)){
utm_medium_str = utm_medium_str + ":";
}
utm_medium_str = utm_medium_str + ":" + visitor_id;
utm_medium_str = utm_medium_str + ":" + v_country;
for (const property in active_visit) {
var ptyn = `${active_visit[property]}`;
if((`${property}` != "utm_medium") && (`${property}` != "msclkid") && (`${property}` != "fbclid") && (`${property}` != "gclid") ){
calendlyurl = calendlyurl+`${property}`+"="+`${active_visit[property]}`+"&";
}
}
utm_medium_str = utm_medium_str + "&salesforce_uuid="+v_timezone +":ik.com"+cta_lp+":ik.com"+getCookie("ik-landingpage-v2");
calendlyurl = calendlyurl + utm_medium_str;
return calendlyurl;
}
function setHiddenFields(){
let params = read_cookie("v_latest");
let fUSWFlag = getAllUrlParams();
if(fUSWFlag['forceuswebinar'] == "true"){
$('.v_country').val("United States");
$('.user_timezone').val("US/Pacific");
v_timezone = "US/Pacific";
v_country = "United States";
}else{
$('.v_country').val(v_country);
$('.user_timezone').val(v_timezone);
}
$('.utm_source').val(decodeURIComponent((params?.utm_source != undefined) ? params['utm_source'] : "Organic"));
$('.utm_medium').val(decodeURIComponent((params?.utm_medium != undefined) ? params['utm_medium'] : ""));
$('.utm_campaign').val(decodeURIComponent((params?.utm_campaign != undefined) ? params['utm_campaign'] : ""));
$('.utm_adset').val(decodeURIComponent((params?.utm_adset != undefined) ? params['utm_adset'] : ""));
$('.utm_content').val(decodeURIComponent((params?.utm_content != undefined) ? params['utm_content'] : ""));
$('.utm_term').val(decodeURIComponent((params?.utm_term != undefined) ? params['utm_term'] : ""));
$('.page_url').val(window.location.href);
$('.webinar-type').val(((webinarType == undefined) || (webinarType == "REGULAR")) ? "REGULAR" : "SWITCH_UP");
$('.user_id').val(visitor_id);
$('.gclid').val(decodeURIComponent((params?.gclid != undefined) ? params['gclid'] : ""));
$('.salesforce_uuid').val(decodeURIComponent((params?.salesforce_uuid != undefined) ? params['salesforce_uuid'] : ""));
$('.msclkid').val(decodeURIComponent((params?.msclkid != undefined) ? params['msclkid'] : ""));
$('.fbclid').val(decodeURIComponent((params?.fbclid != undefined) ? params['fbclid'] : ""));
$(".landing_page").val("ik.com"+getCookie("ik-landingpage-v2"));
$(".cta_page_url").val("ik.com"+cta_lp),
$(".l_page_url").val("ik.com"+getCookie("ik-landingpage-v2"));
$('.var_localtimezone').text(utz == undefined ? "US/Pacific" : utz);
$('.wr__referrer').val(referrer);
$('.wr__device').val(getDeviceType());
}
function getDeviceType() {
var userAgent = navigator.userAgent;
if (/mobile/i.test(userAgent)) {
return 'Mobile';
} else if (/iPad|Android|Touch/i.test(userAgent)) {
return 'Tablet';
} else {
return 'Desktop';
}
}
function calendlySignup(isthisForm,formstr) {
$('.loading-overlay').css('display', 'flex');
let calendlyurl = generateCalendlyLink();
var visit_history = read_cookie("v_history");
if(isthisForm){
calendlyurl = calendlyurl + formstr;
}
let page_url = window.location.pathname;
var jsonData = {"unique_visitor_id": visitor_id.toString().replace(/"/g, ""), "device_name": "", "page_url": page_url, "visitor_city": v_city, "click_history":JSON.stringify(visit_history)};
$.ajax({
type: "POST",
url: "https://hooks.zapier.com/hooks/catch/9555768/ong6g6o/",
data: jsonData,
success: function (e) {
if(e.status == "success"){
bake_cookie("v_history","");
bake_cookie("v_latest","");
}
setCookie("ik-landingpage","");
setTimeout(function(){
location.href = calendlyurl;
$('.loading-overlay').css('display', 'none');
}, 100);
}
});
}