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:
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?
CodePudding user response:
The referrer is in document.referrer
, not an attribute.
var _clickHref = document.referrer;