visual-framework / vf-core

A (primarily CSS) framework that targets needs of life science websites and services
https://stable.visual-framework.dev/
Apache License 2.0
22 stars 10 forks source link

GA: Issue when tracking image interactions #1226

Closed khawkins98 closed 4 years ago

khawkins98 commented 4 years ago

In vf-analtyics-google, there's bug when you click on footer logos European commission or any logo link:

ERROR TypeError: Cannot read property 'split' of undefined
    at vfGaTrackInteraction (vf-analytics-google.js:328)
    at HTMLBodyElement.<anonymous> (vf-analytics-google.js:233)
    at ZoneDelegate.invokeTask (zone-evergreen.js:399)
    at Object.onInvokeTask (core.js:41645)
    at ZoneDelegate.invokeTask (zone-evergreen.js:398)
    at Zone.runTask (zone-evergreen.js:167)
    at ZoneTask.invokeTask [as invoke] (zone-evergreen.js:480)
    at invokeTask (zone-evergreen.js:1621)
    at HTMLBodyElement.globalZoneAwareCallback (zone-evergreen.js:1647)

Originally posted by @sandykadam in https://github.com/visual-framework/vf-core/issues/1210#issuecomment-723100300

khawkins98 commented 4 years ago

This looks like it might be a separate issue with a missing getElementsByTagName("img")[0] in

    // is there an inner image?
    if (linkName.length == 0 && actedOnItem.getElementsByTagName("img")) {
      if (actedOnItem.getElementsByTagName("img")[0]) {
        if (actedOnItem.getElementsByTagName("img")[0].hasAttribute("src")) {
          linkName = actedOnItem.src.split("/").vfGaLinkLast();
        }
      }
    }