<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[prototype.berlin - Medium]]></title>
        <description><![CDATA[Um an der Spitze zu bleiben, muss man mit den Schnellsten arbeiten — Von Idee zum AppStore in 6 Wochen. Schnell, effizient und mit Wow. - Medium]]></description>
        <link>https://medium.com/prototype-berlin?source=rss----2132059bc59a---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>prototype.berlin - Medium</title>
            <link>https://medium.com/prototype-berlin?source=rss----2132059bc59a---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 15:59:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/prototype-berlin" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[App Reload in Ionic 3]]></title>
            <link>https://medium.com/prototype-berlin/app-reload-in-ionic-3-d2f870d188c3?source=rss----2132059bc59a---4</link>
            <guid isPermaLink="false">https://medium.com/p/d2f870d188c3</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[ionic]]></category>
            <category><![CDATA[cordova]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Valentin Klinghammer]]></dc:creator>
            <pubDate>Tue, 20 Nov 2018 20:49:36 GMT</pubDate>
            <atom:updated>2018-11-20T20:47:17.417Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ruWpQGmtFdqWQ9yFzVKySg.png" /></figure><h4>Easily manage your app’s lifecycle with a service</h4><h3>Problem</h3><p>Newer mobile devices have more and more memory and use that memory more efficiently. That means, the operating system can keep apps longer active than anticipated. This may lead to weird behavior or stale states within the app, e.g. some content not refreshing after a few days.</p><h3>Solution</h3><p>We want the app to hard reload after a certain amount of time, to ensure a fresh app state when the user is more than likely to have forgotten about the app.</p><h3>Implementation</h3><h4>1. Save a timestamp of the current datetime</h4><p>First, we create a service and add a public method called init. That method will be called from our app.component to initialize the behavior.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ec674979bfa7b27930c4d88f20a69f34/href">https://medium.com/media/ec674979bfa7b27930c4d88f20a69f34/href</a></iframe><p>We’re using our localStorage service from our previous blog post about an <a href="https://medium.com/p/56ec590b96">Ionic 3 localStorage Service</a>.</p><h4>2. Add a resume callback to refresh if necessary</h4><p>We’re using the Ionic Platform provider to subscribe to the resume event. We then retrieve the timestamp from step 1 when the app resumes and check, wether it crossed our threshold.</p><p>If it did cross it, we show the splash screen and do a hard reload.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/11c4cd1a8f1eac6bf55942956a185673/href">https://medium.com/media/11c4cd1a8f1eac6bf55942956a185673/href</a></iframe><p>We’re using our Constants Provider on which we’ll do a separate blog post, C.appReloadThreshold simply contains the threshold in milliseconds after which to reload, e.g. 20*60*60*1000 for 20 minutes.</p><h4>3. Add AppReloadService.init to app.component</h4><p>Now, simply find a place in your app.component to call the init method. There’s usually a lot going on in the app.component of a typical project, but for the AppReloadService it doesn’t really matter.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/97fc34a3d56cc4ef998c89256bbac406/href">https://medium.com/media/97fc34a3d56cc4ef998c89256bbac406/href</a></iframe><h3>Improvements</h3><p>It might make sense to save the time only when actually being put into the background. The way it’s currently implemented may surprise the user who has been using the app for 2 hours and then just quickly switches between apps only to find his data gone.</p><p>I hope, this helps someone!</p><p>Here’s the code of the complete service for easy reference:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/551cc8173ffebf23564c6f2bfd58f086/href">https://medium.com/media/551cc8173ffebf23564c6f2bfd58f086/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d2f870d188c3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/prototype-berlin/app-reload-in-ionic-3-d2f870d188c3">App Reload in Ionic 3</a> was originally published in <a href="https://medium.com/prototype-berlin">prototype.berlin</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ionic 3: Better Dialogs with async/await]]></title>
            <link>https://medium.com/prototype-berlin/ionic-3-better-dialogs-with-async-await-c67fb5423c5f?source=rss----2132059bc59a---4</link>
            <guid isPermaLink="false">https://medium.com/p/c67fb5423c5f</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[ionic]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Manuel Heidrich]]></dc:creator>
            <pubDate>Tue, 04 Sep 2018 08:01:02 GMT</pubDate>
            <atom:updated>2018-09-04T08:01:01.673Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AiCGVT8YAT5LDCd1h13MGQ.jpeg" /></figure><p>When building a mobile app with Ionic there is a good chance you will want to display confirm dialogs to your users to ask them if they really want to do something, for example before logging them out of your application.</p><p>Fortunately Ionic comes with an <a href="https://ionicframework.com/docs/api/components/alert/AlertController/">AlertController</a> that can handle dialogs like alerts, confirms and prompts. Unfortunately, though, the example usage explained in the Ionic docs is kind of clumsy and hard to read. That’s why I decided to develop a better approach. In this post I am going to explain why and how I did that. (tl;dr, just take me to <a href="#38e8">the solution</a>!)</p><p>So let’s look at an example based on the Ionic docs where you ask for confirmation before logging out the user:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/56bc8fecf52943c6ab30e5c3682055f2/href">https://medium.com/media/56bc8fecf52943c6ab30e5c3682055f2/href</a></iframe><p>So this works fine of course, but I think it is not the most beautiful solution.</p><p>Why, you ask?</p><p>You would have to read through lots of lines of code to see what is actually happening when the user confirms the logout. I usually like to split up huge methods into smaller ones, also keeping the <a href="https://en.wikipedia.org/wiki/Separation_of_concerns">separation of concerns</a> principle in mind.</p><p>So what I usually did was splitting up the code into two methods, one responsible for displaying the dialog and one responsible for the actual logout process:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/72ccb486ff1ea4c1bbe38824a12497df/href">https://medium.com/media/72ccb486ff1ea4c1bbe38824a12497df/href</a></iframe><p>That seems better, but the there are still a lot of lines to read until you reach the actual logout method. I also did not like this solution very much because of semantics. The method called logout() does not do the actual logging out and I think a button labeled “Logout” should call a method with a similar name and not something like showLogoutConfirmation().</p><p>So now what?</p><h4>async/await</h4><p>As the post title might reveal my preferred solution is async/await. I had this idea while browsing through the documentation of the upcoming Ionic 4 release where the AlertController will be promisified by default. So why not use this strategy in Ionic 3?</p><p>That’s what I came up with and what I really like using right now for dialogs:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9141569c16b696910fdf9500984ea10e/href">https://medium.com/media/9141569c16b696910fdf9500984ea10e/href</a></iframe><p>We have a method called logout() and one called confirmLogout(). The code is easy to read and each method does exactly what you would expect from their names.</p><p>I hope you like this solution and if you have any ideas or questions, please feel free to comment below!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c67fb5423c5f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/prototype-berlin/ionic-3-better-dialogs-with-async-await-c67fb5423c5f">Ionic 3: Better Dialogs with async/await</a> was originally published in <a href="https://medium.com/prototype-berlin">prototype.berlin</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pagination in LoopBack 3]]></title>
            <link>https://medium.com/prototype-berlin/pagination-in-loopback-3-1cb5e7e7bc20?source=rss----2132059bc59a---4</link>
            <guid isPermaLink="false">https://medium.com/p/1cb5e7e7bc20</guid>
            <category><![CDATA[pagination]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[loopback]]></category>
            <dc:creator><![CDATA[Manuel Heidrich]]></dc:creator>
            <pubDate>Mon, 20 Aug 2018 07:05:28 GMT</pubDate>
            <atom:updated>2018-08-20T07:05:28.025Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zkISXWVieJdfk9DssHJb8w.jpeg" /></figure><p>When developing an application with a LoopBack backend it usually won’t take long until you will need some kind of pagination in your frontend to make long lists of countless items more user-friendly to navigate.</p><p>Thankfully LoopBack has a <a href="https://loopback.io/doc/en/lb3/Skip-filter.html">skip filter</a> and a <a href="https://loopback.io/doc/en/lb3/Limit-filter.html">limit filter</a> which allows us to implement pagination with just using some url parameters. Your first request to fetch the list would contain</p><pre>?filter={“skip”:0,”limit”:10}</pre><p>the next request</p><pre>?filter={“skip”:10,”limit”:10}</pre><p>and so on. This is quite useful!</p><p>However whether you are building a classic pagination with pages, a load more button or even some kind of infinite scrolling you might want to know exactly how many pages there are or how many items there are left to fetch. In this post I will discuss two options to solve this issue: the X-Total-Count header and the <a href="https://www.npmjs.com/package/loopback-paginator">loopback-paginator</a> mixin.</p><p><strong>The X-Total-Count header</strong></p><p>As the headline might suggest one solution would be to add a header to your response that tells you, how much items there are in total. This can easily be done with the following boot script you just have to place into the server/boot directory.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c2cda4fbec472f1f9f9d3d330da45bde/href">https://medium.com/media/c2cda4fbec472f1f9f9d3d330da45bde/href</a></iframe><p>This will automatically intercept all calls for item lists (find) and add the X-Total-Count header to the response. This also takes filters into account. So if you applied a where filter to your request only items that fit your filter will be counted.</p><p>In your frontend you can use that total count to calculate the number of available pages for example or hide the load more button if no more items are available.</p><p><strong>The loopback-paginator</strong></p><p>The second option is to use the <a href="https://www.npmjs.com/package/loopback-paginator">loopback-paginator</a> mixin. (Full disclosure: I’m the author of this mixin which I wrote to have an in my opinion more elegant solution to the pagination problem.) After installing and applying the mixin to your models (check the <a href="https://github.com/prototype-berlin/loopback-paginator#readme">readme</a> to see all available options), the response body of your GET /api/items requests will look slightly different:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e766e2dbb085acfb77db0234ad1e660c/href">https://medium.com/media/e766e2dbb085acfb77db0234ad1e660c/href</a></iframe><p>Instead of an array with all your items the body will contain <strong>data</strong> and <strong>meta</strong>. Data contains the array of items as you are used to and meta contains some helpful information to implement pagination. You will see the total number of items, the total number of available pages, the number of items per page as well as the current, previous and next page (if available). This solution also takes all your applied filters into account.</p><p>I just started working on the paginator last week, but I have some more features in mind and updates will come soon.</p><p>So which solution you want to use is totally up to you. They will both optimise the user experience of your application.</p><p>Have any questions? Want to let me know what you think? Just post a comment below!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1cb5e7e7bc20" width="1" height="1" alt=""><hr><p><a href="https://medium.com/prototype-berlin/pagination-in-loopback-3-1cb5e7e7bc20">Pagination in LoopBack 3</a> was originally published in <a href="https://medium.com/prototype-berlin">prototype.berlin</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[localStorage in Ionic 3]]></title>
            <link>https://medium.com/prototype-berlin/localstorage-in-ionic-3-56ec590b96?source=rss----2132059bc59a---4</link>
            <guid isPermaLink="false">https://medium.com/p/56ec590b96</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[ionic]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Valentin Klinghammer]]></dc:creator>
            <pubDate>Fri, 03 Aug 2018 14:11:19 GMT</pubDate>
            <atom:updated>2018-08-03T14:11:18.957Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ne5bVEWPAGmgm1mUUvinJw.png" /></figure><h4>Multi-project and conflict-free usage of localStorage with a custom provider</h4><h4>Problem</h4><p>Instant preview in the <em>Browser</em> during development through ionic serve is one of the major upside for developers when using <em>Ionic</em> to build apps. But when you work on multiple apps and use <em>localStorage</em> to store things like access tokens and user data, things quickly become difficult to handle. Because during development ionic serves all apps from the same domain, localhost:8000 , there will be a conflict between multiple projects.</p><p>When you try to retrieve a <em>localStorage</em> key called accessToken in <em>Project 2</em> has been previously set by <em>Project 1</em>, strange things will happen if you use it. This means</p><ul><li>having to clear localStorage when working on multiple apps in parallel</li><li>having to clear the app anytime a user changes environments</li></ul><p>This is inconvenient when switching between projects for quick fixes.</p><h4>Solution</h4><p>We will create a <em>Provider</em> that seamlessly uses a prefix for setting and getting localStorage keys. As an additional benefit, the Provider will also handle serialization and deserialization for storing and retrieving Objects.</p><p>The prefix will be project-specific as well as environment specific. We talked about <a href="https://medium.com/prototype-berlin/a-simple-way-to-use-environment-variables-in-ionic-3-12641dc55b55">A Simple Way to Use Environment Variables in Ionic 3</a> in a previous article.</p><h4>Implementation</h4><p><strong>1. Generating a conflict-free localStorage key</strong></p><p>To separate data for each project and each environment, we’ll use a combination of values as the actual localStorage key. So if you build Your Awesome App for the staging environment and want to save the key currentUser, what would be written into the localStorage would look like this: yourawesomeapp-stagingಠ_ಠcurrentUser.</p><p>As covered in the article mentioned above, we use a constants Provider, that would also hold our localStorage key. The relevant part looks like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e6f9598c57f273cc0d0ef5a4234c0eb3/href">https://medium.com/media/e6f9598c57f273cc0d0ef5a4234c0eb3/href</a></iframe><p><strong>2. The localStorage Service</strong></p><p>First, let’s create a basic service that stores the reference to the global localStorage object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9dbb3ed85cc671ae941080de60930072/href">https://medium.com/media/9dbb3ed85cc671ae941080de60930072/href</a></iframe><p>Next, we create a set function that looks at the type of value parameter, automatically stringifying objects.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0f72a15f1f81d85301017ff36121c69/href">https://medium.com/media/b0f72a15f1f81d85301017ff36121c69/href</a></iframe><p>To set a value, use it as this.storageService.set(&#39;currentUser&#39;, { id: 1, name: &#39;Jo&#39; }); after injecting it. This will set the key yourawesomeapp-stagingಠ_ಠcurrentUser.</p><p>Writing is just half of it, next we’ll write our reading method which will retrieve the key and parse them appropriately.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/10d0ed4c9f61f5ab4822ad15d8242f95/href">https://medium.com/media/10d0ed4c9f61f5ab4822ad15d8242f95/href</a></iframe><p>And that’s it. You can use it like this: this.storageService.get(&#39;currentUser&#39;); to retrieve your data and even set a default value as a second parameter: this.storageService.get(&#39;currentUser&#39;, new User());</p><p>Here’s the whole Service for reference, including a delete method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d66cefd352a9ec67d7643cc8627fe70/href">https://medium.com/media/0d66cefd352a9ec67d7643cc8627fe70/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=56ec590b96" width="1" height="1" alt=""><hr><p><a href="https://medium.com/prototype-berlin/localstorage-in-ionic-3-56ec590b96">localStorage in Ionic 3</a> was originally published in <a href="https://medium.com/prototype-berlin">prototype.berlin</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Simple Way to Use Environment Variables in Ionic 3]]></title>
            <link>https://medium.com/prototype-berlin/a-simple-way-to-use-environment-variables-in-ionic-3-12641dc55b55?source=rss----2132059bc59a---4</link>
            <guid isPermaLink="false">https://medium.com/p/12641dc55b55</guid>
            <category><![CDATA[ionic]]></category>
            <category><![CDATA[ionic-framework]]></category>
            <category><![CDATA[cordova]]></category>
            <category><![CDATA[hybrid-app-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Valentin Klinghammer]]></dc:creator>
            <pubDate>Thu, 07 Jun 2018 14:04:55 GMT</pubDate>
            <atom:updated>2018-06-08T14:46:19.094Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4ZOOfC-l-gCaWhK-m65WEw.jpeg" /></figure><h4>Environment variables enable specific configuration</h4><h3>Problem</h3><p>We build a lot of apps for our clients. We also build and deploy the backends for most of those apps. The best practice of using four separate servers emerged. That’s quite a headache to keep straight without automation.</p><p>Our apps must be configurable to point at each of those servers while still allowing to toggle Ionic’s built-in --prod flag.</p><p>An environment variable must switch the following</p><ul><li>hacking Used to develop new backend features locally<br>URLs point to e.g. <a href="http://localhost:3000`">http://localhost:3000</a></li><li>development The default, used by our developers and QA managers<br>URL points to e.g. <a href="https://example-dev.prototype.berlin`/">https://example-dev.prototype.berlin</a></li><li>staging The clients space, always stable, used to test content, etc.<br>URL points to e.g. <a href="https://example-staging.prototype.berlin`/">https://example-staging.prototype.berlin</a></li><li>production URL points to e.g. <a href="https://app.example.com`/">https://app.example.com</a></li></ul><p>We also use the environment variable to</p><ul><li>Decide what log levels to log</li><li>Decide wether to enable analytics/tracking or not</li></ul><h3>Solution</h3><p>What we want to achieve is an interface, similar to Nodejs apps, that works across all Ionic builds and is programmatically accessible within the app.</p><pre>APP_ENV=development ionic serve -b</pre><p>Then we can still do this</p><pre>APP_ENV=production ionic cordova build ios --prod</pre><p>but also leave the--prod flag out for easier debugging while still using the production URL without touching the code, like so</p><pre>APP_ENV=production ionic cordova build ios</pre><p>To achieve that, we will use Ionics configuration to copy a JavaScript file that contains a global variable with the environment info and load that in our index.html.</p><h3>Implementation</h3><h4>Steps</h4><p>1. Create env.js files<br>2. Copy the right env.js file into our build<br>3. Load env.js file<br>4. Profit</p><h4>1. Create env.js files</h4><p>We start off by creating a new folder src/env.For the four environments we typically use, we would create four subfolders and files that will contain our environment info.</p><p>src/env/development/env.js</p><pre>window.ENV = &#39;development&#39;</pre><p>src/env/staging/env.js</p><pre>window.ENV = &#39;staging&#39;;</pre><p>src/env/production/env.js</p><pre>window.ENV = &#39;production&#39;;</pre><p>src/env/hacking/env.js</p><pre>window.ENV = &#39;hacking&#39;;</pre><h4>2. Copy the right env.js file into our build</h4><p>Next we add something at the beginning of Ionics copy config file, you’ll find it here .config/copy.config.js in your project. We also need to adjust the copyIndexContent task to actually copy our file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dfcbe6569e8527c46771dc3d4e287cca/href">https://medium.com/media/dfcbe6569e8527c46771dc3d4e287cca/href</a></iframe><h4>3. Load env.js file</h4><p>This part is almost trivial, we need to load our env.js file in our src/index.html, do it as soon as possible, e.g. right after cordova.js.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7a9b125b63ff9c0de6c24cb8cb069b01/href">https://medium.com/media/7a9b125b63ff9c0de6c24cb8cb069b01/href</a></iframe><h4>4. Profit</h4><p>So… Now what?</p><p>We use a class that provides us with project-wide constants, e.g. URLs. A minimal version of that might look like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5bfa2de485b78d34500d4211b9aff7bc/href">https://medium.com/media/5bfa2de485b78d34500d4211b9aff7bc/href</a></iframe><p>Now you can access the environment you’re running as well as the URLs</p><pre>import { C } from &#39;../shared/constants&#39;;</pre><pre>console.log(C.ENV, C.urls.users);</pre><p>I hope this helps!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=12641dc55b55" width="1" height="1" alt=""><hr><p><a href="https://medium.com/prototype-berlin/a-simple-way-to-use-environment-variables-in-ionic-3-12641dc55b55">A Simple Way to Use Environment Variables in Ionic 3</a> was originally published in <a href="https://medium.com/prototype-berlin">prototype.berlin</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Analytics in Ionic 3: Easily Track Page Views with a Custom Decorator]]></title>
            <link>https://medium.com/prototype-berlin/analytics-in-ionic-3-easily-track-page-views-with-a-custom-decorator-33aa96e5a499?source=rss----2132059bc59a---4</link>
            <guid isPermaLink="false">https://medium.com/p/33aa96e5a499</guid>
            <category><![CDATA[ionic]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[cordova]]></category>
            <category><![CDATA[hybrid-app-development]]></category>
            <dc:creator><![CDATA[Manuel Heidrich]]></dc:creator>
            <pubDate>Thu, 07 Jun 2018 13:49:03 GMT</pubDate>
            <atom:updated>2018-06-08T14:30:49.812Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7HE-Ybeq0-KIcJeIr2wAmQ.jpeg" /></figure><p>If you develop a production Ionic app chances are you also want to integrate some kind of analytics to analyse how your app is being used. There are a lot of different options available like Google Analytics, Firebase or Flurry Analytics, but all they have in common: you have to implement to implement the tracking of your individual views.</p><p>I am usually using <a href="https://ionicframework.com/docs/native/google-analytics/">@ionic-native/google-analytics</a> in my apps and since I did not really want to add this.googleAnalytics.trackView(‘SomePage’) manually to every page I tried different approaches to implement automatic view tracking. What I ended up using is a custom decorator I just need to add to any page I want to track.</p><h3>How does this decorator look like?</h3><p>Glad you asked. Like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/443c5bea4ed273c23482e3012a32467e/href">https://medium.com/media/443c5bea4ed273c23482e3012a32467e/href</a></iframe><p>To use it you have to modify your core module as well. If you don’t have a core module you can just do the same in your app.module.ts. (Don’t forget to change line 3 in page-track.decorator.ts in that case!)</p><p>Core module example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/80a1a045c8e1e6a01c521e3588eb58dd/href">https://medium.com/media/80a1a045c8e1e6a01c521e3588eb58dd/href</a></iframe><p>And now you just have to import and add the PageTrack() decorator to your page component:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b909d41a6f33246c01ef9decb655c45/href">https://medium.com/media/6b909d41a6f33246c01ef9decb655c45/href</a></iframe><p>That’s it!</p><h3><strong>So how does this work?</strong></h3><p>What the page track decorator basically does is publish a ‘view:enter’ event every time a view is being entered which also passes the page name (the name of the page component to be exact).<br>I am using the ionViewDidEnter life cycle event of Ionic to achieve that, but you could also use other events depending on when you want the event to be published.</p><p>So all I have to do is listen to the ‘view:enter’ event in an analytics service for example and do the actual view tracking there:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1e59cdaf46923aceafa22e4f39be86c/href">https://medium.com/media/a1e59cdaf46923aceafa22e4f39be86c/href</a></iframe><p>I think this is a pretty neat way to add page tracking to an Ionic app. What do you think?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33aa96e5a499" width="1" height="1" alt=""><hr><p><a href="https://medium.com/prototype-berlin/analytics-in-ionic-3-easily-track-page-views-with-a-custom-decorator-33aa96e5a499">Analytics in Ionic 3: Easily Track Page Views with a Custom Decorator</a> was originally published in <a href="https://medium.com/prototype-berlin">prototype.berlin</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Simple Logger Service for Ionic 3]]></title>
            <link>https://medium.com/prototype-berlin/building-a-simple-logger-service-for-ionic-3-540d924fe615?source=rss----2132059bc59a---4</link>
            <guid isPermaLink="false">https://medium.com/p/540d924fe615</guid>
            <category><![CDATA[ionic]]></category>
            <category><![CDATA[hybrid-app-development]]></category>
            <category><![CDATA[ionic-framework]]></category>
            <category><![CDATA[cordova]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Manuel Heidrich]]></dc:creator>
            <pubDate>Thu, 07 Jun 2018 13:47:34 GMT</pubDate>
            <atom:updated>2018-06-08T14:53:33.832Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ma3-ciO7SybtCGRMVHwA8A.jpeg" /></figure><p>An Ionic developer’s best friend often are console statements to do some quick debugging or maybe to log the order of Ionic’s lifecycle events. Console output is awesome but you would not want to make this available in a production application as it often displays information not meant so be seen by others than you or your development team. In fact it can pose a security risk.</p><p>It is usually a good idea to remove all console.log, console.warn, console.whatever statements before releasing a production version of your app. So I do not miss any I usually add a <a href="https://palantir.github.io/tslint/rules/no-console/">tslint rule</a> to my tsconfig.json to throw lint errors on all console statements. But who wants to manually remove all console statements before releasing and then adding them again when needed? Nobody I guess.<br>You could add some custom steps to your build process to automatically remove all console statements of course, but a more elegant way I think is a custom logger service.<br>This is why I built a custom logger service that outputs the different log levels depending on the current environment.</p><p>(Also check out this article about the environment switch we use at <a href="https://prototype.berlin/">prototype.berlin</a> to easily switch between different environments when serving or building our Ionic apps.)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4bf3137f2859bf65820e4d750fe4e8c5/href">https://medium.com/media/4bf3137f2859bf65820e4d750fe4e8c5/href</a></iframe><p>The logger service at the moment supports four log levels: debug, info, warning and error. Of course it can be extended with some other common levels like trace or fatal, but those four are what I am usually using.<br>In lines 51 to 54 you can see the environment filter where only errors are allowed when on a production environment, otherwise all outputs are shown. This of course can be extended as well. For example you might have a staging environment where only warnings and errors should be visible.</p><p>After adding the service to the app.module.ts it can be used straight forward like the usual console statements.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e63a5380c621387aecae281b988170f8/href">https://medium.com/media/e63a5380c621387aecae281b988170f8/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XVJ-84rY7kcy800QebE-wQ.png" /><figcaption>Console output of the example service above.</figcaption></figure><p>So if you use console statements a lot — and I do so — this simple logger service can make your life much easier. Just give it a try!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=540d924fe615" width="1" height="1" alt=""><hr><p><a href="https://medium.com/prototype-berlin/building-a-simple-logger-service-for-ionic-3-540d924fe615">Building a Simple Logger Service for Ionic 3</a> was originally published in <a href="https://medium.com/prototype-berlin">prototype.berlin</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>