diff --git a/.eslintrc b/.eslintrc index 582942b284..15453f65ec 100644 --- a/.eslintrc +++ b/.eslintrc @@ -19,7 +19,8 @@ "globals": { "Blockly": false, "trackJs": false, - "jest": false + "jest": false, + "dataLayer": false }, "plugins": [ "react" diff --git a/gulp/build.js b/gulp/build.js index 30ebffc806..d40b1cabbc 100644 --- a/gulp/build.js +++ b/gulp/build.js @@ -16,7 +16,6 @@ const getConfig = prefix => ({ binary_style_img: 'image/binary-style', elevio_script : '', - gtm_head : ' ', gtm_iframe: ' ', }); diff --git a/src/botPage/view/blockly/customBlockly.js b/src/botPage/view/blockly/customBlockly.js index 4e9319a389..db1fa80e52 100644 --- a/src/botPage/view/blockly/customBlockly.js +++ b/src/botPage/view/blockly/customBlockly.js @@ -1,4 +1,6 @@ -import { translate } from '../../../common/utils/tools'; +import GTM from '../../../common/gtm'; +import { translate, translateLangToLang } from '../../../common/i18n'; +import { getLanguage } from '../../../common/lang'; /* eslint-disable */ Blockly.WorkspaceAudio.prototype.preload = function() {}; @@ -334,3 +336,25 @@ Blockly.Input.prototype.attachShadowBlock = function(value, name, shadowBlockTyp shadowBlock.initSvg(); shadowBlock.render(); }; + +/** + * Expand or collapse the node on mouse click. + * @param {!goog.events.BrowserEvent} _e The browser event. + * @override + */ +Blockly.Toolbox.TreeNode.prototype.onClick_ = function(_e) { + // eslint-disable-next-line no-underscore-dangle + const blocklyCategoryName = translateLangToLang(_e.target.innerText, getLanguage(), 'en'); + GTM.pushDataLayer({ event: 'Click Block Category', blocklyCategoryName }); + + // Expand icon. + if (this.hasChildren() && this.isUserCollapsible_) { + this.toggle(); + this.select(); + } else if (this.isSelected()) { + this.getTree().setSelectedItem(null); + } else { + this.select(); + } + this.updateRow(); +}; diff --git a/src/botPage/view/blockly/index.js b/src/botPage/view/blockly/index.js index f464a78d63..0636724381 100644 --- a/src/botPage/view/blockly/index.js +++ b/src/botPage/view/blockly/index.js @@ -21,6 +21,7 @@ import { translate, xml as translateXml } from '../../../common/i18n'; import { getLanguage } from '../../../common/lang'; import { observer as globalObserver } from '../../../common/utils/observer'; import { showDialog } from '../../bot/tools'; +import GTM from '../../../common/gtm'; const setBeforeUnload = off => { if (off) { @@ -232,6 +233,31 @@ export default class _Blockly { }, trashcan: false, }); + workspace.addChangeListener(event => { + if (event.type === Blockly.Events.BLOCK_CREATE) { + event.ids.forEach(id => { + const block = workspace.getBlockById(id); + if (block) { + GTM.pushDataLayer({ + event : 'Block Event', + blockEvent: event.type, + blockType : block.type, + }); + } + }); + } else if (event.type === Blockly.Events.BLOCK_DELETE) { + const dom = Blockly.Xml.textToDom(`${event.oldXml.outerHTML}`); + const blockNodes = dom.getElementsByTagName('block'); + Array.from(blockNodes).forEach(blockNode => { + GTM.pushDataLayer({ + event : 'Block Event', + blockEvent: event.type, + blockType : blockNode.getAttribute('type'), + }); + }); + } + }); + const renderInstance = render(workspace); window.addEventListener('resize', renderInstance, false); renderInstance(); diff --git a/src/botPage/view/index.js b/src/botPage/view/index.js index 497d2d8c25..113250da51 100644 --- a/src/botPage/view/index.js +++ b/src/botPage/view/index.js @@ -30,7 +30,7 @@ view.initPromise.then(() => { $('.barspinner').hide(); window.dispatchEvent(new Event('resize')); Elevio.init(); - GTM.setVisitorId(); + GTM.init(); trackJs.configure({ userId: $('.account-id') .first() diff --git a/src/botPage/view/react-components/Integrations/GoogleDriveIntegration.js b/src/botPage/view/react-components/Integrations/GoogleDriveIntegration.js index 8d4f4c53e0..6fe9627ec9 100644 --- a/src/botPage/view/react-components/Integrations/GoogleDriveIntegration.js +++ b/src/botPage/view/react-components/Integrations/GoogleDriveIntegration.js @@ -31,13 +31,13 @@ export default class GoogleDriveIntegration extends PureComponent { onClick={() => googleDrive.authorise()} className={!googleDrive.isAuthorised ? 'button' : 'button-disabled'} > - {translate('Connect')} + {translate('Connect')} googleDrive.signOut()} className={googleDrive.isAuthorised ? 'button' : 'button-disabled'} > - {translate('Disconnect')} + {translate('Disconnect')} diff --git a/src/common/gtm.js b/src/common/gtm.js index 3fc21bd414..142fb41e2f 100644 --- a/src/common/gtm.js +++ b/src/common/gtm.js @@ -5,9 +5,26 @@ import { getTokenList } from './utils/storageManager'; const GTM = (() => { const isGtmApplicable = () => Object.values(AppIdMap).includes(`${getAppIdFallback()}`); - const pushDataLayer = data => { + const init = () => { if (isGtmApplicable()) { - // eslint-disable-next-line no-undef + const gtmTag = + '(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({\'gtm.start\': new Date().getTime(),event:\'gtm.js\'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!=\'dataLayer\'?\'&l=\'+l:\'\';j.async=true;j.src= \'https://www.googletagmanager.com/gtm.js?id=\'+i+dl;f.parentNode.insertBefore(j,f); })(window,document,\'script\',\'dataLayer\',\'GTM-P97C2DZ\');'; + + const script = document.createElement('script'); + script.innerHTML = gtmTag; + document.body.appendChild(script); + + const interval = setInterval(() => { + if (dataLayer) { + setVisitorId(); + clearInterval(interval); + } + }, 500); + } + }; + + const pushDataLayer = data => { + if (isGtmApplicable() && dataLayer) { dataLayer.push({ ...data, }); @@ -24,6 +41,8 @@ const GTM = (() => { }; return { + init, + pushDataLayer, setVisitorId, }; })(); diff --git a/src/common/i18n.js b/src/common/i18n.js index e1b6204be4..af02af8f8d 100644 --- a/src/common/i18n.js +++ b/src/common/i18n.js @@ -40,6 +40,20 @@ export const init = lang => { export const translate = str => (str && t(sha1(str))) || str; +export const translateLangToLang = (str, fromLang, toLang) => { + if (supportedLanguages[fromLang]) { + const hashIndex = Object.values(supportedLanguages[fromLang]).findIndex(translatedStr => str === translatedStr); + if (hashIndex !== -1) { + const hash = Object.keys(supportedLanguages[fromLang])[hashIndex]; + const translatedStr = supportedLanguages[toLang][hash]; + if (translatedStr) { + return translatedStr; + } + } + } + return str; +}; + export const xml = dom => { const categories = Array.from(dom.getElementsByTagName('category') || []); categories.forEach(child => { diff --git a/src/indexPage/index.js b/src/indexPage/index.js index 7962da9cec..ce98e6bb66 100644 --- a/src/indexPage/index.js +++ b/src/indexPage/index.js @@ -1,14 +1,15 @@ import React from 'react'; import ReactDOM from 'react-dom'; +import endpoint from './endpoint'; import Logo from './react-components/logo.jsx'; import Footer from './react-components/footer.jsx'; -import { getTokenList } from '../common/utils/storageManager'; import { oauthLogin } from '../common/appId'; -import { createUrl } from '../common/utils/tools'; -import { load as loadLang } from '../common/lang'; import '../common/binary-ui/dropdown'; -import endpoint from './endpoint'; import isEuCountry from '../common/footer-checks'; +import GTM from '../common/gtm'; +import { load as loadLang } from '../common/lang'; +import { getTokenList } from '../common/utils/storageManager'; +import { createUrl } from '../common/utils/tools'; const renderElements = () => { const showHideEuElements = isEu => { @@ -33,6 +34,7 @@ const loginCheck = () => { $('.show-on-load').show(); $('.barspinner').hide(); renderElements(); + GTM.init(); }); } }; diff --git a/src/indexPage/react-components/footer.jsx b/src/indexPage/react-components/footer.jsx index 32466aeb49..a95c20b1c2 100644 --- a/src/indexPage/react-components/footer.jsx +++ b/src/indexPage/react-components/footer.jsx @@ -44,20 +44,20 @@ const Footer = () => (

- {translate(['In the EU, financial products are offered by Binary Investments (Europe) Ltd., Mompalao Building, Suite 2, Tower Road, Msida MSD1825, Malta, regulated as a Category 3 Investment Services provider by the Malta Financial Services Authority ([_1]licence no. IS/70156[_2]).', ``, ''])} + {translate(['In the EU, financial products are offered by Binary Investments (Europe) Ltd., W Business Centre, Level 3, Triq Dun Karm, Birkirkara, BKR 9033, Malta, regulated as a Category 3 Investment Services provider by the Malta Financial Services Authority ([_1]licence no. IS/70156[_2]).', ``, ''])}

- {translate(['Outside the EU, financial products are offered by Binary (C.R.) S.A., 5th Floor, Building 6 Centro Ejecutivo La Sabana, Sabana Sur, San José, Costa Rica, Binary (V) Ltd, Govant Building, Port Vila, PO Box 1276, Vanuatu, regulated by the Vanuatu Financial Services Commission ([_1]view licence[_2]), Binary (BVI) Ltd, 2nd Floor, O’Neal Marketing Associates Building, Wickham’s Cay II, P.O. Box 3174, Road Town, Tortola VB1110, British Virgin Islands, regulated by the British Virgin Islands Financial Services Commission ([_3]licence no. SIBA/L/18/1114[_4]), and Binary (FX) Ltd., Lot No. F16, First Floor, Paragon Labuan, Jalan Tun Mustapha, 87000 Labuan, Malaysia, regulated by the Labuan Financial Services Authority to carry on a money-broking business ([_5]licence no. MB/18/0024[_6])', + {translate(['Outside the EU, financial products are offered by Binary (SVG) Ltd, Hinds Building, Kingstown, St. Vincent and the Grenadines; Binary (V) Ltd, Govant Building, Port Vila, PO Box 1276, Vanuatu, regulated by the Vanuatu Financial Services Commission ([_1]view licence[_2]); Binary (BVI) Ltd, Kingston Chambers, P.O. Box 173, Road Town, Tortola, British Virgin Islands, regulated by the British Virgin Islands Financial Services Commission ([_3]licence no. SIBA/L/18/1114[_4]); and Binary (FX) Ltd., Lot No. F16, First Floor, Paragon Labuan, Jalan Tun Mustapha, 87000 Labuan, Malaysia, regulated by the Labuan Financial Services Authority to carry on a money-broking business ([_5]licence no. MB/18/0024[_6]).', '', '', ``, '', ``, ''])}

- {translate(['This website’s services are not made available in certain countries such as the USA, Canada, Costa Rica, Hong Kong, Japan, or to persons under age 18.'])} + {translate(['This website\'s services are not made available in certain countries such as the USA, Canada, Hong Kong, Japan, or to persons under age 18.'])}

{translate(['Risk Warning'])} -

{translate(['The financial products offered via this website include binary options, contracts for difference ("CFDs") and other complex derivatives and financial products. Trading binary options may not be suitable for everyone. Trading CFDs carries a high level of risk since leverage can work both to your advantage and disadvantage. As a result, the products offered on this website may not be suitable for all investors because of the risk of losing all of your invested capital. You should never invest money that you cannot afford to lose, and never trade with borrowed money. Before trading in the complex financial products offered, please be sure to understand the risks involved and learn about [_1]Responsible Trading[_2].', ``, ''])}

+

{translate(['The products offered via this website include binary options, contracts for difference ("CFDs") and other complex derivatives. Trading binary options may not be suitable for everyone. Trading CFDs carries a high level of risk since leverage can work both to your advantage and disadvantage. As a result, the products offered on this website may not be suitable for all investors because of the risk of losing all of your invested capital. You should never invest money that you cannot afford to lose, and never trade with borrowed money. Before trading in the complex products offered, please be sure to understand the risks involved and learn about [_1]Responsible Trading[_2].', ``, ''])}

@@ -97,13 +97,13 @@ const Footer = () => (

- {translate(['In the EU, financial products are offered by Binary Investments (Europe) Ltd., Mompalao Building, Suite 2, Tower Road, Msida MSD1825, Malta, licensed and regulated as a Category 3 Investment Services provider by the Malta Financial Services Authority (licence no. IS/70156).'])} + {translate(['In the EU, financial products are offered by Binary Investments (Europe) Ltd., W Business Centre, Level 3, Triq Dun Karm, Birkirkara, BKR 9033, Malta, licensed and regulated as a Category 3 Investment Services provider by the Malta Financial Services Authority (licence no. IS/70156).'])}

{translate(['In the Isle of Man and the UK, Volatility Indices are offered by Binary (IOM) Ltd., First Floor, Millennium House, Victoria Road, Douglas, IM2 4RW, Isle of Man, British Isles; licensed and regulated respectively by (1) the Gambling Supervision Commission in the Isle of Man (current licence issued on 31 August 2017) and by (2) the Gambling Commission in the UK (licence [_1]reference no: 39172[_2]).', '', ''])}

- {translate(['In the rest of the EU, Volatility Indices are offered by Binary (Europe) Ltd., Mompalao Building, Suite 2, Tower Road, Msida MSD1825, Malta; licensed and regulated by (1) the Malta Gaming Authority in Malta (licence no. MGA/B2C/102/2000 issued on 01 August 2018), for UK clients by (2) the UK Gambling Commission (licence [_1]reference no: 39495[_2]), and for Irish clients by (3) the Revenue Commissioners in Ireland (Remote Bookmaker\'s Licence no. 1010285 issued on 1 July 2017). View complete [_3]Regulatory Information[_2].', '', '', ``])} + {translate(['In the rest of the EU, Volatility Indices are offered by Binary (Europe) Ltd., W Business Centre, Level 3, Triq Dun Karm, Birkirkara, BKR 9033, Malta; licensed and regulated by (1) the Malta Gaming Authority in Malta (licence no. MGA/B2C/102/2000 issued on 01 August 2018), for UK clients by (2) the UK Gambling Commission (licence [_1]reference no: 39495[_2]), and for Irish clients by (3) the Revenue Commissioners in Ireland (Remote Bookmaker\'s Licence no. 1010285 issued on 1 July 2017). View complete [_3]Regulatory Information[_2].', '', '', ``])}

@@ -111,7 +111,7 @@ const Footer = () => (

- {translate(['Binary.com is an award-winning online trading provider that helps its clients to trade on financial markets through binary options and CFDs. Trading binary options and CFDs on Volatility Indices is classified as a gambling activity. Remember that gambling can be addictive – please play responsibly. Learn more about [_1]Responsible Trading[_2]. Some products are not available in all countries. This website’s services are not made available in certain countries such as the USA, Canada, Costa Rica, Hong Kong, or to persons under age 18.', ``, ''])} + {translate(['Binary.com is an award-winning online trading provider that helps its clients to trade on financial markets through binary options and CFDs. Trading binary options and CFDs on Volatility Indices is classified as a gambling activity. Remember that gambling can be addictive – please play responsibly. Learn more about [_1]Responsible Trading[_2]. Some products are not available in all countries. This website\'s services are not made available in certain countries such as the USA, Canada, Hong Kong, or to persons under age 18.', ``, ''])}

diff --git a/templates/bot.mustache b/templates/bot.mustache index 2a0b626ec2..7353ebd26f 100644 --- a/templates/bot.mustache +++ b/templates/bot.mustache @@ -7,7 +7,6 @@ {{> bundle_css }} {{> bot_css }} - {{> gtm_head }} @@ -166,7 +165,11 @@
- + + diff --git a/templates/index.mustache b/templates/index.mustache index e49cf2cb92..8d353bc8ac 100644 --- a/templates/index.mustache +++ b/templates/index.mustache @@ -8,7 +8,6 @@ {{> index_css }} -{{> gtm_head }}