On the Modifications tab, I have had some very good luck with the Experimental Settings/"Move Google Analytics analytics.js code from inline to be a file". I use the Google Analytics and Commerce Google Analytics modules and my data capture has been perfect, and PageSpeed Insights is no longer yelling at me to Leverage Browser Caching.

So then I added the Facebook Pixel module as well. Much like the problem I had before with my Analytics tracking code, PageSpeed Insights is once again telling me:

Leverage Browser Caching for the following resources:
https://connect.facebook.net/en_US/fbevents.js (20 minutes)
https://connect.facebook.net/…signals/config/1961054097462651?v=2.7.16 (20 minutes)

So.......
Question 1) Why is the modification "Move Google Analytics analytics.js code from inline to be a file" still considered an "Experimental Setting"? I've been using it for nearly a year through several version releases of Advagg and it's worked smoothly. Are there people out there who are having trouble with it still or some other issue?

Question 2) How hard would it be to implement a similar functionality for Facebook Pixel tracking codes? I feel like the two tracking codes function in a similar way. Could this be implemented for the Facebook Pixel tracking codes?

Question 3) On a broader scale, there are probably other tracking codes besides these two that get used on various sites. Rather than a script-specific implementation, how hard would it be to make a general option to select which scripts to move from inline to be files?

I'm not a developer and I only have some very basic programming skills, so I don't know what the scope of something like this would be. Still, if the maintainer decides to work on this and there is something I can do to help, just ask. :)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

TynanFox created an issue. See original summary.

mikeytown2’s picture

I might want to move it out into the relocation sub module. It's already inlineing google fonts, doing the same for JS makes sense. FB has a really short TTL (20 min) so it's a little bit harder to do in comparison to GA but should be possible.

mikeytown2’s picture

Inline GA code without script loader
(function(i,s,o,r){i["GoogleAnalyticsObject"]=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date()})(window,document,"script","ga");ga("create", "UA-XXXXXXX-X", {"cookieDomain":"auto"});ga("set", "anonymizeIp", true);ga("send", "pageview");

mikeytown2’s picture

Title: Aggregate Facebook Pixel » Aggregate External JS
Component: Modifier » Relocate
Status: Active » Needs review
FileSize
15.31 KB

No UI, no control, proof on concept code.

Status: Needs review » Needs work

The last submitted patch, 5: advagg-2886940-5-pull-external-js-local.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mikeytown2’s picture

Status: Needs work » Needs review
FileSize
16.49 KB

Status: Needs review » Needs work

The last submitted patch, 7: advagg-2886940-7-pull-external-js-local.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mikeytown2’s picture

Status: Needs work » Needs review
FileSize
16.58 KB

Status: Needs review » Needs work

The last submitted patch, 9: advagg-2886940-9-pull-external-js-local.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mikeytown2’s picture

Status: Needs work » Needs review
FileSize
16.58 KB

Status: Needs review » Needs work

The last submitted patch, 11: advagg-2886940-11-pull-external-js-local.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mikeytown2’s picture

Status: Needs work » Needs review
FileSize
16.6 KB
mikeytown2’s picture

Still need to handle @import statements for external CSS files, better code doc, put in a UI, and merge duplicate functionality. Looking good though.

@import needs to use

  $contents = preg_replace_callback('%@import\s*+(?:url\(\s*+)?+[\'"]?+(?![a-z]++:|/)([^\'"()\s]++)[\'"]?+\s*+\)?+\s*+;%i', '_advagg_load_stylesheet', $contents);

with a different _advagg_load_stylesheet() function.

mikeytown2’s picture

Title: Aggregate External JS » Aggregate External CSS & JS
FileSize
22.81 KB

Got this working with import now. Still need code doc, move code to .inc, UI for control, and merge duplicate functionality. Also need to keep #2889776: Remove no longer needed dns-prefetch and preconnect link tags in mind. Should also check if fonts loaded via deep import statements are handled. Need to try drupal_http_request again on failure.

Appears that there is a bug with nested import statements... might be core related.

Quick testing code

  drupal_static_reset('drupal_add_css');
  drupal_static_reset('drupal_add_js');
  drupal_add_css($GLOBALS['base_url'] . '/sites/all/modules/advagg/tests/css_test_files/css_input_with_import.css', array('type' => 'external'));
  $variables = array();
  _advagg_process_html($variables);
  $a = explode('link type="text/css" rel="stylesheet" href="', $variables['styles']);
  $c = array();
  foreach ($a as $b) {
    $z = explode('" media="all" />', $b);
    if (count($z) > 1) {
      $c[] = str_replace($GLOBALS['base_path'], $GLOBALS['base_url'] . '/', $z[0]);
    }
  }
  echo httprl_pr($c);
mikeytown2’s picture

Functionally it's there. UI is there, but not really plugged in the code; need to add in the states array as well. Look into merging duplicate code functionality.

mikeytown2’s picture

UI needs states array; need to pass variables into the $aggregate_settings array.

mikeytown2’s picture

Should be good to go.

  • mikeytown2 committed 5532c46 on 7.x-2.x
    Issue #2886940 by mikeytown2: Aggregate External CSS & JS
    
mikeytown2’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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

TynanFox’s picture

Dude, MikeyTown, you're a machine. :)
Thanks for this!

mikeytown2’s picture

You're welcome! Let me know how it works for you. The Facebook pixel code was quite difficult to pull off, but I have it working on our site; getting a 100/100 on google page speed when using google analytics & tag manager as well as FB pixel https://developers.google.com/speed/pagespeed/insights/?utm_source=analy...