Problem/Motivation

When deploying sites automatically (eg. using drush) you normally don't use forms to configure things. This means the google tag snippets won't be created.

Proposed resolution

Provide a drush command and/or rebuild the snippets on cache rebuild.

Remaining tasks

(reviews needed, tests to be written or run, documentation to be written, etc.)

User interface changes

None

API changes

A new drush command will be available

Data model changes

None

Comments

casey created an issue. See original summary.

casey’s picture

Issue summary: View changes
marcelovani’s picture

I think a drush command is not the best idea for the following reasons"
1 - We have standard scripts used for deployment, it would not make sense changing the scripts just to run a command that will be used once for a given site
2 - Many people are starting to use Drupal console instead of Drush

I am in favour of having a function that we can call on hook_update or during cache rebuild.

marcelovani’s picture

Status: Active » Needs review
StatusFileSize
new2.49 KB

Created function that is be called on:

  1. Form submit of Google Tag configuration
  2. Hook Cache rebuild

Created function that is be called on:

  1. Form submit of Google Tag configuration
  2. Hook Cache rebuild

google_tag_save_snippets() can be called during deployment via update hooks.

Also, you can write a Drush command or Drupal console command that calls google_tag_save_snippets().

casey’s picture

After some thinking I am not sure whether rebuilding on every cache rebuild is the best way, but it does the job; This would solve automatic deployments (when cache rebuild is not part of a deployment process a custom drush/drupla console command would suffice).

For now I regard this as an acceptable solution. I am curious what solotandem and others think.

cllamas’s picture

Working in my machine as well, I think this solution is acceptable until a better one is found, as at lets makes the module work with automatic deployments, which a majority of people use.

cllamas’s picture

I've found a problem when deploying a new site it can't find the public://js folder therefor it flags an error when saving the js snippet files.

Working in a solution

dmsmidt’s picture

StatusFileSize
new4.68 KB
new3.8 KB

Here is a patch that fixes the problem mentioned in #7.
And it allows people to disable recreating the snippets.
This can be done via the UI or in settings.php.

cburschka’s picture

Status: Needs review » Needs work

The newly added rebuild_snippets setting needs to be declared in the schema as well.

Otherwise, this patch works.

cburschka’s picture

Status: Needs work » Needs review
StatusFileSize
new5.16 KB
new485 bytes
geertvd’s picture

StatusFileSize
new5.08 KB

Reroll

fago’s picture

Title: (Re)create snippets from commandline and/or cache rebuild » Warnings when snippets files are missing - create them automatically
Category: Feature request » Bug report
Priority: Normal » Major
StatusFileSize
new3.83 KB

I ran into a related issue on a site, where the module was installed via configuration sync. The files were missing, what lead to some empty page attachment being added to the site, consequently leading to quite ugly warnings and an empty tag being shown every page.

While it would be possible to create the files during a config sync, this would not work for cases where you installed the site from a dump or the files are missing for some other reason. That said, I think they should be just re-created when needed just as the aggregated js files. This solves the issue while making the command and cache-rebuild features unnecessary - it just works. That seems better, not? :)

Attached patch solves the problem for me and works if files are suddenly missing.

  • solotandem committed 413c3b5 on 8.x-1.x
    Issue #2843994 by marcelovani, dmsmidt, cburschka, geertvd, solotandem:...
solotandem’s picture

Assigned: Unassigned » solotandem
Status: Needs review » Fixed

Thanks to all for the input.

gro’s picture

StatusFileSize
new3.88 KB

Re-rolled #12 for latest 8.x-dev (commit 09ce10cf)

gro’s picture

StatusFileSize
new4.03 KB

Fixes patch from https://www.drupal.org/node/2843994#comment-12135228 by removing duplicate declaration of hook_rebuild.

gro’s picture

Status: Fixed » Closed (fixed)

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

dakwamine’s picture

StatusFileSize
new3.99 KB

Using the #16 patch, I had a 404 on the generated files because the module points on /sites/[site_name]/files/google_tag/[generated_files] but the patch creates the files at /sites/[site_name]/files/js/[generated_files].

I have added a patch with the paths which worked for me.