import { apiRequest } from '../../common/helpers/api';

export const ATTRS_FETCHING = 'ATTRS_FETCHING';
export const ATTRS_SUCCESS = 'ATTRS_SUCCESS';
export const ATTRS_FAILURE = 'ATTRS_FAILURE';
export const REDIRECT_TIMED_OUT = 'REDIRECT_TIMED_OUT';

export function initiateIdRequest() {
  return dispatch => {
    dispatch({ type: ATTRS_FETCHING });

    apiRequest('/id_card/attributes',
      {},
      (response) => dispatch({
        type: ATTRS_SUCCESS,
        vicUrl: response.url,
        traits: response.traits
      }),
      (response) => dispatch({
        type: ATTRS_FAILURE,
        errors: response.errors
      })
    );
  };
}

export function timeoutRedirect() {
  return { type: REDIRECT_TIMED_OUT };
}

@@ -280,24 +280,82 @@
 Request() %7B%0A
+  window.dataLayer.push(%7B event: 'vic-submit-started' %7D);%0A
   return dis
@@ -365,16 +365,16 @@
 ch =%3E %7B%0A
-
     disp
@@ -465,32 +465,106 @@
    (response) =%3E
+ %7B%0A        window.dataLayer.push(%7B event: 'vic-submit-success' %7D);%0A       
  dispatch(%7B%0A    
@@ -559,32 +559,34 @@
 patch(%7B%0A        
+  
 type: ATTRS_SUCC
@@ -590,16 +590,18 @@
 UCCESS,%0A
+  
         
@@ -630,16 +630,18 @@
         
+ 
+ 
 traits: 
@@ -662,18 +662,29 @@
 s%0A      
+  %7D);%0A      
 %7D
-)
 ,%0A      
@@ -696,16 +696,90 @@
 onse) =%3E
+ %7B%0A        window.dataLayer.push(%7B event: 'vic-submit-failure' %7D);%0A       
  dispatc
@@ -774,32 +774,34 @@
      dispatch(%7B%0A
+  
         type: AT
@@ -813,16 +813,18 @@
 AILURE,%0A
+  
         
@@ -853,18 +853,29 @@
 s%0A      
+  %7D);%0A      
 %7D
-)
 %0A    );%0A

Add GA events for VIC submission, success, failure (#6856)