@@ -22,16 +22,10 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
22
22
23
23
var $checkedOption = $submittedForm . find ( 'input:checked' )
24
24
25
- var checkedValue = $checkedOption . val ( ) ;
26
-
27
- if ( typeof checkedValue === 'undefined' ) {
28
- checkedValue = 'submitted-without-choosing'
29
- }
30
-
31
- GOVUK . analytics . trackEvent ( 'Radio button chosen' , checkedValue + ( withHint ? '-with-hint' : '' ) , options )
25
+ GOVUK . analytics . trackEvent ( 'Radio button chosen' , eventTrackingValue ( $checkedOption , withHint ) , options )
32
26
33
27
if ( typeof $submittedForm . attr ( 'data-tracking-code' ) !== 'undefined' ) {
34
- addCrossDomainTracking ( $submittedForm , $checkedOption , options )
28
+ addCrossDomainTracking ( $submittedForm , $checkedOption , options , withHint )
35
29
}
36
30
} )
37
31
}
@@ -58,15 +52,28 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
58
52
}
59
53
}
60
54
61
- function addCrossDomainTracking ( element , $checkedOption , options ) {
55
+ function eventTrackingValue ( element , withHint ) {
56
+ var value = element . val ( )
57
+
58
+ if ( typeof value === 'undefined' ) {
59
+ value = 'submitted-without-choosing'
60
+ }
61
+
62
+ if ( withHint ) {
63
+ value += '-with-hint'
64
+ }
65
+ return value
66
+ }
67
+
68
+ function addCrossDomainTracking ( element , $checkedOption , options , withHint ) {
62
69
var code = element . attr ( 'data-tracking-code' )
63
70
var name = element . attr ( 'data-tracking-name' )
64
71
var url = $checkedOption . attr ( 'data-tracking-url' )
65
72
var hostname = $ ( '<a>' ) . prop ( 'href' , url ) . prop ( 'hostname' )
66
73
var eventOptions = $ . extend ( { 'trackerName' : name } , options )
67
74
68
75
GOVUK . analytics . addLinkedTrackerDomain ( code , name , hostname )
69
- GOVUK . analytics . trackEvent ( 'Radio button chosen' , $checkedOption . val ( ) , eventOptions )
76
+ GOVUK . analytics . trackEvent ( 'Radio button chosen' , eventTrackingValue ( $checkedOption , withHint ) , eventOptions )
70
77
}
71
78
}
72
79
} ) ( window , window . GOVUK ) ;
0 commit comments