Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

cannot read properties of undefined split

I am trying to get the values of _clickHref and _pageName, however if I use the code:

jQuery().ready(function(){
var _clickHref = jQuery(this).attr('{{Referrer}}');
var _pageName= _clickHref.split('/').filter(Boolean);
_pageName = _pageName[_pageName.length-1];
  
window.dataLayer = window.dataLayer || [];
    window.dataLayer.push({
      'event': 'special_offer',
      'carouselHref' : _clickHref,
      'modelName': _pageName
    });
  });

I get the error ‘cannot read properties of undefined split’

and when I write the code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

jQuery().ready(function(){
var _clickHref = jQuery(this).attr('{{Referrer}}');
var _pageName= undefined;
  
window.dataLayer = window.dataLayer || [];
    window.dataLayer.push({
      'event': 'special_offer',
      'carouselHref' : _clickHref,
      'modelName': _pageName
    });
  });

‘carouselHref’is undefined. how to get the values of both carousalHref and modelName?

>Solution :

The referrer is in document.referrer, not an attribute.

var _clickHref = document.referrer;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading