diff --git a/packages/javascript-sdk/src/tracking/autocapture.ts b/packages/javascript-sdk/src/tracking/autocapture.ts index e349f31..846abc2 100644 --- a/packages/javascript-sdk/src/tracking/autocapture.ts +++ b/packages/javascript-sdk/src/tracking/autocapture.ts @@ -159,7 +159,8 @@ class AutoCapture { private getElementsJson(targetElementList: Element[], e: Event): any[] { const elementsJson: any[] = []; - let href; + let href: false | string | null = null; + let explicitNoCapture = false; _each(targetElementList, (el) => { if (isTag(el, 'a')) { @@ -167,6 +168,12 @@ class AutoCapture { href = shouldCaptureElement(el) && shouldCaptureValue(href) && href; } + // Check for 'ph-no-capture' class + const classes = getClassName(el).split(' '); + if (_includes(classes, 'ph-no-capture')) { + explicitNoCapture = true; + } + elementsJson.push(this.getPropertiesFromElement(el)); }); @@ -178,7 +185,7 @@ class AutoCapture { elementsJson[0]['attr__href'] = this.sanitizeUrl(href); } - return elementsJson; + return explicitNoCapture ? [] : elementsJson; } private getPropertiesFromElement(element: Element): any {