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

Commit 3707414

Browse files
committed
pass in url and remove gtm
1 parent 626a8fd commit 3707414

File tree

4 files changed

+28
-74
lines changed

4 files changed

+28
-74
lines changed

src/javascript/app/base/binary_loader.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const localize = require('../../_common/localize').localize;
1515
const ScrollToAnchor = require('../../_common/scroll_to_anchor');
1616
const isStorageSupported = require('../../_common/storage').isStorageSupported;
1717
const ThirdPartyLinks = require('../../_common/third_party_links');
18-
const urlFor = require('../../_common/url').urlFor;
18+
const Url = require('../../_common/url');
1919
const createElement = require('../../_common/utility').createElement;
2020

2121
const BinaryLoader = (() => {
@@ -74,7 +74,8 @@ const BinaryLoader = (() => {
7474
ContentVisibility.init();
7575

7676
BinarySocket.wait('authorize', 'website_status', 'landing_company').then(() => {
77-
GTM.pushDataLayer({ event: 'page_load' }); // we need website_status.clients_country
77+
const url_params = Url.paramsHash().referrer;
78+
GTM.pushDataLayer({ event: 'page_load', ...(url_params && { referrer: url_params }) }); // we need website_status.clients_country
7879

7980
// first time load.
8081
const last_image = $('#content img').last();
@@ -92,7 +93,7 @@ const BinaryLoader = (() => {
9293
};
9394

9495
const error_messages = {
95-
login : () => localize('Please [_1]log in[_2] or [_3]sign up[_4] to view this page.', [`<a href="${'javascript:;'}">`, '</a>', `<a href="${urlFor('new-account')}">`, '</a>']),
96+
login : () => localize('Please [_1]log in[_2] or [_3]sign up[_4] to view this page.', [`<a href="${'javascript:;'}">`, '</a>', `<a href="${Url.urlFor('new-account')}">`, '</a>']),
9697
only_virtual : () => localize('Sorry, this feature is available to virtual accounts only.'),
9798
only_real : () => localize('This feature is not relevant to virtual-money accounts.'),
9899
not_authenticated: () => localize('This page is only available to logged out clients.'),

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

Lines changed: 3 additions & 1 deletion
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 Url from '_common/url';
78
import routes from 'Constants/routes';
89
import GTM from 'Utils/gtm';
910
import LoginPrompt from '../Elements/login-prompt.jsx';
@@ -33,7 +34,8 @@ const RouteWithSubRoutes = route => {
3334
const title = route.title ? `${route.title} | ` : '';
3435
document.title = `${ title }${ default_title }`;
3536
BinarySocket.wait('website_status').then(() => {
36-
GTM.pushDataLayer({ event: 'page_load' });
37+
const url_params = Url.paramsHash().referrer;
38+
GTM.pushDataLayer({ event: 'page_load', ...(url_params && { referrer: url_params }) });
3739
});
3840
return result;
3941
};

src/root_files/app/index.html

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,8 @@
4848
var loginid = localStorage.getItem('active_loginid');
4949
var client_info = JSON.parse(localStorage.getItem('client.accounts') || '{}')[loginid];
5050
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 isGtmApplicable() {
54-
return /(www|staging)\.binary\.(com|me)/i.test(window.location.hostname);
55-
}
56-
function pushEvent() {
57-
if (isGtmApplicable()) {
58-
dataLayer.push({
59-
'event': 'page_load',
60-
'eventCallback': function() {
61-
redirect();
62-
},
63-
'referrer': document.referrer
64-
});
65-
} else {
66-
redirect();
67-
}
51+
var search = (window.location.search ? window.location.search : '') + (document.referrer ? ('?referrer=' + document.referrer) : '');
52+
window.location.href = (lang || 'en').toLowerCase() + '/' + (is_logged_in ? 'trading' : 'home') + '.html' + search;
6853
}
6954

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

src/root_files/app_2/index.html

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,8 @@
4747
var loginid = localStorage.getItem('active_loginid');
4848
var client_info = JSON.parse(localStorage.getItem('client.accounts') || '{}')[loginid];
4949
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-
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-
'referrer': document.referrer
63-
});
64-
} else {
65-
redirect();
66-
}
50+
var search = (window.location.search ? window.location.search : '') + (document.referrer ? ('?referrer=' + document.referrer) : '');
51+
window.location.href = (/\/app\//.test(window.location.pathname) ? '' : 'app/') + (lang || 'en').toLowerCase() + '/trade' + search;
6752
}
6853

6954
if (document.referrer) {
@@ -85,21 +70,9 @@
8570
}
8671
ws.close();
8772
redirect();
88-
pushEvent(); // we need website_status.clients_country
8973
}
9074
};
9175
}
9276
</script>
9377
</head>
94-
<body>
95-
<!-- Google Tag Manager -->
96-
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-MZWFF7"
97-
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
98-
<script data-cfasync="false">(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
99-
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
100-
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
101-
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
102-
})(window,document,'script','dataLayer','GTM-MZWFF7');</script>
103-
<!-- End Google Tag Manager -->
104-
</body>
10578
</html>

0 commit comments

Comments
 (0)