hof 20.3.6-beta-gtm → 20.3.8-beta-gtm
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
    
        package/config/hof-defaults.js
    CHANGED
    
    | 
         @@ -22,7 +22,20 @@ const defaults = { 
     | 
|
| 
       22 
22 
     | 
    
         
             
              env: process.env.NODE_ENV || 'development',
         
     | 
| 
       23 
23 
     | 
    
         
             
              gaTagId: process.env.GA_TAG || 'Test-GA-Tag',
         
     | 
| 
       24 
24 
     | 
    
         
             
              ga4TagId: process.env.GA_4_TAG,
         
     | 
| 
       25 
     | 
    
         
            -
               
     | 
| 
      
 25 
     | 
    
         
            +
              // added to allow support for multiple HOF forms using GTM to customize how they track page views
         
     | 
| 
      
 26 
     | 
    
         
            +
              gtm: {
         
     | 
| 
      
 27 
     | 
    
         
            +
                tagId: process.env.GTM_TAG || false,
         
     | 
| 
      
 28 
     | 
    
         
            +
                config: {},
         
     | 
| 
      
 29 
     | 
    
         
            +
                composePageName: function (page, convertPage, serviceName) {
         
     | 
| 
      
 30 
     | 
    
         
            +
                  switch (serviceName) {
         
     | 
| 
      
 31 
     | 
    
         
            +
                    case 'ETA':
         
     | 
| 
      
 32 
     | 
    
         
            +
                      return 'ETA | Customer Contact | ' + convertPage(page);
         
     | 
| 
      
 33 
     | 
    
         
            +
                    // Add other services here...
         
     | 
| 
      
 34 
     | 
    
         
            +
                    default:
         
     | 
| 
      
 35 
     | 
    
         
            +
                      return convertPage(page);
         
     | 
| 
      
 36 
     | 
    
         
            +
                  }
         
     | 
| 
      
 37 
     | 
    
         
            +
                }
         
     | 
| 
      
 38 
     | 
    
         
            +
              },
         
     | 
| 
       26 
39 
     | 
    
         
             
              gaCrossDomainTrackingTagId: process.env.GDS_CROSS_DOMAIN_GA_TAG,
         
     | 
| 
       27 
40 
     | 
    
         
             
              loglevel: process.env.LOG_LEVEL || 'info',
         
     | 
| 
       28 
41 
     | 
    
         
             
              ignoreMiddlewareLogs: ['/healthz'],
         
     | 
| 
         @@ -3,12 +3,9 @@ 
     | 
|
| 
       3 
3 
     | 
    
         
             
            <!-- Google Tag Manager Data Layer  -->
         
     | 
| 
       4 
4 
     | 
    
         
             
            <script {{#nonce}}nonce="{{nonce}}"{{/nonce}}>
         
     | 
| 
       5 
5 
     | 
    
         
             
              var dataLayer = window.dataLayer || [];
         
     | 
| 
       6 
     | 
    
         
            -
              dataLayer.push( 
     | 
| 
       7 
     | 
    
         
            -
                 
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
                'applicationType': '{{applicationType}}',
         
     | 
| 
       10 
     | 
    
         
            -
                'environmentType': '{{environmentType}}'
         
     | 
| 
       11 
     | 
    
         
            -
              });
         
     | 
| 
      
 6 
     | 
    
         
            +
              dataLayer.push(
         
     | 
| 
      
 7 
     | 
    
         
            +
                {{{gtmConfig}}}
         
     | 
| 
      
 8 
     | 
    
         
            +
              );
         
     | 
| 
       12 
9 
     | 
    
         
             
            </script>
         
     | 
| 
       13 
10 
     | 
    
         
             
            <!-- End Google Tag Manager Data Layer  -->
         
     | 
| 
       14 
11 
     | 
    
         | 
    
        package/lib/ga-tag.js
    CHANGED
    
    | 
         @@ -52,12 +52,11 @@ const setupPageMap = routes => { 
     | 
|
| 
       52 
52 
     | 
    
         
             
            module.exports = (app, config) => {
         
     | 
| 
       53 
53 
     | 
    
         
             
              const gaTagId = config.gaTagId;
         
     | 
| 
       54 
54 
     | 
    
         
             
              const ga4TagId = config.ga4TagId;
         
     | 
| 
       55 
     | 
    
         
            -
              const  
     | 
| 
       56 
     | 
    
         
            -
              const environmentType = config.environmentType ? config.environmentType : 'dev';
         
     | 
| 
      
 55 
     | 
    
         
            +
              const gtm = config.gtm;
         
     | 
| 
       57 
56 
     | 
    
         
             
              const gaCrossDomainTrackingTagId = config.gaCrossDomainTrackingTagId;
         
     | 
| 
       58 
57 
     | 
    
         
             
              const routes = config.routes;
         
     | 
| 
       59 
58 
     | 
    
         | 
| 
       60 
     | 
    
         
            -
              if (gaTagId || ga4TagId ||  
     | 
| 
      
 59 
     | 
    
         
            +
              if (gaTagId || ga4TagId || gtm.tagId) {
         
     | 
| 
       61 
60 
     | 
    
         
             
                const pageMap = setupPageMap(routes);
         
     | 
| 
       62 
61 
     | 
    
         | 
| 
       63 
62 
     | 
    
         
             
                app.use((req, res, next) => {
         
     | 
| 
         @@ -74,47 +73,17 @@ module.exports = (app, config) => { 
     | 
|
| 
       74 
73 
     | 
    
         
             
                  };
         
     | 
| 
       75 
74 
     | 
    
         | 
| 
       76 
75 
     | 
    
         
             
                  // Adding extra properties if a GTM TAG is available
         
     | 
| 
       77 
     | 
    
         
            -
                  if ( 
     | 
| 
      
 76 
     | 
    
         
            +
                  if (gtm.tagId) {
         
     | 
| 
      
 77 
     | 
    
         
            +
                    gtm.config.pageName = gtm.composePageName(page, convertToGTMPage);
         
     | 
| 
       78 
78 
     | 
    
         
             
                    Object.assign(properties, {
         
     | 
| 
       79 
     | 
    
         
            -
                       
     | 
| 
       80 
     | 
    
         
            -
                       
     | 
| 
       81 
     | 
    
         
            -
                      eventName: 'pageLoad',
         
     | 
| 
       82 
     | 
    
         
            -
                      pageName: `ETA | Customer Contact Webform | ${convertToGTMPage(page)}`,
         
     | 
| 
       83 
     | 
    
         
            -
                      applicationType: 'ETA | Customer Contact',
         
     | 
| 
       84 
     | 
    
         
            -
                      environmentType: environmentType
         
     | 
| 
      
 79 
     | 
    
         
            +
                      gtmConfig: JSON.stringify(gtm.config),
         
     | 
| 
      
 80 
     | 
    
         
            +
                      gtmTagId: gtm.tagId
         
     | 
| 
       85 
81 
     | 
    
         
             
                    });
         
     | 
| 
       86 
82 
     | 
    
         
             
                  }
         
     | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
83 
     | 
    
         
             
                  res.locals = Object.assign(res.locals, properties);
         
     | 
| 
       89 
84 
     | 
    
         
             
                  next();
         
     | 
| 
       90 
85 
     | 
    
         
             
                });
         
     | 
| 
       91 
86 
     | 
    
         
             
              }
         
     | 
| 
       92 
87 
     | 
    
         | 
| 
       93 
     | 
    
         
            -
              /*
         
     | 
| 
       94 
     | 
    
         
            -
               if (gaTagId || ga4TagId || gtmTagId) {
         
     | 
| 
       95 
     | 
    
         
            -
                const pageMap = setupPageMap(routes);
         
     | 
| 
       96 
     | 
    
         
            -
             
     | 
| 
       97 
     | 
    
         
            -
                app.use((req, res, next) => {
         
     | 
| 
       98 
     | 
    
         
            -
                  const page = pageView(req.path, pageMap);
         
     | 
| 
       99 
     | 
    
         
            -
                  res.locals.gaAllowDebug = config.env === 'development';
         
     | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
       101 
     | 
    
         
            -
                  if (gtmTagId) {
         
     | 
| 
       102 
     | 
    
         
            -
                    res.locals.gtmTagId = gtmTagId;
         
     | 
| 
       103 
     | 
    
         
            -
                    res.locals['gtm-page'] = convertToGTMPage(page);
         
     | 
| 
       104 
     | 
    
         
            -
                    res.locals.eventName = "pageLoad"
         
     | 
| 
       105 
     | 
    
         
            -
                    res.locals.pageName = `ETA | Customer Contact Webform | ${res.locals['gtm-page']}`
         
     | 
| 
       106 
     | 
    
         
            -
                    res.locals.applicationType = "ETA | Customer Contact"
         
     | 
| 
       107 
     | 
    
         
            -
                    res.locals.environmentType = environmentType;
         
     | 
| 
       108 
     | 
    
         
            -
                  }
         
     | 
| 
       109 
     | 
    
         
            -
                  res.locals.gaTagId = gaTagId;
         
     | 
| 
       110 
     | 
    
         
            -
                  res.locals.ga4TagId = ga4TagId;
         
     | 
| 
       111 
     | 
    
         
            -
                  res.locals.gaCrossDomainTrackingTagId = gaCrossDomainTrackingTagId;
         
     | 
| 
       112 
     | 
    
         
            -
                  res.locals['ga-id'] = gaTagId;
         
     | 
| 
       113 
     | 
    
         
            -
                  res.locals['ga-page'] = page;
         
     | 
| 
       114 
     | 
    
         
            -
                  next();
         
     | 
| 
       115 
     | 
    
         
            -
                });
         
     | 
| 
       116 
     | 
    
         
            -
              }
         
     | 
| 
       117 
     | 
    
         
            -
              */
         
     | 
| 
       118 
     | 
    
         
            -
             
     | 
| 
       119 
88 
     | 
    
         
             
              return app;
         
     | 
| 
       120 
89 
     | 
    
         
             
            };
         
     |