3

What I am trying to accomplish:

Why:

  • To create a Rich Card showcased in the SERP

Problem:

When trying to create a User-Defined Variable as well as the script used by the Tag itself. When utilizing the Preview and Debug feature of GTM. I receive the following error:

this language feature is only supported for ECMASCRIPT6 mode or better: let declaration. Use --language_in=ECMASCRIPT6 or ECMASCRIPT6_STRICT to enable ES6 features.

I understand... or at least I think I understand that I need to tell the compiler to

Use --language_in=ECMASCRIPT6 or ECMASCRIPT6_STRICT

But how do I accomplish this?

<script>
(function(){
// ==ClosureCompiler==
// @compilation_level SIMPLE_OPTIMIZATIONS
// @output_file_name default.js
// @language_in=ECMASCRIPT6_STRICT;
// @language_out=ES5_STRICT;
 // ==/ClosureCompiler==

 "use strict";
  let data = {
  "@context": "http://schema.org",
  "@type": "MovingCompany",
  "name": "WDA Movers",
  "logo" : {
    "@type" : "ImageObject",
    "url" : "http://wda-moving.online/images/logo.jpg",
    "height" : 435,
    "width" : 361      
  },
  "address": {
    "@type": "PostalAddress",
    "addressLocality": "Eugene",
    "addressRegion": "OR",
    "postalCode": "97404",
    "streetAddress": "411 Heywood Avenue"
  },
  "openingHours": "Mo-Su 7:00-23:30",
  "priceRange": "$$$",
  "telephone": "(541) 255-9876",
  "url": "http://wda-moving.online",
  "sameAs" : [
    "https://www.facebook.com/wda.movers/",
    "https://plus.google.com/+WDAMoversEugene/about?gmbpt=true&hl=en"
  ],
  "aggregateRating": {
    "@type": "AggregateRating",
    "ratingValue": {{YELP_rating}},
    "reviewCount": {{YELP_review_count}},
    "bestRating": "5",
    "worstRating": "1"
  },
  "review": {
"@type" : "Review",
"author" : {{YELP_reviews_user_name}},
"reviewBody" : {{YELP_reviews_excerpt}},
"reviewRating" : {
    "@type": "Rating",
    "ratingValue": {{YELP_reviews_rating}}
    }
   }
 }
 let richCard = document.createElement('script');
 richCard.type = "application/ld+json";
 richCard.innerHTML = JSON.stringify(data);
 document.getElementsByTagName('head')[0].appendChild(richCard);
 })(document);
 </script>

As you can see I've tried adding the following to the script above:

// ==ClosureCompiler==
// @compilation_level SIMPLE_OPTIMIZATIONS
// @output_file_name default.js
// @language_in=ECMASCRIPT6_STRICT;
// @language_out=ES5_STRICT;
// ==/ClosureCompiler==

"use strict";

This did not work... can anyone help me?

1 Answer 1

6

If you take a look at the asset-pipeline plugin, you will find the following example for build.gradle:

assets {
    minifyJs = true
    minifyCss = true
    enableSourceMaps = true
    configOptions = [:]

    minifyOptions = [
        languageMode: 'ES5',
        targetLanguage: 'ES5', //Can go from ES6 to ES5 for those bleeding edgers
        optimizationLevel: 'SIMPLE',
        angularPass: true // Can use @ngInject annotation for Angular Apps
    ]
    // ... snip ...
}

When I set languageMode in the minifyOptions to 'ES6', the errors disappear and the correct JavaScript is served on deployment. You could of course also set assets.minifyJs to false for the same effect.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.