Problem/Motivation

VWO code is meant to be loaded in the head.

This should also allow VWO to detect the code inserted into the correct location.

Steps to reproduce

Install the module and use as is.

Proposed resolution

Use contrib module https://www.drupal.org/project/attachinline to allow inline js in head

Remaining tasks

- test this works
- make this a dependency
- move all variables and content back into inline, removing settings array/behaviour

User interface changes

n/a

API changes

n/a

Data model changes

n/a

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

grasmash created an issue. See original summary.

elc’s picture

Status: Active » Needs review

Needs review by an active user of the module to confirm this does not adversely effect anything. It should effectively be a transparent change. Including in had is also one of the specifications for adding VWO code.

I would expect this should be an included change.

One possible issue would be access to the drupal settings since these are usually included later in the page. Although this may be why #3184848: Fix broken drupalSettings is also needed.

The JS was originally included in the head by using an inline js include but this is not available in D8 yet as per #2391025: Add support for inline JS/CSS with #attached. The use of a library was included later on.

elc’s picture

After reading up on drupal behaviours as in #3184848: Fix broken drupalSettings in combination with this change, I'm concerned that neither of them should be included.

This patch is adding the VWO code to the head instead of the footer. It still needs variables from settings which appear to be only available in footer.

The 3184848 patch then converts the existing JS into a behaviour which are then only run at the end of the page load.

These changes together appear to make zero different to the functionality of the module or when the JS is run. It still runs at the end of the DOM fully loading. What is needed to make it run early is inline js include, which is still an outstanding issue on core.

Could anyone please confirm this is what is happening?

elc’s picture

Issue summary: View changes

Contrib module to add inline js in head.

https://www.drupal.org/project/attachinline

- test this works
- make this a dependency
- move all variables and content back into inline, removing settings array/behaviour

This core issue should be marked as closed: #2391025: Add support for inline JS/CSS with #attached

elc’s picture

Status: Needs review » Needs work

Change to issue status.

  • ELC committed 7444117b on 8.x-1.x
    [#3186631] Add VWO SmartCode to head.
    
elc’s picture

Status: Needs work » Fixed

Available in dev package, or next release as 8.x-1.3, perhaps as RC1.

  • ELC committed 4de308bd on 8.x-1.x
    [#3186631] Use EventSubscriber to add JS to head. Remove old method.
    

  • ELC committed 67d84593 on 8.x-1.x
    [#3186631] Remove unused library.
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.