<?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[Stories by Michael Agustian on Medium]]></title>
        <description><![CDATA[Stories by Michael Agustian on Medium]]></description>
        <link>https://medium.com/@michaelian12?source=rss-97a5dae07422------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*MZ__Q39XTvlqqdoMjSYPIw.jpeg</url>
            <title>Stories by Michael Agustian on Medium</title>
            <link>https://medium.com/@michaelian12?source=rss-97a5dae07422------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 23:05:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@michaelian12/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Sustainable Native Firebase Analytics Event Logging from Mobile Web View]]></title>
            <link>https://medium.com/bliblidotcom-techblog/sustainable-native-firebase-analytics-event-logging-from-mobile-web-view-774fd4d7a5a7?source=rss-97a5dae07422------2</link>
            <guid isPermaLink="false">https://medium.com/p/774fd4d7a5a7</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[web]]></category>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[tracking]]></category>
            <dc:creator><![CDATA[Michael Agustian]]></dc:creator>
            <pubDate>Fri, 29 Jan 2021 06:53:34 GMT</pubDate>
            <atom:updated>2021-01-29T06:53:34.429Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zLvkIIJY5b62HRNe" /><figcaption>Photo by <a href="https://unsplash.com/@lukechesser?utm_source=medium&amp;utm_medium=referral">Luke Chesser</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>We want to see events that occur from the mobile web view as events from the mobile app. In order to log analytic events from within mobile web view, we need to forward the events to native code before they can be sent to app reports in Firebase Analytics. So the Web App and the Mobile App teams needs to work together to achieve this.</p><h3>Current Situation</h3><p><strong>The Web App and the Mobile App teams have their own respective data structure for the analytics events</strong>, we call it as <strong><em>“contract”</em></strong>. For example, let’s say we want to know what products is being viewed by our user</p><p>The Web App contract is created in JSON and looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/563848cf34cd150297121803c58a244c/href">https://medium.com/media/563848cf34cd150297121803c58a244c/href</a></iframe><p>That’s the contract that will be passed to our native code and we need to map it to fit our Mobile App contract. Since we used Firebase Analytics, then the Mobile app contract (which is obviously the params that we’ll pass) is look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b95da0a98eb6a805715be141e1081737/href">https://medium.com/media/b95da0a98eb6a805715be141e1081737/href</a></iframe><h3>The Considerations</h3><p>In the creation, we as a Mobile App team considering several things in case we make a change in the future, such as:</p><ol><li>What if there is a need to make a change in the future from Mobile App side? Such as adding new params for example.<br><em>Piece of cake, just update the code and deploy the new version of the app</em> ❌ <br><strong>We don’t want to release a new version of the app just only for updating the analytics events, </strong>and it leads to the second question.</li><li>How to keep the previous version of our Mobile App stay up to date when there is a code change? <br><em>Mmmmmmm…. make sure there is no update </em>🙃 ❌<br><strong>We want to keep the current and future versions of our Mobile App have the same action and behaviour in logging the analytics events</strong>.</li><li>What if the Web App contract is change?<br><em>uuhh it’s a nightmare, if the Web App contract is changed then the previous version of the Mobile App will no longer work as expected. We need a code change to map it to Mobile App contract </em>😰❌ <br><strong>We want our mapper code can be changed easily without the need for updating the Mobile App.</strong></li></ol><h3>The Solution</h3><p>Usually, the Web App will pass the Web Contract to the Mobile App using JavaScript, then we will map the Web Contract in native code so it fit to the Mobile Contract, then log that Mobile Contract to the Firebase Analytics.</p><p>Web App → Mobile App → Firebase</p><p>But, we will <strong>separate the contract mapping code not as a native code and put it on the cloud to fulfil our considerations above</strong>. The contract mapper code will be built in JavaScript, so it can be consumed by both Android and iOS. The plus is that we only need to code once and have one actual source code. So the data flow will look like this:</p><p>Web App → Mobile App → <strong><em>Contract Mapper Code → Mobile App</em></strong> → Firebase</p><blockquote>Please note that I will provide an example implementation for iOS, but the concept will remain the same for Android.</blockquote><h3>Passing the Event</h3><p>First we need a JavaScript function in the web view to pass the event to the native code. Let’s say it looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/66024064425315afed9216284e2ba346/href">https://medium.com/media/66024064425315afed9216284e2ba346/href</a></iframe><h3>Catch the Event</h3><p>In our native iOS code, we need to implement the WKScriptMessageHandler protocol in our class to catch the Web Contract that passed by the JavaScript function in the web view, then we decode it as JSON string and pass it to our contract mapper code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/32870cb4650856fd989909a0903bdc81/href">https://medium.com/media/32870cb4650856fd989909a0903bdc81/href</a></iframe><h3>Map the Analytics Event</h3><p>We will map it as a JSON string and we build it to form like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/691ca34b29f1439a1d5a9c90914db428/href">https://medium.com/media/691ca34b29f1439a1d5a9c90914db428/href</a></iframe><p>Here we map the Web Contract in JavaScript so it’s suits our Mobile Contract and pass it back to our mobile app.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/282bb231c49ca27f6f8edb1765b8e81c/href">https://medium.com/media/282bb231c49ca27f6f8edb1765b8e81c/href</a></iframe><p>This form will make it dynamic if we want to add some new params, we just need to use a for loop to add params to the analytics events.</p><h3>Log the Analytics Event</h3><p>And last we need to update our native iOS code to catch our Mobile Contract and make log for the analytics event.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0db8884c7b92add9027838666d004b7/href">https://medium.com/media/b0db8884c7b92add9027838666d004b7/href</a></iframe><p>That’s it! Tell me your thought about this, if you want to correct me somewhere or maybe there is another effective way other than this feel free to write some response, cheers! 🥂</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=774fd4d7a5a7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bliblidotcom-techblog/sustainable-native-firebase-analytics-event-logging-from-mobile-web-view-774fd4d7a5a7">Sustainable Native Firebase Analytics Event Logging from Mobile Web View</a> was originally published in <a href="https://medium.com/bliblidotcom-techblog">Blibli.com Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Handle (parsing) dynamic JSON response in Swift]]></title>
            <link>https://medium.com/bliblidotcom-techblog/handle-parsing-dynamic-json-response-in-swift-741f8ddf2eeb?source=rss-97a5dae07422------2</link>
            <guid isPermaLink="false">https://medium.com/p/741f8ddf2eeb</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[parsing]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[json]]></category>
            <dc:creator><![CDATA[Michael Agustian]]></dc:creator>
            <pubDate>Mon, 03 Feb 2020 03:30:53 GMT</pubDate>
            <atom:updated>2020-02-04T08:11:49.047Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*srurjLeA2_pkvhI9" /><figcaption>Photo by <a href="https://unsplash.com/@olav_ahrens?utm_source=medium&amp;utm_medium=referral">Olav Ahrens Røtne</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I got a New Year’s eve “present” on December 30, 2019. Well it’s still too early even for New Year’s eve.</p><h3><strong>The “Present”</strong></h3><p>I’m facing with a dynamic JSON response from <strong><em>one same API call</em></strong>, something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d3ea2530acba5fe615a30957bd10b858/href">https://medium.com/media/d3ea2530acba5fe615a30957bd10b858/href</a></iframe><p>And sometimes like this when it has no result:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/46626ddf8a510db5ef3407bdb0a11008/href">https://medium.com/media/46626ddf8a510db5ef3407bdb0a11008/href</a></iframe><p>As you can see the value for <strong>“result”</strong> property can be an <strong>Object </strong>or a <strong>String</strong>. Your problem could be more than these two data types, maybe three, four, or more data types.</p><blockquote><em>“That is an unpredictable result because we got it from an API call”</em></blockquote><h3>Current Situation</h3><p>Currently, we use the <strong>Codable </strong>to parse the JSON to its respective model. And we have the <strong>Response</strong> struct with <a href="https://docs.swift.org/swift-book/LanguageGuide/Generics.html"><strong>Generics</strong></a><strong> </strong>so it can be used by another API calls like so:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e0f7fbe05a0d8e1b59e9bd98534ed37d/href">https://medium.com/media/e0f7fbe05a0d8e1b59e9bd98534ed37d/href</a></iframe><h3>The Question?</h3><p>But how we can determine the <a href="https://docs.swift.org/swift-book/LanguageGuide/Generics.html"><strong>Generics</strong></a><strong> </strong>when we try to <a href="https://developer.apple.com/documentation/foundation/jsondecoder"><strong>decode</strong></a><strong> </strong>the JSON, since the return is unpredictable?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/559685506e091ccd6bdd0ce7b4eba5a3/href">https://medium.com/media/559685506e091ccd6bdd0ce7b4eba5a3/href</a></iframe><h3>Solve The Problem</h3><p>We can make a <strong>Codable Enum</strong> representing those data types, like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e4d5c5605edc8b5967031ee0f6e29409/href">https://medium.com/media/e4d5c5605edc8b5967031ee0f6e29409/href</a></iframe><p>And when it comes to the decode, we can parse it like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6966e3e06d1f5c1a843158c2fbc3f570/href">https://medium.com/media/6966e3e06d1f5c1a843158c2fbc3f570/href</a></iframe><p>That’s it! Tell me your thought about this, if you want to correct me somewhere or maybe there is another effective way other than this feel free to write some response, cheers! 🥂</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=741f8ddf2eeb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bliblidotcom-techblog/handle-parsing-dynamic-json-response-in-swift-741f8ddf2eeb">Handle (parsing) dynamic JSON response in Swift</a> was originally published in <a href="https://medium.com/bliblidotcom-techblog">Blibli.com Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>