<@U07FJ89LFFB> I've noticed that I'm sending GA4 e...
# ask-ai
w
@brash-pillow-71627 I've noticed that I'm sending GA4 events with the tracking script even if I don't have any experiments live. Is there a way to prevent this from happening?
o
A message from kapa.ai
Yes, you can control when and how the events are sent to GA4 by customizing the tracking callback in your GrowthBook setup. The tracking callback is a function that gets called whenever an experiment is viewed. If you don't want to send events when there are no live experiments, you can add a condition in this callback to check if there are any active experiments before sending the event. Here is an example of how you can define a custom tracking callback:
Copy code
javascript GROWTHBOOK_TRACKING_CALLBACK="(experiment, results) => {    if (/* condition to check if there are active experiments */) {     console.log('browser tracking callback', {experiment, results});    } }"
In the above code, replace
/* condition to check if there are active experiments */
with your actual condition. This will ensure that the tracking callback (and thus the GA4 event) is only triggered when there are active experiments. Please note that the exact condition will depend on how you are managing and checking the status of your experiments. You might need to refer to your experiment management system or GrowthBook's API to determine whether there are any active experiments. For more information on tracking callbacks and how to customize them, you can refer to the [GrowthBook documentation](https://docs.growthbook.io/lib/edge/other#tracking-experiment-views).