Block GA4 tag from firing in extension

Bronze Contributor
Bronze Contributor

Hello, I would like to code an extension such as under a certain condition, it will change the base_url, otherwise it will block the ga4 tag from firing.

I don't know what to write in the "else" statement

var ga4_tag_id = 4;
if(b['visitor_customer_id'] && utag.sender[ga4_tag_id]){
    u.data.base_url = "new_url"
} else{
   ...
}
1 REPLY 1

Block GA4 tag from firing in extension

Gold Contributor
Gold Contributor

In the "else" statement, you can write the following code:

Code snippet
utag.sender[ga4_tag_id].enabled = false;
 

This code will disable the GA4 tag from firing.

Here is an explanation of the code:

  • The utag.sender[ga4_tag_id] object represents the GA4 tag.
  • The enabled property of the utag.sender[ga4_tag_id] object controls whether the tag is enabled.
  • Setting the enabled property to false will disable the tag from firing.

Here is the complete code:

Code snippet
var ga4_tag_id = 4;
if(b['visitor_customer_id'] && utag.sender[ga4_tag_id]){
    u.data.base_url = "new_url"
} else{
    utag.sender[ga4_tag_id].enabled = false;
}

I hope this helps! Let me know if you have any other questions.

shivam joshi
Public