@@ -18,9 +18,32 @@ function get_form_inputs(properties) {
18
18
} ) ;
19
19
}
20
20
21
+ function get_redirect ( e ) {
22
+ return e . currentTarget . getAttribute ( 'href' )
23
+ }
24
+
25
+
21
26
$ ( document ) . ready ( function ( ) {
27
+
28
+ // Create flags
29
+ var button_event_triggered = false ;
30
+
22
31
// capture a click on any element that has
23
- $ ( "[data-analytics]" ) . on ( "click" , async function ( ) {
32
+ $ ( "[data-analytics]" ) . on ( "click" , async function ( e ) {
33
+ if ( button_event_triggered ) {
34
+ button_event_triggered = false ; // reset flag
35
+
36
+ const redirect_to = get_redirect ( e ) ;
37
+
38
+ if ( redirect_to ) {
39
+ window . location . href = redirect_to ;
40
+ }
41
+
42
+ return true ; // let the event bubble away
43
+ }
44
+
45
+ e . preventDefault ( ) ;
46
+
24
47
// Get event name
25
48
var event = $ ( this ) . attr ( "data-analytics" ) ;
26
49
@@ -37,11 +60,15 @@ $(document).ready(function () {
37
60
get_extra_attributes . call ( this , properties ) ;
38
61
// Fire Segment event
39
62
if ( "analytics" in window ) await analytics . track ( event , properties ) ;
63
+
64
+ button_event_triggered = true ; // set flag
65
+ $ ( this ) . trigger ( 'click' ) ;
66
+
40
67
} ) ;
41
68
42
69
43
70
// Add submit listener for all forms
44
- $ ( "form" ) . bind ( "submit" , function ( e ) {
71
+ $ ( "form" ) . on ( "submit" , function ( ) {
45
72
46
73
var properties = {
47
74
// capture the URL where this event is fired
0 commit comments