Abstract adding of VWO into pages, into their own functions.

Created on 23 February 2014, almost 11 years ago
Updated 30 November 2023, about 1 year ago

I have some pages I want to add VWO for.

These urls are my node URL's but have some query strings appended to them like

http://www.website.tld/sometype/the-node-123?help=review

VWO uses drupal_match_path() to include the JS, thus I can't use /node/*?help=review since only the path and not the query string are used when creating for matches.

So I'd like to do this myself in a page alter.

The problem is, there's not a function in the code I can call, to include the javascript.

So I would recommend pulling those peices of code, into their own functions, or even better, a single function with an argument (sync vs async)

would look something like this


function visual_website_optimizer_add_js($synctype = NULL) {
  static $already_added = 0;
  if($already_added) { return; }
  
  if(empty($synctype)) {
    $settings = array_merge(
    _visual_website_optimizer_settings_defaults(),
    variable_get('visual_website_optimizer_settings', array())
  );
   $synctype = $settings['synctype'];
  }
  if($synctype == 'async') {
  drupal_add_js(/*The async stuff*/);
  $already_added = 1;
  }
  else if($synctype == 'sync') {
  drupal_add_js(/*The sync stuff*/); 
  $already_added = 1;
  }
}

📌 Task
Status

Fixed

Version

1.0

Component

Code

Created by

🇨🇦Canada j0rd

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024