Load snippet based on domain name

I am just wondering if there is a more concise / smarter way of doing this. I want a snippet to only load if the domain is the live domain. I have three variables in my config with live, staging and local set. So if the domain contains either staging or local, dont load the snippet. (it contains analytics tracking codes, so dont want false hits).

It seems to work with this:

    if (strpos($url,c::get('staging')) !== false || strpos($url,c::get('local')) !== false ) {
      // Local or staging
    } else {
      // Live

I just cant help thinking theres a better or more accurate way…

Why don’t you use a config.php setting (with a config.php for each server)

c::set('analytics', true); // or false for local and staging

And then just check this setting.

1 Like

Thats so brilliantly simple its made me feel brilliantly stupid for not thinking of it. Thanks :slight_smile: