@@ -8,16 +8,16 @@ import enquiry_button from './components/enquiry-button'
88import enquiry_modal from './components/enquiry-modal'
99import grid from './components/grid'
1010import con_modal from './components/con-modal'
11- import { to_markdown , clean , auto_url_root } from './utils'
11+ import { to_markdown , clean , auto_url_root , init_ga } from './utils'
1212
13- let raven_config = {
13+ const raven_config = {
1414 release : process . env . RELEASE ,
1515 tags : {
1616 host : window . location . host ,
1717 } ,
1818 shouldSendCallback : ( data ) => {
1919 // if no culprit this a message and came from socket
20- let culprit = data . culprit || '/socket.js'
20+ const culprit = data . culprit || '/socket.js'
2121 return culprit . indexOf ( '/socket.js' ) > 0
2222 }
2323}
@@ -26,9 +26,9 @@ Raven.config(process.env.RAVEN_DSN, raven_config).addPlugin(RavenVue, Vue).insta
2626Vue . use ( VueRouter )
2727
2828const ConfiguredVueRouter = config => {
29- let routes = [ ]
29+ const routes = [ ]
3030 if ( config . mode === 'grid' ) {
31- routes = [
31+ routes . push (
3232 {
3333 path : config . url_root ,
3434 name : 'index' ,
@@ -41,17 +41,17 @@ const ConfiguredVueRouter = config => {
4141 }
4242 ]
4343 }
44- ]
44+ )
4545 } else if ( config . mode === 'enquiry' ) {
46- routes = [
46+ routes . push (
4747 {
4848 path : config . url_root ,
4949 name : 'index' ,
5050 component : enquiry ,
5151 } ,
52- ]
52+ )
5353 } else if ( config . mode === 'enquiry-modal' ) {
54- routes = [
54+ routes . push (
5555 {
5656 path : config . url_root ,
5757 name : 'index' ,
@@ -64,7 +64,7 @@ const ConfiguredVueRouter = config => {
6464 }
6565 ]
6666 }
67- ]
67+ )
6868 }
6969 return new VueRouter ( {
7070 mode : config . router_mode ,
@@ -144,10 +144,13 @@ module.exports = function (public_key, config) {
144144 config [ k ] = STRINGS [ k ]
145145 }
146146 }
147+ const router = ConfiguredVueRouter ( config )
148+
149+ const ga_prefixes = init_ga ( router , config )
147150
148151 return new Vue ( {
149152 el : config . element ,
150- router : ConfiguredVueRouter ( config ) ,
153+ router : router ,
151154 render : h => h ( app ) ,
152155 data : {
153156 grecaptcha_key : process . env . GRECAPTCHA_KEY ,
@@ -182,8 +185,8 @@ module.exports = function (public_key, config) {
182185 if ( error !== null ) {
183186 return
184187 }
185- let xhr = new window . XMLHttpRequest ( )
186- let url = `${ config . api_root } /${ public_key } /contractors`
188+ const xhr = new window . XMLHttpRequest ( )
189+ const url = `${ config . api_root } /${ public_key } /contractors`
187190 xhr . open ( 'GET' , url )
188191 xhr . onload = ( ) => {
189192 let contractors
@@ -217,13 +220,13 @@ response text: "${xhr.responseText}"`)
217220 if ( this . contractors_extra [ link ] !== undefined ) {
218221 return false
219222 }
220- let xhr = new window . XMLHttpRequest ( )
223+ const xhr = new window . XMLHttpRequest ( )
221224 xhr . open ( 'GET' , url )
222225 xhr . onload = ( ) => {
223226 if ( xhr . status !== 200 ) {
224227 this . handle_error ( `bad response ${ xhr . status } at "${ url } "` )
225228 } else {
226- let con = JSON . parse ( xhr . responseText )
229+ const con = JSON . parse ( xhr . responseText )
227230 Vue . set ( this . contractors_extra , link , con )
228231 }
229232 }
@@ -234,8 +237,8 @@ response text: "${xhr.responseText}"`)
234237 if ( Object . keys ( this . enquiry_form_info ) . length !== 0 || this . _getting_enquiry_info ) {
235238 return
236239 }
237- let xhr = new window . XMLHttpRequest ( )
238- let url = `${ config . api_root } /${ public_key } /enquiry`
240+ const xhr = new window . XMLHttpRequest ( )
241+ const url = `${ config . api_root } /${ public_key } /enquiry`
239242 xhr . open ( 'GET' , url )
240243 xhr . onload = ( ) => {
241244 if ( xhr . status !== 200 ) {
@@ -251,9 +254,9 @@ response text: "${xhr.responseText}"`)
251254 xhr . send ( )
252255 } ,
253256 submit_enquiry : function ( callback ) {
254- let data = JSON . stringify ( clean ( this . enquiry_data ) )
255- let xhr = new window . XMLHttpRequest ( )
256- let url = `${ config . api_root } /${ public_key } /enquiry`
257+ const data = JSON . stringify ( clean ( this . enquiry_data ) )
258+ const xhr = new window . XMLHttpRequest ( )
259+ const url = `${ config . api_root } /${ public_key } /enquiry`
257260 xhr . open ( 'POST' , url )
258261 xhr . onload = ( ) => {
259262 if ( xhr . status !== 201 ) {
@@ -280,6 +283,12 @@ response text: "${xhr.responseText}"`)
280283 return s
281284 }
282285 } ,
286+ ga_event : function ( category , action , label ) {
287+ /* istanbul ignore next */
288+ for ( let prefix of ga_prefixes ) {
289+ window . ga ( prefix + 'send' , 'event' , category , action , label )
290+ }
291+ } ,
283292 goto : function ( name , params ) {
284293 this . $router . push ( { 'name' : name , params : params } )
285294 }
0 commit comments