Expand my Community achievements bar.

SOLVED

Tag Firing Twice

Avatar

Level 2

Hi all, I'm at my wit's end trying to figure out why a relatively simple tag is firing twice on the page. It's a gtag (google analytics tag) that fires on click of an anchor element with the telephone attribute. (see pictures below)

aksum_0-1679507630573.png

aksum_1-1679507713293.png

This is the script inside of the action 'Tag: GA4 telephone_click event'

try{
var e = this;
let linkText = e.innerText.trim();

let href = e.closest('a').href;

const regex = new RegExp('tel:*')
//capture the url by getting everything AFTER the 'tel:'
const link_url = href.substring(href.indexOf(':') + 1);


if(regex.test(href)){
gtag('event','telephone_click', {
'link_text': linkText || undefined,
'link_url': link_url || undefined
});
}
}
catch(e){
satellite.logger.error('[GA4] telephone_click error: ',e);
}

When I check the network requests and data layer however.. I see the 'telephone_click' event two times. I don't know why this is happening. I'm also including a picture of the html code for an example of an item I'd be clicking.

 

aksum_2-1679507898114.png
After just one click this is how the network request tab looks

aksum_3-1679508050786.png

Any advice or suggestions is very much appreciated. I tried Googling and looking at previous questions in addition to unchecking 'Allow this rule to run even if the event already triggered a rule targeting a descendant element' in the advanced options of the event.

Thank you!

 

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Try logging your "this" object to see what element it's referencing. Hopefully, that gives a clue about what elements the browser is detecting when the user clicks your tel: link.

var e = this;
console.log('this object', e);

// rest of your code

View solution in original post

5 Replies

Avatar

Community Advisor

Does your GA4 property have the Enhanced Measurement tracking enabled? Ref: https://support.google.com/analytics/answer/9216061?hl=en This allows for some user actions to be tracked automatically. If you have it enabled, then I wonder if that's causing the 2nd hit, which would then have nothing to do with your implementation.

Avatar

Level 2

Hi thanks for the response. Yes, I believe the GA4 property has enhanced measurement tracking allowed but I don't think this is the problem since other tags work just fine in the same property.

Avatar

Community Advisor

To eliminate this Enhanced Measurement as the cause, I suggest disabling it in your GA4 property setting, wait a while (to allow GA to update its script), then load your website (preferably in a private window, so that you don't have to deal with previous cache and cookies), then test your tel: link click to see if you still get the double tracking.

Avatar

Level 2

Unfortunately this was not the issue but thanks for the suggestion. (I think your answer has been automatically accepted as the correct answer by Adobe's algorithm since no other answers have been made.)

Avatar

Correct answer by
Community Advisor

Try logging your "this" object to see what element it's referencing. Hopefully, that gives a clue about what elements the browser is detecting when the user clicks your tel: link.

var e = this;
console.log('this object', e);

// rest of your code