From fa529e47f9d35b35b26b6e2e3be274752641e6b0 Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 31 Jul 2024 13:26:54 -0500 Subject: [PATCH] Website: add Segment analytics (#20867) Related to: https://github.com/fleetdm/confidential/issues/7339 Changes: - Added a script tag for segment - Added segment tracking for contact form submissions, signups, and swag requests. --- website/assets/.eslintrc | 1 + website/assets/js/pages/contact.page.js | 6 +++++ .../js/pages/customers/new-license.page.js | 26 ++++++++++++++++++- .../js/pages/docs/basic-documentation.page.js | 3 +++ .../assets/js/pages/entrance/login.page.js | 4 +-- .../assets/js/pages/entrance/signup.page.js | 4 +-- website/assets/js/pages/start.page.js | 25 ++++++++++++++++++ website/views/layouts/layout.ejs | 13 ++++++---- 8 files changed, 72 insertions(+), 10 deletions(-) diff --git a/website/assets/.eslintrc b/website/assets/.eslintrc index 96d18f3427..6cb581fa72 100644 --- a/website/assets/.eslintrc +++ b/website/assets/.eslintrc @@ -49,6 +49,7 @@ "docsearch": true, "Chart": true, "gtag": true, + "analytics": true, // ...etc. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/website/assets/js/pages/contact.page.js b/website/assets/js/pages/contact.page.js index 4982f49cf8..36571b672a 100644 --- a/website/assets/js/pages/contact.page.js +++ b/website/assets/js/pages/contact.page.js @@ -86,6 +86,9 @@ parasails.registerPage('contact', { if(typeof window.lintrk !== 'undefined') { window.lintrk('track', { conversion_id: 18587089 });// eslint-disable-line camelcase } + if(typeof analytics !== 'undefined'){ + analytics.track('fleet_website__contact_forms'); + } // Show the success message. this.cloudSuccess = true; @@ -98,6 +101,9 @@ parasails.registerPage('contact', { if(typeof window.lintrk !== 'undefined') { window.lintrk('track', { conversion_id: 18587089 });// eslint-disable-line camelcase } + if(typeof analytics !== 'undefined'){ + analytics.track('fleet_website__contact_forms'); + } if(this.formData.numberOfHosts > 700){ this.goto(`https://calendly.com/fleetdm/talk-to-us?email=${encodeURIComponent(this.formData.emailAddress)}&name=${encodeURIComponent(this.formData.firstName+' '+this.formData.lastName)}`); } else { diff --git a/website/assets/js/pages/customers/new-license.page.js b/website/assets/js/pages/customers/new-license.page.js index 6917592f51..3f1b582300 100644 --- a/website/assets/js/pages/customers/new-license.page.js +++ b/website/assets/js/pages/customers/new-license.page.js @@ -39,7 +39,31 @@ parasails.registerPage('new-license', { // ║ ║╠╣ ║╣ ║ ╚╦╝║ ║ ║╣ // ╩═╝╩╚ ╚═╝╚═╝ ╩ ╚═╝╩═╝╚═╝ beforeMount: function() { - //… + if(window.location.hash) { + if(typeof analytics !== 'undefined') { + if(window.location.hash === '#signup') { + analytics.identify(this.me.id, { + email: this.me.emailAddress, + firstName: this.me.firstName, + lastName: this.me.lastName, + company: this.me.organization, + primaryBuyingSituation: this.me.primaryBuyingSituation, + psychologicalStage: this.me.psychologicalStage, + }); + analytics.track('fleet_website__sign_up'); + } else if(window.location.hash === '#login') { + analytics.identify(this.me.id, { + email: this.me.emailAddress, + firstName: this.me.firstName, + lastName: this.me.lastName, + company: this.me.organization, + primaryBuyingSituation: this.me.primaryBuyingSituation, + psychologicalStage: this.me.psychologicalStage, + }); + } + } + window.location.hash = ''; + } }, mounted: async function() { diff --git a/website/assets/js/pages/docs/basic-documentation.page.js b/website/assets/js/pages/docs/basic-documentation.page.js index 2c40e629da..d09d42f605 100644 --- a/website/assets/js/pages/docs/basic-documentation.page.js +++ b/website/assets/js/pages/docs/basic-documentation.page.js @@ -229,6 +229,9 @@ parasails.registerPage('basic-documentation', { if(typeof window.lintrk !== 'undefined') { window.lintrk('track', { conversion_id: 18587105 });// eslint-disable-line camelcase } + if(typeof analytics !== 'undefined'){ + analytics.track('fleet_website__swag_request'); + } this.goto('https://kqphpqst851.typeform.com/to/ZfA3sOu0'); }, diff --git a/website/assets/js/pages/entrance/login.page.js b/website/assets/js/pages/entrance/login.page.js index a506effa58..a18738b75d 100644 --- a/website/assets/js/pages/entrance/login.page.js +++ b/website/assets/js/pages/entrance/login.page.js @@ -27,7 +27,7 @@ parasails.registerPage('login', { showCustomerLogin: true, // For redirecting users coming from the "Get your license" link to the license dispenser. registerSlug: '/register', - pageToRedirectToAfterLogin: '/start', + pageToRedirectToAfterLogin: '/start#login', }, // ╦ ╦╔═╗╔═╗╔═╗╦ ╦╔═╗╦ ╔═╗ @@ -41,7 +41,7 @@ parasails.registerPage('login', { // If we're redirecting this user to the license dispenser after they log in, modify the link to the /register page and the pageToRedirectToAfterLogin. if(window.location.hash && window.location.hash === '#purchaseLicense'){ this.registerSlug = '/register#purchaseLicense'; - this.pageToRedirectToAfterLogin = '/new-license'; + this.pageToRedirectToAfterLogin = '/new-license#login'; window.location.hash = ''; } }, diff --git a/website/assets/js/pages/entrance/signup.page.js b/website/assets/js/pages/entrance/signup.page.js index 6cad63f897..d749af7b30 100644 --- a/website/assets/js/pages/entrance/signup.page.js +++ b/website/assets/js/pages/entrance/signup.page.js @@ -26,7 +26,7 @@ parasails.registerPage('signup', { showFullForm: false, // For redirecting users coming from the "Get your license" link to the license dispenser. loginSlug: '/login', - pageToRedirectToAfterRegistration: '/start', + pageToRedirectToAfterRegistration: '/start#signup', primaryBuyingSituation: undefined }, @@ -37,7 +37,7 @@ parasails.registerPage('signup', { // If we're redirecting this user to the license dispenser after they sign up, modify the link to the login page and the pageToRedirectToAfterRegistration if(window.location.hash && window.location.hash === '#purchaseLicense'){ this.loginSlug = '/login#purchaseLicense'; - this.pageToRedirectToAfterRegistration = '/new-license'; + this.pageToRedirectToAfterRegistration = '/new-license#signup'; window.location.hash = ''; } }, diff --git a/website/assets/js/pages/start.page.js b/website/assets/js/pages/start.page.js index ac31cb69d4..191a445f99 100644 --- a/website/assets/js/pages/start.page.js +++ b/website/assets/js/pages/start.page.js @@ -87,6 +87,31 @@ parasails.registerPage('start', { if(this.primaryBuyingSituation && _.isEmpty(this.formData['what-are-you-using-fleet-for'])){ this.formData['what-are-you-using-fleet-for'] = {primaryBuyingSituation: this.primaryBuyingSituation}; } + if(window.location.hash) { + if(typeof analytics !== 'undefined') { + if(window.location.hash === '#signup') { + analytics.identify(this.me.id, { + email: this.me.emailAddress, + firstName: this.me.firstName, + lastName: this.me.lastName, + company: this.me.organization, + primaryBuyingSituation: this.me.primaryBuyingSituation, + psychologicalStage: this.me.psychologicalStage, + }); + analytics.track('fleet_website__sign_up'); + } else if(window.location.hash === '#login') { + analytics.identify(this.me.id, { + email: this.me.emailAddress, + firstName: this.me.firstName, + lastName: this.me.lastName, + company: this.me.organization, + primaryBuyingSituation: this.me.primaryBuyingSituation, + psychologicalStage: this.me.psychologicalStage, + }); + } + } + window.location.hash = ''; + } }, mounted: async function() { //… diff --git a/website/views/layouts/layout.ejs b/website/views/layouts/layout.ejs index 9b090d48db..ed4ebaf20b 100644 --- a/website/views/layouts/layout.ejs +++ b/website/views/layouts/layout.ejs @@ -61,6 +61,13 @@ + <%/* Segment */%> + <% /* Meta pixel code */ %> - <% /* Delete the global `self` to help avoid client-side bugs. - (see https://developer.mozilla.org/en-US/docs/Web/API/Window/self) */ %> - - - <%/* bowser.js (for browser detection) -- included inline to avoid issues with minification that could affect the unsupported browser overlay */%> @@ -635,6 +637,7 @@ window.history.replaceState({}, '', queryParameterLessUrl);// https://caniuse.com/mdn-api_history_replacestate } }); + // Adding hover events to header dropdown menus. $(function(){ $('[purpose=dropdown-button]').hover(