Skip to content

Commit

Permalink
Merge pull request #115 from ddragosd/feat_autotrack_ctas
Browse files Browse the repository at this point in the history
feat(sourceselector): highlight clicks on buttons and CTAs
  • Loading branch information
trieloff authored Mar 4, 2024
2 parents 80b7c0e + 21eaf26 commit ce197f5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,20 @@ const sourceselector = (element) => {
formElementSelector = element.tagName === 'INPUT' ? `form input[type='${element.getAttribute('type')}']` : `form ${element.tagName.toLowerCase()}`;
}

const blockName = element.closest('.block') ? element.closest('.block').getAttribute('data-block-name') : '';
if (element.id || formElementSelector) {
const blockName = element.closest('.block') ? element.closest('.block').getAttribute('data-block-name') : '';
const id = element.id ? `#${element.id}` : '';
return blockName ? `.${blockName} ${formElementSelector}${id}` : `${formElementSelector}${id}`;
}

if (element.getAttribute('data-block-name')) {
return `.${element.getAttribute('data-block-name')}`;
}

if (Array.from(element.classList).some((className) => className.match(/button|cta/))) {
return blockName ? `.${blockName} .button` : '.button';
}

return sourceselector(element.parentElement);
};

Expand Down

0 comments on commit ce197f5

Please sign in to comment.