Skip to content

Instantly share code, notes, and snippets.

@Dan0sz
Last active January 3, 2020 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dan0sz/f443af12f2790f65850cb38ad18c3ca1 to your computer and use it in GitHub Desktop.
Save Dan0sz/f443af12f2790f65850cb38ad18c3ca1 to your computer and use it in GitHub Desktop.
Add Google Optimize to CAOS
<?php
/**
* @formatter:off
* Plugin Name: Google Optimize for CAOS
* Plugin URI: https://daan.dev/google-optimize-caos/
* Description: Add Google Optimize for CAOS in gtag.js
* Version: 1.0.0
* Author: Daan van den Bergh
* Author URI: https://daan.dev
* License: GPL2v2 or later
* @formatter:on
*/
if (!defined('ABSPATH')) {
exit;
}
/**
* Replace 'YOUR-OPTIMIZE-CONTAINER-ID' with, well, your optimize container id.
*/
function caos_google_optimize()
{
$optimizeId = 'YOUR-OPTIMIZE-CONTAINER-ID';
if (CAOS_OPT_REMOTE_JS_FILE == 'gtag.js') {
add_filter(
'caos_gtag_config', function ($config, $trackingId) use ($optimizeId) {
return $config + array('optimize_id' => $optimizeId);
}, 10, 2
);
}
}
add_action('caos_process_settings', 'caos_google_optimize');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment