Forum for discussing general topics related to Couch.
7 posts Page 1 of 1
How do you skip adding the google analytics-snippet when you are developing?
One way of doing this is to define a K_LIVE constant in couch/config.php

Code: Select all
define( ‘K_LIVE’, ‘0’ );

Then, in couch/addons/kfunctions.php, use Couch’s $CTX class to set a global variable according to your new config constant.

Code: Select all
$CTX->set(‘k_live’, K_LIVE, ‘global’);

That will give you a k_live variable to use in your project. For instance:

Code: Select all

<head>

  <cms:if k_live>
    // show Google Analytics snippet
  </cms:if>

</head>

@mwlarkin1, perhaps <cms:smart_embed> can be used and with analytics code set aside in a snippet e.g. /snippets/production/google-analytics/default.inc
Code: Select all
<cms:smart_embed 'production/google-analytics' >

Its advantage over the sibling tag cms:embed is no warning in case "default.inc" snippet is missing (will be present only in production environment).
Interesting @trendoman! I didn’t realize <cms:smart_embed /> had that feature.

I never use smart embed because the codebase I work from relies on custom routes, but I may need to revise it now so I can make use of smart embed, as I do like the option of returning nothing instead of an error.

Thanks for the tip!
You are welcome) I am PMing you a mod for smart_embed which makes it even more practical and usable.
mwlarkin1 wrote: One way of doing this is to define a K_LIVE constant in couch/config.php

Code: Select all
define( ‘K_LIVE’, ‘0’ );

Then, in couch/addons/kfunctions.php, use Couch’s $CTX class to set a global variable according to your new config constant.

Code: Select all
$CTX->set(‘k_live’, K_LIVE, ‘global’);

That will give you a k_live variable to use in your project. For instance:

Code: Select all

<head>

  <cms:if k_live>
    // show Google Analytics snippet
  </cms:if>

</head>



Thank you for this solution! Works perfect for me. Much apreciated!
trendoman wrote: @mwlarkin1, perhaps <cms:smart_embed> can be used and with analytics code set aside in a snippet e.g. /snippets/production/google-analytics/default.inc
Code: Select all
<cms:smart_embed 'production/google-analytics' >

Its advantage over the sibling tag cms:embed is no warning in case "default.inc" snippet is missing (will be present only in production environment).


This one is a bit over my current level, i think, but i'll surely check into this tag in the future. CouchCMS sure is full of great surprices! Thank you!
7 posts Page 1 of 1