You are here

function abjs_preprocess_html in A/B Test JS 7

Implements hook_preprocess_html().

Outputs testing javascript for all valid and active tests inline at top of scripts via drupal_add_js.

File

./abjs.module, line 192
Define permissions and admin form paths, and write test JavaScript.

Code

function abjs_preprocess_html(&$vars) {
  if (path_is_admin(current_path())) {
    return;
  }

  // Get all active tests that have at least one experience.
  $test_results = db_query("SELECT DISTINCT t.tid FROM {abjs_test} AS t LEFT JOIN {abjs_test_condition} AS tc ON t.tid = tc.tid INNER JOIN {abjs_test_experience} AS te ON t.tid = te.tid WHERE t.active=1");
  $tests = $test_results
    ->fetchAll();

  // At least one test with at least one condition and at least one experience.
  // must be active for any script to be added to the page. Because of this,
  // we don't need a similar check later for conditions and experiences
  // individually.
  if (empty($tests)) {
    return;
  }

  // The following section prints out javascript objects for the active tests,
  // conditions, and experiences.
  $abjs_script = abjs_generate_js($tests);

  // Outputting javascript inline above other scripts for fastest execution.
  // Group is set to -1000 to output before JS_LIBRARY (which is -100). Note
  // that there are no dependencies for this JavaScript. Use hook_js_alter to
  // alter loading order.
  drupal_add_js($abjs_script, array(
    'type' => 'inline',
    'scope' => 'header',
    'group' => -1000,
  ));
}