Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.

Commit 6c58bc6

Browse files
authored
Merge pull request #5383 from negarn/negar/send_referrer
negar/send_referrer
2 parents 988a174 + d1df829 commit 6c58bc6

File tree

3 files changed

+35
-76
lines changed

3 files changed

+35
-76
lines changed

src/javascript/app_2/App/Components/Routes/route-with-sub-routes.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
Route } from 'react-router-dom';
55
import { redirectToLogin } from '_common/base/login';
66
import BinarySocket from '_common/base/socket_base';
7+
import Language from '_common/language';
78
import routes from 'Constants/routes';
89
import GTM from 'Utils/gtm';
910
import LoginPrompt from '../Elements/login-prompt.jsx';
@@ -30,6 +31,7 @@ const RouteWithSubRoutes = route => {
3031
);
3132
}
3233

34+
Language.setCookie();
3335
const title = route.title ? `${route.title} | ` : '';
3436
document.title = `${ title }${ default_title }`;
3537
BinarySocket.wait('website_status').then(() => {

src/root_files/app/index.html

Lines changed: 25 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
'de': 'de|at|li',
2727
'es': 'ar|bo|cl|co|cr|cu|do|ec|sv|gt|hn|mx|ni|pa|py|pr|es|uy|ve',
2828
'fr': 'fr|ad|bj|bf|cf|cg|ga|gn|ml|mc|ne|sn|tg',
29+
'id': 'id',
2930
'it': 'it',
3031
'ko': 'kr',
3132
'pl': 'po',
@@ -48,30 +49,13 @@
4849
var loginid = localStorage.getItem('active_loginid');
4950
var client_info = JSON.parse(localStorage.getItem('client.accounts') || '{}')[loginid];
5051
var is_logged_in = client_info && client_info['token'];
51-
window.location.href = (lang || 'en').toLowerCase() + '/' + (is_logged_in ? 'trading' : 'home') + '.html' + window.location.search;
52-
}
53-
function isDelayedRedirect() {
54-
if (isGtmApplicable() && !redirectTimeOut) {
55-
redirectTimeOut = setTimeout(redirect, 5000);
56-
} else {
57-
clearTimeout(redirectTimeOut);
58-
redirect();
59-
}
60-
}
61-
function isGtmApplicable() {
62-
return /(www|staging)\.binary\.(com|me)/i.test(window.location.hostname);
63-
}
64-
function pushEvent() {
65-
if (isGtmApplicable()) {
66-
dataLayer.push({
67-
'event': 'page_load',
68-
'eventCallback': function() {
69-
isDelayedRedirect();
70-
}
71-
});
72-
} else {
73-
isDelayedRedirect();
74-
}
52+
53+
var search = window.location.search ? window.location.search : '';
54+
var has_external_referrer = document.referrer && !/\.binary\.(com|me)/.test(document.referrer);
55+
var has_utm_source = /utm_source/.test(search);
56+
var utm_source = has_external_referrer && !has_utm_source ? ((search ? '&' : '?') + 'utm_source=' + new URL(document.referrer).hostname) : '';
57+
58+
window.location.href = (lang || 'en').toLowerCase() + '/' + (is_logged_in ? 'trading' : 'home') + '.html' + search + utm_source;
7559
}
7660

7761
if (/^https:\/\/staging\.binary\.com\/translations\//i.test(window.location.href)) {
@@ -81,32 +65,25 @@
8165
localStorage.setItem('index_referrer', document.referrer);
8266
}
8367
lang = getCookieItem('language');
84-
var ws = new WebSocket('wss://ws.binaryws.com/websockets/v3?app_id=1');
85-
ws.onopen = function(e) {
86-
ws.send(JSON.stringify({'website_status': '1'}));
87-
};
88-
ws.onmessage = function(msg) {
89-
var response = JSON.parse(msg.data);
90-
if (response.msg_type === 'website_status') {
91-
if (!lang && !response.error && response.hasOwnProperty('website_status')) {
92-
lang = getLanguage(response.website_status.clients_country);
68+
if (lang) {
69+
redirect();
70+
} else {
71+
var ws = new WebSocket('wss://ws.binaryws.com/websockets/v3?app_id=1');
72+
ws.onopen = function(e) {
73+
ws.send(JSON.stringify({'website_status': '1'}));
74+
};
75+
ws.onmessage = function(msg) {
76+
var response = JSON.parse(msg.data);
77+
if (response.msg_type === 'website_status') {
78+
if (!response.error && response.hasOwnProperty('website_status')) {
79+
lang = getLanguage(response.website_status.clients_country);
80+
}
81+
ws.close();
82+
redirect();
9383
}
94-
ws.close();
95-
pushEvent(); // we need website_status.clients_country
96-
}
97-
};
84+
};
85+
}
9886
}
9987
</script>
10088
</head>
101-
<body>
102-
<!-- Google Tag Manager -->
103-
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-MZWFF7"
104-
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
105-
<script data-cfasync="false">(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
106-
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
107-
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
108-
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
109-
})(window,document,'script','dataLayer','GTM-MZWFF7');</script>
110-
<!-- End Google Tag Manager -->
111-
</body>
11289
</html>

