Creating apps with a complex business logic
Jul 28, 2017 · 2 min read
Recently, I was a bit stuck while developing an app with a complicated logic. In my case it was a javascript app to send data to Google Analytics. It turned out what I need was a right approach
Here are the steps I used to break down the app logic
- Write a description in one sentence like this:
This library sends data to GA containing time it took for a user to complete a certain workflow. - Create Basic Scenarios. Something along these lines:
1. User goes to initial page of the workflow. The script creates a new time entry for an id in local storage
2. User goes to any intermediate page in the workflow. The script adds additional time to existing entry in local storage
3. User ends up on a last page of the workflow. The script sends data with total time spent to GA and deletes local storage keys for this id - Write what the main functions of the app will do like so:
main(flow object)
1. Create storage name in this format ‘userTimings_someWorkflow_123’
2. If flow object has property category then its a final page in the workflow, then call pushToDataLayer function
3. Delete storageName from localStorage
onPageLeave(storage name, new time)
Add storage name (localStorage userTimings_someWorkflow_123: ‘13494’)
pushToDatalayer(storage name)
1. Push to dataLayer.
2. Delete storageName from local storage
Optionally you can also add usage instructions like this
1. Include this library
2. If its not the last page in workflow then add this to your script:
my_library.main({flow: ‘myFlow’, id: ‘123’})
If it is the last page in workflow then add this:
my_library.main({flow: ‘myFlow’, id: ‘123’, category: ‘My Cool App Workflow’})
