summaryrefslogtreecommitdiff
path: root/app/views/layouts/_google_tag_manager_head.html.haml
blob: 21b9a604a35a10b0303cefcd517397ee25296299 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
- return unless google_tag_manager_enabled?
- if Feature.enabled?(:gitlab_gtm_datalayer, type: :ops)
  = javascript_tag do
    :plain
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}

      gtag('consent', 'default', {
        'analytics_storage': 'granted',
        'ad_storage': 'granted',
        'functionality_storage': 'granted',
        'wait_for_update': 500
      });

      gtag('consent', 'default', {
        'analytics_storage': 'denied',
        'ad_storage': 'denied',
        'functionality_storage': 'denied',
        'region': ['AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE', 'IS', 'LI', 'NO', 'GB', 'PE', 'RU'],
        'wait_for_update': 500
      });

       window.geofeed = (options) => {
          dataLayer.push({
            'event' : 'OneTrustCountryLoad',
            'oneTrustCountryId': options.country.toString()
          })
        }

        const json = document.createElement('script');
        json.setAttribute('src', 'https://geolocation.onetrust.com/cookieconsentpub/v1/geo/location/geofeed');
        document.head.appendChild(json);

- if Feature.enabled?(:gtm_nonce, type: :ops)
  = javascript_tag nonce: content_security_policy_nonce do
    :plain
      (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
      new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
      j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
      'https://www.googletagmanager.com/gtm.js?id='+i+dl;j.setAttribute('nonce',
      '#{content_security_policy_nonce}');f.parentNode.insertBefore(j,f);
      })(window,document,'script','dataLayer','#{google_tag_manager_id}');
- else
  = javascript_tag do
    :plain
      (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
      new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
      j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
      'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
      })(window,document,'script','dataLayer','#{google_tag_manager_id}');