{"id":957,"date":"2019-02-07T15:14:07","date_gmt":"2019-02-07T12:14:07","guid":{"rendered":"https:\/\/global.bg\/en\/?p=957"},"modified":"2019-02-07T16:38:33","modified_gmt":"2019-02-07T13:38:33","slug":"a-way-to-hook-to-the-initialization-of-the-angular-application-part-i","status":"publish","type":"post","link":"http:\/\/global.bg\/en\/a-way-to-hook-to-the-initialization-of-the-angular-application-part-i\/","title":{"rendered":"Download of a third-party JavaScript library and a way to &#8220;hook&#8221; to the initialization of the Angular application. Example with Analytics.js. Part One."},"content":{"rendered":"\n<p>For a while, in my professional work, I have been developing software applications using <em>Angular<\/em>. In a few cases I have faced questions about how one or another thing could be achieved and I have not found a quick and unambiguous answer for myself. In this post I will discuss two interesting topics of this nature:<\/p>\n\n\n\n<ol><li>How\ndynamically, from <em>Angular<\/em>, to\n&#8220;download&#8221; in the app third-party JavaScript libraries<\/li><li>How to\n&#8220;hook&#8221; to the initialization process of an <em>Angular<\/em> application and run our own script<\/li><\/ol>\n\n\n\n<p>For illustration purposes I have written a sample application that I will quote in several places in the post.<\/p>\n\n\n\n<p>The code for the\nexample application is available at: <a href=\"https:\/\/github.com\/agyonov\/NgInitGA\">https:\/\/github.com\/agyonov\/NgInitGA<\/a><\/p>\n\n\n\n<p>The app itself is live on: <a href=\"https:\/\/agyonov.github.io\/NgInitGA\">https:\/\/agyonov.github.io\/NgInitGA<\/a><\/p>\n\n\n\n<h2 style=\"text-align:center\">Dynamic download of a third-party\nJavaScript library<\/h2>\n\n\n\n<p>For most libraries that you would like to use, someone has already created, developed and maintains a NPM package with the relevant <em>Angular<\/em> modules and you could (and should) use them. But sometimes there is no ready NPM package or you may not like the one that is available. In this case you can directly reference the requested JavaScript library from your <em>Angular<\/em> application and use it.<\/p>\n\n\n\n<p>There are two easy approaches that are described in the <em>Angular<\/em> documentation and, for example, in <em>Google Analytics<\/em>. And which don&#8217;t always do the job for one reason or another.<\/p>\n\n\n\n<ol><li><strong>The first<\/strong>, entirely <em>Angular<\/em>, solution is to download the corresponding .js file from the Internet. Add it to your project and place a reference to the .js library in the scripts array, in the <em>angular.json<\/em> config file. E.g:<\/li><\/ol>\n\n\n<pre class=\"prettyprint\"><code class=\"language-ts\">\n\u2026\n\"scripts\": [\n              \"src\/scripts\/analytics.js\"\n            ]\n\u2026\n<\/code><\/pre>\n\n\n<p>This is described in detail in the <a href=\"https:\/\/angular.io\/guide\/workspace-config#additional-build-and-test-options\">documentation of <em>Angular<\/em><\/a>. <\/p>\n\n\n\n<p>It&#8217;s an OK approach and will work.<\/p>\n\n\n\n<p><strong>A consideration<\/strong> against its possible use is that under this approach is that the .js script will be download from your hosting server and not from the original server (in this case <a href=\"https:\/\/www.google-analytics.com\/analytics.js\">https:\/\/www.google-analytics.com\/analytics.js<\/a>). And the question is not so much in increased traffic to your site and performance issues, but in that the author of the library (Google) could change things in it, have new versions, etc., and you will not have this new version until you re-build and re-publish your app.<\/p>\n\n\n\n<p style=\"text-align:left\">       2<strong> . The second<\/strong> approach is to apply the instruction on the <em><a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/analyticsjs\/#alternative_async_tracking_snippet\">Google    Analytics page<\/a><\/em>: <\/p>\n\n\n<pre class=\"prettyprint\"><code class=\"language-html\">\n&lt;script&gt;\nwindow.ga=window.ga || function(){(ga.q=ga.q||[]).push(arguments)};\nga.l=+new Date;\nga('create', 'UA-XXXXX-Y', 'auto');\nga('send', 'pageview');\n&lt;\/script&gt;\n&lt;script async src='https:\/\/www.google-analytics.com\/analytics.js'&gt;\n&lt;\/script&gt;\n<\/code><\/pre>\n\n\n<p><\/p>\n\n\n\n<p>And the above code to be\npasted directly into the <em>index.html<\/em>\nfile initializing your <em>Angular<\/em>\napplication. <strong>In particular, the last\nline of the above sample code.<\/strong><\/p>\n\n\n\n<p>It&#8217;s OK as an approach and will also work in <strong>its part to download the .js library<\/strong>. In addition, the objections which were valid for the first decision are irrelevant.<\/p>\n\n\n\n<p style=\"text-align:center\"><strong>A consideration<\/strong> against its possible use is stylistic \u2013 it is not a &#8220;clean&#8221; <em>Angular<\/em> solution.<\/p>\n\n\n\n<p>The rest of the code snip from <em>Google Analytics<\/em>, shown above, <strong>does not work for us at all<\/strong>! Because with <em>Angular<\/em> we have a <strong>Single Page Application<\/strong> (SPA) where, unlike traditional web applications, in reality only the first page is loaded from the Web server and subsequently every transition from page to page, occurs only inside the SPA application in the browser. Also, if we have any special events (e.g. button press) they as well occur inside the <em>Angular<\/em> app and will not affect the data in <em>Google Analytics<\/em>.<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/global.bg\/en\/wp-content\/uploads\/2019\/02\/image-2.png\" alt=\"\" class=\"wp-image-960\" width=\"834\" height=\"396\" srcset=\"http:\/\/global.bg\/en\/wp-content\/uploads\/2019\/02\/image-2.png 437w, http:\/\/global.bg\/en\/wp-content\/uploads\/2019\/02\/image-2-300x143.png 300w, http:\/\/global.bg\/en\/wp-content\/uploads\/2019\/02\/image-2-24x11.png 24w, http:\/\/global.bg\/en\/wp-content\/uploads\/2019\/02\/image-2-36x17.png 36w, http:\/\/global.bg\/en\/wp-content\/uploads\/2019\/02\/image-2-48x23.png 48w\" sizes=\"(max-width: 834px) 100vw, 834px\" \/><\/figure>\n\n\n\n<p>These issues are discussed in detail in the <em>Google Analytics<\/em> documentation itself under the <a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/analyticsjs\/single-page-applications\">Single Page Application Tracking<\/a> topic.<\/p>\n\n\n\n<p>          3. Let&#8217;s get back to the issue with the dynamic download of the JavaScript library. <strong>There is a third <\/strong>method that I will look at. Because the example is using <em>Google Analytics<\/em>, I&#8217;ll expand it to be used to track users\u2019 actions in the <em>Angular<\/em> app.<\/p>\n\n\n\n<p style=\"text-align:center\"><strong>Note<\/strong>: As for tracking of users in <em>Angular<\/em> application, it has great, ready-made libraries, such as <a href=\"https:\/\/github.com\/angulartics\/angulartics2\">angulartics2<\/a>, which you can use. Here the question is not to create another such library, but to illustrate with an example a possible solution to the two questions set at the beginning of this post!<\/p>\n\n\n\n<p>So, the dynamic download. Let us see a sample of the following <em>Angular<\/em> service:<\/p>\n\n\n<pre class=\"prettyprint\"><code class=\"language-ts\">\n\u2026\n\/\/ Typescript extention of Window interface\ndeclare global {\n  interface Window { ga: any; }\n}\n\n@Injectable({\n  providedIn: 'root'\n})\nexport class GoogleAnalyticsService {\n\n  \/\/ The source for the load\n  private googleAnalyticsScript= {\n    loaded: false,\n    url: 'https:\/\/www.google-analytics.com\/analytics.js'\n  };\n\n  constructor(@Inject(PLATFORM_ID) private platformId: Object,\n    @Inject(DOCUMENT) private dom: Document) {\n  }\n\u2026\n  \/\/ Init the GA infrastructure\n  public loadScript(): void {\n    \/\/ Check already loaded\n    if (!this.googleAnalyticsScript.loaded) {\n      \/\/ Check if we are at browser\n      if (isPlatformBrowser(this.platformId)) {\n        \/\/ Create new scipt element\n        const scriptElm: HTMLScriptElement = this.dom.createElement('script');\n        scriptElm.src = this.googleAnalyticsScript.url;\n        scriptElm.type = 'text\/javascript';\n        scriptElm.async = true;\n        scriptElm.onload = () =&gt; {\n          \/\/ Prevent from load second time\n          this.googleAnalyticsScript.loaded = true;\n        };\n\n        \/\/ Define GA object\n        window.ga = window.ga || function () { (window.ga.q = window.ga.q || []).push(arguments); };\n        window.ga.l = +new Date;\n\n        \/\/ Set some Google Analytics stuff\n        window.ga('create', environment.propertyID, 'auto');\n\n        \/\/ Add to document\n        this.dom.body.appendChild(scriptElm);\n      }\n    }\n  }\n}\n<\/code><\/pre>\n\n\n<p>Basically, it&#8217;s a\ntranscription in <em>TypeScript<\/em>, of the\ninstructions from the <em>Google Analytics<\/em>\npage, which we have above. The important points are:<\/p>\n\n\n\n<ul><li>Only in the beginning we expand the <em>TypeScript <strong>Window<\/strong><\/em> interface with a new field-&#8216;ga&#8217;<\/li><li>In the <em>&#8216;loadScript&#8217;<\/em> method, the actual work is done:<ul><li>A <em>scriptElm<\/em> script element is created and is dynamically added to the DOM of the Web page. It&#8217;s the same as putting:<\/li><\/ul><\/li><\/ul>\n\n\n<pre class=\"prettyprint\"><code class=\"language-html\">&lt;script async src='https:\/\/www.google-analytics.com\/analytics.js'&gt;&lt;\/script&gt;<\/code><\/pre>\n\n\n<p>in\n<em>index.html<\/em>.<\/p>\n\n\n\n<ul><li>Definition of the &#8216;ga&#8217; field with which the <strong><em>Window<\/em><\/strong> interface is expanded, as specified by <em>Google Analytics<\/em>. It&#8217;s the same as putting:<\/li><\/ul>\n\n\n<pre class=\"prettyprint\"><code class=\"language-html\">&lt;script&gt;\nwindow.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};\nga.l=+new Date;\nga('create', 'UA-XXXXX-Y', 'auto');\n&lt;\/script&gt;\n\n<\/code><\/pre>\n\n\n<p>in <em>index.html<\/em>.<\/p>\n\n\n\n<p>And voila!<\/p>\n\n\n\n<p>\ud83d\ude0a well not quite&#8230; Still, the &#8216;<em>loadScript<\/em>&#8216; method should be invoked,\nsomewhere from the <em>Angular<\/em>\napplication and cause the browser to start the download of the JavaScript\nlibrary. And here we come to the second question:<\/p>\n\n\n\n<h2>How to \u201cHook\u201d to the initializing of an Angular application<\/h2>\n\n\n\n<p>But this post is already a bit long. I guess it&#8217;s time to finish this first part. For &#8220;hooking&#8221; to the initialization of the Angular application, check \u00a0part two.<\/p>\n\n\n\n<p>Author: Aleksandar Gyonov<\/p>\n\n\n\n<p><strong><em>Stay tuned for Part 2!<\/em><\/strong><\/p>\n\n\n<p><script src=\"https:\/\/cdn.rawgit.com\/google\/code-prettify\/master\/loader\/run_prettify.js?skin=sons-of-obsidian\"><\/script><\/p>\n<p><!-- \/wp:paragraph --><\/p>","protected":false},"excerpt":{"rendered":"<p>For a while, in my professional work, I have been developing software applications using Angular. In a few cases I have faced questions about how one or another thing could be achieved and I have not found a quick and unambiguous answer for myself. In this post I will discuss two interesting topics of this [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":978,"comment_status":"closed","ping_status":"closed","sticky":true,"template":"","format":"standard","meta":{"_et_pb_use_builder":"off","_et_pb_old_content":"<!-- wp:paragraph -->\n<p>For a while, in my\nprofessional work, I have been developing software applications using <em>Angular<\/em>. In a few cases I have faced\nquestions about how one or other thing could have happened and I have not found\na quick and unambiguous answer for myself. In this post I will discuss two\ninteresting things of this nature:<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:list {\"ordered\":true} -->\n<ol><li>How\ndynamically, from <em>Angular<\/em>, to\n\"download\" in the app third-party JavaScript libraries<\/li><li>How to\n\"hook\" to the initialization process of an <em>Angular<\/em> application and run our own script<\/li><\/ol>\n<!-- \/wp:list -->\n\n<!-- wp:paragraph -->\n<p>For illustration I\nhave written a sample application that I will quote in several places in the\npost.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>The code for the\nexample application is available at: <a href=\"https:\/\/github.com\/agyonov\/NgInitGA\">https:\/\/github.com\/agyonov\/NgInitGA<\/a><\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>The app itself is live on: <a href=\"https:\/\/agyonov.github.io\/NgInitGA\">https:\/\/agyonov.github.io\/NgInitGA<\/a><\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:heading -->\n<h2>Dynamic download of a third-party\nJavaScript library<\/h2>\n<!-- \/wp:heading -->\n\n<!-- wp:paragraph -->\n<p>For most libraries\nthat you would like to use, someone has already created, developed and maintains\nan NPM package with the relevant <em>Angular<\/em>\nmodules and you could (and should) use them. But sometimes there is no ready\nNPM package or you do not like one that is available. Then you can directly reference\nthe requested JavaScript library from your <em>Angular<\/em>\napplication and use it.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>There are two easy\napproaches that are described in the <em>Angular<\/em>\ndocumentation and, for example, in <em>Google\nAnalytics<\/em>. And which don't always do the work for one reason or another.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p><strong>The first<\/strong>, entirely <em>Angular<\/em>, solution is to download the corresponding .js file from the Internet. Add it to your project and place a reference to the .js library in the scripts array, in the <em>angular.json<\/em> config file. E.g:<\/p>\n<!-- \/wp:paragraph -->\n\n<pre class=\"prettyprint\"><code class=\"language-ts\">\n\u2026\n\"scripts\": [\n              \"src\/scripts\/analytics.js\"\n            ]\n\u2026\n<\/code><\/pre>\n\n<!-- wp:paragraph -->\n<p>As described in detail\nin the documentation of <em>Angular<\/em>, at <a href=\"https:\/\/angular.io\/guide\/workspace-config%23additional-build-and-test-options\">https:\/\/angular.io\/guide\/workspace-config#additional-build-and-test-options<\/a>.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>It's OK as an approach\nand will work.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p><strong>A consideration<\/strong> against its possible use is that under this\napproach is that the .js script will be download from your hosting server and\nnot from the original server (in this case <a href=\"https:\/\/www.google-analytics.com\/analytics.js\">https:\/\/www.google-analytics.com\/analytics.js<\/a>). And the question is not so much in increased\ntraffic to your site and performance issues, but in that the author of the\nlibrary (Google) could change things in it, have new versions, etc., and you\nwill not have this new version until you re-build and do not re-publish your\napp.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p><strong>The second<\/strong> approach is to apply the instruction on the <em>Google Analytics<\/em> page (<a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/analyticsjs\/%23alternative_async_tracking_snippet\">https:\/\/developers.google.com\/analytics\/devguides\/collection\/analyticsjs\/#alternative_async_tracking_snippet<\/a>):<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:image {\"id\":959} -->\n<figure class=\"wp-block-image\"><img src=\"https:\/\/global.bg\/en\/wp-content\/uploads\/2019\/02\/image-1.png\" alt=\"\" class=\"wp-image-959\"\/><\/figure>\n<!-- \/wp:image -->\n\n<!-- wp:paragraph -->\n<p>And the above code to be\npasted directly into the <em>index.html<\/em>\nfile initializing your <em>Angular<\/em>\napplication. <strong>In particular, the last\nline of the above sample code.<\/strong><\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>It's OK as an approach\nand will also work in <strong>its part to\ndownload the .js library<\/strong>. In addition, here the objections which were valid\nfor the first decision are irrelevant.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p><strong>A consideration<\/strong> against its possible use is stylistic \u2013 not a\n\"clean\" <em>Angular<\/em> solution.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>The rest of the code snip from <em>Google Analytics<\/em>, shown above, <strong>does not work for us at all<\/strong>! Because with <em>Angular<\/em> we have a <strong>Single page Application<\/strong> (SPA) where, unlike traditional web applications, in reality only the first page is loaded from the Web server and subsequently every transition from page to page, occurs only inside the SPA application in the browser. Also, if we have any special events (e.g. button press) they as well occur inside the <em>Angular<\/em> app and will not affect the data in <em>Google Analytics<\/em>.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:image {\"id\":960} -->\n<figure class=\"wp-block-image\"><img src=\"https:\/\/global.bg\/en\/wp-content\/uploads\/2019\/02\/image-2.png\" alt=\"\" class=\"wp-image-960\"\/><\/figure>\n<!-- \/wp:image -->\n\n<!-- wp:paragraph -->\n<p>These issues are\ndiscussed in detail in the <em>Google\nAnalytics<\/em> documentation itself under the <a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/analyticsjs\/single-page-applications\">Single Page Application Tracking<\/a> theme.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>Let's get back to the\nissue with the dynamic download of the JavaScript library. <strong>There is a third way<\/strong> that I will look at. Because the example is\nusing <em>Google Analytics<\/em>, I'll expand\nit to be used to track users\u2019 actions in the <em>Angular<\/em> app.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p><strong>NB<\/strong>: As for tracking of users in <em>Angular<\/em> application, it has great,\nready-made libraries, such as <a href=\"https:\/\/github.com\/angulartics\/angulartics2\">angulartics2<\/a>, which you can use. Here the question is not\nto create another such library, but with an example to show a possible solution\nto the two questions set at the beginning of this post!<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>So, the dynamic download. Let us see a sample of the following <em>Angular<\/em> service:<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:image {\"id\":961} -->\n<figure class=\"wp-block-image\"><img src=\"https:\/\/global.bg\/en\/wp-content\/uploads\/2019\/02\/image-3.png\" alt=\"\" class=\"wp-image-961\"\/><\/figure>\n<!-- \/wp:image -->\n\n<p><script src=\"https:\/\/cdn.rawgit.com\/google\/code-prettify\/master\/loader\/run_prettify.js?skin=desert\"><\/script><\/p>","_et_gb_content_width":"","inline_featured_image":false},"categories":[41],"tags":[61,63,60,59,62,51],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>A way to &quot;hook&quot; to the initialization of the Angular application! Part I<\/title>\n<meta name=\"description\" content=\"GLOBAL CONSULTING - Download of a third-party JavaScript library and a way to &quot;hook&quot; to the initialization of the Angular application. Example with Analytics.js. Part One.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/global.bg\/en\/a-way-to-hook-to-the-initialization-of-the-angular-application-part-i\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"A way to &quot;hook&quot; to the initialization of the Angular application! Part I\" \/>\n<meta property=\"og:description\" content=\"GLOBAL CONSULTING - Download of a third-party JavaScript library and a way to &quot;hook&quot; to the initialization of the Angular application. Example with Analytics.js. Part One.\" \/>\n<meta property=\"og:url\" content=\"http:\/\/global.bg\/en\/a-way-to-hook-to-the-initialization-of-the-angular-application-part-i\/\" \/>\n<meta property=\"og:site_name\" content=\"GLOBAL CONSULTING\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/global.bg\/\" \/>\n<meta property=\"article:published_time\" content=\"2019-02-07T12:14:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-02-07T13:38:33+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/global.bg\/en\/wp-content\/uploads\/2019\/02\/maxresdefault-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"576\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"alext\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@GlobalConsult19\" \/>\n<meta name=\"twitter:site\" content=\"@GlobalConsult19\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"alext\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\/\/global.bg\/en\/a-way-to-hook-to-the-initialization-of-the-angular-application-part-i\/#article\",\"isPartOf\":{\"@id\":\"http:\/\/global.bg\/en\/a-way-to-hook-to-the-initialization-of-the-angular-application-part-i\/\"},\"author\":{\"name\":\"alext\",\"@id\":\"https:\/\/global.bg\/en\/#\/schema\/person\/f1d3ed6545a59e4ff50f600b1f54d565\"},\"headline\":\"Download of a third-party JavaScript library and a way to &#8220;hook&#8221; to the initialization of the Angular application. Example with Analytics.js. Part One.\",\"datePublished\":\"2019-02-07T12:14:07+00:00\",\"dateModified\":\"2019-02-07T13:38:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/global.bg\/en\/a-way-to-hook-to-the-initialization-of-the-angular-application-part-i\/\"},\"wordCount\":882,\"publisher\":{\"@id\":\"https:\/\/global.bg\/en\/#organization\"},\"keywords\":[\"Aleksandar Gyonov\",\"Analytics\",\"Angular\",\"JavaScript\",\"js\",\"part 1\"],\"articleSection\":[\"Articles\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/global.bg\/en\/a-way-to-hook-to-the-initialization-of-the-angular-application-part-i\/\",\"url\":\"http:\/\/global.bg\/en\/a-way-to-hook-to-the-initialization-of-the-angular-application-part-i\/\",\"name\":\"A way to \\\"hook\\\" to the initialization of the Angular application! Part I\",\"isPartOf\":{\"@id\":\"https:\/\/global.bg\/en\/#website\"},\"datePublished\":\"2019-02-07T12:14:07+00:00\",\"dateModified\":\"2019-02-07T13:38:33+00:00\",\"description\":\"GLOBAL CONSULTING - Download of a third-party JavaScript library and a way to \\\"hook\\\" to the initialization of the Angular application. Example with Analytics.js. Part One.\",\"breadcrumb\":{\"@id\":\"http:\/\/global.bg\/en\/a-way-to-hook-to-the-initialization-of-the-angular-application-part-i\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/global.bg\/en\/a-way-to-hook-to-the-initialization-of-the-angular-application-part-i\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/global.bg\/en\/a-way-to-hook-to-the-initialization-of-the-angular-application-part-i\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/global.bg\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Download of a third-party JavaScript library and a way to &#8220;hook&#8221; to the initialization of the Angular application. Example with Analytics.js. Part One.\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/global.bg\/en\/#website\",\"url\":\"https:\/\/global.bg\/en\/\",\"name\":\"GLOBAL CONSULTING\",\"description\":\"Make IT Global\",\"publisher\":{\"@id\":\"https:\/\/global.bg\/en\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/global.bg\/en\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/global.bg\/en\/#organization\",\"name\":\"Global Consulting Ltd | Make IT Global\",\"url\":\"https:\/\/global.bg\/en\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/global.bg\/en\/#\/schema\/logo\/image\/\",\"url\":\"http:\/\/global.bg\/en\/wp-content\/uploads\/2017\/08\/GCPrimaryLogoHorizontalPositive-1.svg\",\"contentUrl\":\"http:\/\/global.bg\/en\/wp-content\/uploads\/2017\/08\/GCPrimaryLogoHorizontalPositive-1.svg\",\"caption\":\"Global Consulting Ltd | Make IT Global\"},\"image\":{\"@id\":\"https:\/\/global.bg\/en\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.linkedin.com\/company\/global-consulting-ltd\/\",\"https:\/\/www.facebook.com\/global.bg\/\",\"https:\/\/twitter.com\/GlobalConsult19\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/global.bg\/en\/#\/schema\/person\/f1d3ed6545a59e4ff50f600b1f54d565\",\"name\":\"alext\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/global.bg\/en\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/1.gravatar.com\/avatar\/dcefe2e0f629ed86ee7022824f7266b1?s=96&d=mm&r=g\",\"contentUrl\":\"http:\/\/1.gravatar.com\/avatar\/dcefe2e0f629ed86ee7022824f7266b1?s=96&d=mm&r=g\",\"caption\":\"alext\"},\"url\":\"http:\/\/global.bg\/en\/author\/alext\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"A way to \"hook\" to the initialization of the Angular application! Part I","description":"GLOBAL CONSULTING - Download of a third-party JavaScript library and a way to \"hook\" to the initialization of the Angular application. Example with Analytics.js. Part One.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/global.bg\/en\/a-way-to-hook-to-the-initialization-of-the-angular-application-part-i\/","og_locale":"en_US","og_type":"article","og_title":"A way to \"hook\" to the initialization of the Angular application! Part I","og_description":"GLOBAL CONSULTING - Download of a third-party JavaScript library and a way to \"hook\" to the initialization of the Angular application. Example with Analytics.js. Part One.","og_url":"http:\/\/global.bg\/en\/a-way-to-hook-to-the-initialization-of-the-angular-application-part-i\/","og_site_name":"GLOBAL CONSULTING","article_publisher":"https:\/\/www.facebook.com\/global.bg\/","article_published_time":"2019-02-07T12:14:07+00:00","article_modified_time":"2019-02-07T13:38:33+00:00","og_image":[{"width":1024,"height":576,"url":"http:\/\/global.bg\/en\/wp-content\/uploads\/2019\/02\/maxresdefault-1.jpg","type":"image\/jpeg"}],"author":"alext","twitter_card":"summary_large_image","twitter_creator":"@GlobalConsult19","twitter_site":"@GlobalConsult19","twitter_misc":{"Written by":"alext","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/global.bg\/en\/a-way-to-hook-to-the-initialization-of-the-angular-application-part-i\/#article","isPartOf":{"@id":"http:\/\/global.bg\/en\/a-way-to-hook-to-the-initialization-of-the-angular-application-part-i\/"},"author":{"name":"alext","@id":"https:\/\/global.bg\/en\/#\/schema\/person\/f1d3ed6545a59e4ff50f600b1f54d565"},"headline":"Download of a third-party JavaScript library and a way to &#8220;hook&#8221; to the initialization of the Angular application. Example with Analytics.js. Part One.","datePublished":"2019-02-07T12:14:07+00:00","dateModified":"2019-02-07T13:38:33+00:00","mainEntityOfPage":{"@id":"http:\/\/global.bg\/en\/a-way-to-hook-to-the-initialization-of-the-angular-application-part-i\/"},"wordCount":882,"publisher":{"@id":"https:\/\/global.bg\/en\/#organization"},"keywords":["Aleksandar Gyonov","Analytics","Angular","JavaScript","js","part 1"],"articleSection":["Articles"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"http:\/\/global.bg\/en\/a-way-to-hook-to-the-initialization-of-the-angular-application-part-i\/","url":"http:\/\/global.bg\/en\/a-way-to-hook-to-the-initialization-of-the-angular-application-part-i\/","name":"A way to \"hook\" to the initialization of the Angular application! Part I","isPartOf":{"@id":"https:\/\/global.bg\/en\/#website"},"datePublished":"2019-02-07T12:14:07+00:00","dateModified":"2019-02-07T13:38:33+00:00","description":"GLOBAL CONSULTING - Download of a third-party JavaScript library and a way to \"hook\" to the initialization of the Angular application. Example with Analytics.js. Part One.","breadcrumb":{"@id":"http:\/\/global.bg\/en\/a-way-to-hook-to-the-initialization-of-the-angular-application-part-i\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/global.bg\/en\/a-way-to-hook-to-the-initialization-of-the-angular-application-part-i\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/global.bg\/en\/a-way-to-hook-to-the-initialization-of-the-angular-application-part-i\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/global.bg\/en\/"},{"@type":"ListItem","position":2,"name":"Download of a third-party JavaScript library and a way to &#8220;hook&#8221; to the initialization of the Angular application. Example with Analytics.js. Part One."}]},{"@type":"WebSite","@id":"https:\/\/global.bg\/en\/#website","url":"https:\/\/global.bg\/en\/","name":"GLOBAL CONSULTING","description":"Make IT Global","publisher":{"@id":"https:\/\/global.bg\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/global.bg\/en\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/global.bg\/en\/#organization","name":"Global Consulting Ltd | Make IT Global","url":"https:\/\/global.bg\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/global.bg\/en\/#\/schema\/logo\/image\/","url":"http:\/\/global.bg\/en\/wp-content\/uploads\/2017\/08\/GCPrimaryLogoHorizontalPositive-1.svg","contentUrl":"http:\/\/global.bg\/en\/wp-content\/uploads\/2017\/08\/GCPrimaryLogoHorizontalPositive-1.svg","caption":"Global Consulting Ltd | Make IT Global"},"image":{"@id":"https:\/\/global.bg\/en\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.linkedin.com\/company\/global-consulting-ltd\/","https:\/\/www.facebook.com\/global.bg\/","https:\/\/twitter.com\/GlobalConsult19"]},{"@type":"Person","@id":"https:\/\/global.bg\/en\/#\/schema\/person\/f1d3ed6545a59e4ff50f600b1f54d565","name":"alext","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/global.bg\/en\/#\/schema\/person\/image\/","url":"http:\/\/1.gravatar.com\/avatar\/dcefe2e0f629ed86ee7022824f7266b1?s=96&d=mm&r=g","contentUrl":"http:\/\/1.gravatar.com\/avatar\/dcefe2e0f629ed86ee7022824f7266b1?s=96&d=mm&r=g","caption":"alext"},"url":"http:\/\/global.bg\/en\/author\/alext\/"}]}},"_links":{"self":[{"href":"http:\/\/global.bg\/en\/wp-json\/wp\/v2\/posts\/957"}],"collection":[{"href":"http:\/\/global.bg\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/global.bg\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/global.bg\/en\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/global.bg\/en\/wp-json\/wp\/v2\/comments?post=957"}],"version-history":[{"count":19,"href":"http:\/\/global.bg\/en\/wp-json\/wp\/v2\/posts\/957\/revisions"}],"predecessor-version":[{"id":982,"href":"http:\/\/global.bg\/en\/wp-json\/wp\/v2\/posts\/957\/revisions\/982"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/global.bg\/en\/wp-json\/wp\/v2\/media\/978"}],"wp:attachment":[{"href":"http:\/\/global.bg\/en\/wp-json\/wp\/v2\/media?parent=957"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/global.bg\/en\/wp-json\/wp\/v2\/categories?post=957"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/global.bg\/en\/wp-json\/wp\/v2\/tags?post=957"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}