(function () {
  if (document.querySelector('#gtmsdef') !== null) return false
  var nscript = document.createElement('script')
  var hnamesplit = location.hostname.split('.')
  var referrer = document.referrer.split('/')
  if (referrer[4] === 'iframe' && typeof referrer[5] === 'string' && referrer[5].includes('host_url')) {
    var refq = referrer[5].split('?')[1]
    var refparams = new URLSearchParams(refq)
    nscript.src = 'https://gtms.roiq.com/' + new URL(refparams.get('host_url')).host + '.js'
  } else if (referrer[2] && referrer[2] !== location.hostname) {
    nscript.src = 'https://gtms.roiq.com/' + referrer[2] + '.js'
  } else if (hnamesplit[hnamesplit.length-2] !== 'dealerx' && hnamesplit[hnamesplit.length-3] && hnamesplit[hnamesplit.length-3] !== 'www') {
    nscript.src = 'https://gtms.roiq.com/www.' + hnamesplit.slice(-2).join('.') + '.js'
  } else if (hnamesplit[hnamesplit.length-2] === 'dealerx') {
    nscript.src = 'https://gtms.roiq.com/www.' + hnamesplit[hnamesplit.length-3] + '.com.js'
  } else {
    nscript = null
  }
  if (nscript !== null) {
    nscript.id = 'gtmsdef'
    document.body.appendChild(nscript)
  }
})();

(function (dataLayer) {
  var prevconfig = window.dataLayer.filter(function (item) {
    return item.event === 'configReady'
  })
  var roiqId = "fallback_account_id"
  if (document.querySelector('script[src*="5DN6BV9"]') !== null) {
    roiqId = "fallback_account_id_plugin"
  }
  if (prevconfig.length > 0) return false
        var _config = {
 "roiqId": roiqId,
 "fbId": "n/a",
 "phonenum": {
  "hardNumToFlip": "",
  "numToFlipCss": ".na"
 },
 "chunk": {
  "notchunk": false,
  "clickUDClass": "undefined",
  "clickUDType": "submit",
  "formFrame": "undefined"
 },
 "form": {
  "search": "",
  "email": ".na",
  "firstName": ".na",
  "lastName": ".na",
  "phone": ".na",
  "subject": ""
 },
 "page": {
  "VDP": "\\/na\\/.*",
  "SRP": "\\/na\\/.*",
  "model": "\\/na\\/.*"
 }
}
        dataLayer.push({event:'configReady', config: _config})
        })(window.dataLayer)