src/root_files/app_2/index.html

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
'de': 'de|at|li',
2626
'es': 'ar|bo|cl|co|cr|cu|do|ec|sv|gt|hn|mx|ni|pa|py|pr|es|uy|ve',
2727
'fr': 'fr|ad|bj|bf|cf|cg|ga|gn|ml|mc|ne|sn|tg',
28+
'id': 'id',
2829
'it': 'it',
2930
'ko': 'kr',
3031
'pl': 'po',
@@ -47,23 +48,14 @@
4748
var loginid = localStorage.getItem('active_loginid');
4849
var client_info = JSON.parse(localStorage.getItem('client.accounts') || '{}')[loginid];
4950
var is_logged_in = client_info && client_info['token'];
50-
window.location.href = (/\/app\//.test(window.location.pathname) ? '' : 'app/') + (lang || 'en').toLowerCase() + '/trade' + window.location.search;
51+
52+
var search = window.location.search ? window.location.search : '';
53+
var has_external_referrer = document.referrer && !/\.binary\.(com|me)/.test(document.referrer);
54+
var has_utm_source = /utm_source/.test(search);
55+
var utm_source = has_external_referrer && !has_utm_source ? ((search ? '&' : '?') + 'utm_source=' + new URL(document.referrer).hostname) : '';
56+
57+
window.location.href = (/\/app\//.test(window.location.pathname) ? '' : 'app/') + (lang || 'en').toLowerCase() + '/trade' + search + utm_source;
5158
}
52-
// function isGtmApplicable() {
53-
// return /(www|staging)\.binary\.(com|me)/i.test(window.location.hostname);
54-
// }
55-
// function pushEvent() {
56-
// if (isGtmApplicable()) {
57-
// dataLayer.push({
58-
// 'event': 'page_load',
59-
// 'eventCallback': function() {
60-
// redirect();
61-
// }
62-
// });
63-
// } else {
64-
// redirect();
65-
// }
66-
// }
6759

6860
if (document.referrer) {
6961
localStorage.setItem('index_referrer', document.referrer);
@@ -84,21 +76,9 @@
8476
}
8577
ws.close();
8678
redirect();
87-
// pushEvent(); // we need website_status.clients_country
8879
}
8980
};
9081
}
9182
</script>
9283
</head>
93-
<body>
94-
<!--&lt;!&ndash; Google Tag Manager &ndash;&gt;-->
95-
<!--<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-MZWFF7"-->
96-
<!--height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>-->
97-
<!--<script data-cfasync="false">(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':-->
98-
<!--new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],-->
99-
<!--j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=-->
100-
<!--'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);-->
101-
<!--})(window,document,'script','dataLayer','GTM-MZWFF7');</script>-->
102-
<!--&lt;!&ndash; End Google Tag Manager &ndash;&gt;-->
103-
</body>
10484
</html>

0 commit comments

Comments
 (0)