Skip to content

Commit

Permalink
Remove some unnecessary lines of code
Browse files Browse the repository at this point in the history
  • Loading branch information
andysellick committed Sep 27, 2022
1 parent a56648b commit 671179b
Showing 1 changed file with 4 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {};

var core = {
load: function () {
var firstScript
var newScript
var firstScript = document.getElementsByTagName('script')[0]
var newScript = document.createElement('script')
newScript.async = true

if (window.GOVUK.analyticsGa4.vars.gtag_id) {
// initialise gtag
Expand All @@ -16,20 +17,13 @@ window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {};
gtag('js', new Date())
gtag('config', window.GOVUK.analyticsGa4.vars.gtag_id)

firstScript = document.getElementsByTagName('script')[0]
newScript = document.createElement('script')

newScript.async = true
newScript.src = '//www.googletagmanager.com/gtag/js?id=' + window.GOVUK.analyticsGa4.vars.gtag_id
firstScript.parentNode.insertBefore(newScript, firstScript)
} else {
// initialise GTM
window.dataLayer = window.dataLayer || []
window.dataLayer.push({ 'gtm.start': new Date().getTime(), event: 'gtm.js' })

firstScript = document.getElementsByTagName('script')[0]
newScript = document.createElement('script')

var auth = window.GOVUK.analyticsGa4.vars.auth || ''
var preview = window.GOVUK.analyticsGa4.vars.preview || ''
if (auth) {
Expand All @@ -39,7 +33,6 @@ window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {};
preview = '&gtm_preview=' + preview + '&gtm_cookies_win=x'
}

newScript.async = true
this.googleSrc = 'https://www.googletagmanager.com/gtm.js?id=' + window.GOVUK.analyticsGa4.vars.id + auth + preview
newScript.src = this.googleSrc
firstScript.parentNode.insertBefore(newScript, firstScript)
Expand All @@ -53,7 +46,7 @@ window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {};
},

getGemVersion: function () {
return window.GOVUK.analyticsGA4.vars.gem_version || 'not found'
return window.GOVUK.analyticsGa4.vars.gem_version || 'not found'
}
}

Expand Down

0 comments on commit 671179b

Please sign in to comment.