question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Custom Usage Data" script only extract the first data

See original GitHub issue

Hi,

I stumbled or a detail in the Custom Usage Data-example.

In the settings of “Can I use” it is possible to import multiple sources. If for example I first import data by geography and afterwards via Analytics.

The content of localStorage[“usage-data-by-id”] looks similar to this:

{
  "region.DE": {
    "name": "Germany",
    "id": "DE",
    "type": "region",
    "source": "statcounter",
    "dataByBrowser": {
      "SHORTEN": "..."
    },
    "meta": {
      "access_date": "2018-02-05",
      "month": "2018-01"
    },
    "uid": "region.DE"
  },
  "custom.6543947|undefined": {
    "name": "www.example.de",
    "id": "6543947|undefined",
    "type": "custom",
    "source": "google_analytics",
    "dataByBrowser": {
      "SHORTEN": "..."
    },
    "meta": {
      "start_date": "2018-01-24",
      "end_date": "2018-02-22"
    },
    "uid": "custom.6543947|undefined"
  }
}

In this case the example script for extracting the JSON from the local storage only saves the first key. In my example the imported data from the country.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
jstrangfeldcommented, Feb 26, 2018

LGTM. I wasn’t aware of the structure of the localStorage being different. This simple UI is going to make the download process much easier! Good work!

1reaction
vaxulcommented, Feb 26, 2018

PR ready.

Source:

javascript:(function(){
	var data = JSON.parse(localStorage['usage-data-by-id']),
		backdrop = document.createElement('div');
		parent = document.createElement('div');

	backdrop.setAttribute('style', 'background:rgba(0,0,0,.5);display:flex;justify-content:center;align-items:center;position:fixed;top:0;right:0;bottom:0;left:0;z-index:10');
	parent.setAttribute('style', 'background:#fff;color:#000;padding:50px;top:0;left:0');
	
	for(var dataKey in data){
		var link=document.createElement("a");
		
		link.setAttribute("style", "display:block;margin:10px 0");
		link.setAttribute("download", "browserslist-stats.json");
		link.setAttribute("href", "data:text/plain;charset=utf-8," + encodeURIComponent(JSON.stringify(data[dataKey])));
		link.innerHTML='Get data: ' + data[dataKey].name;
		
		parent.appendChild(link);
		
		link.addEventListener('click', function() {
			document.body.removeChild(backdrop);
		});
	}
	
	document.body.appendChild(backdrop);
	backdrop.appendChild(parent);
	backdrop.addEventListener('click', function() {
		document.body.removeChild(backdrop);
	});
})();
Read more comments on GitHub >

github_iconTop Results From Across the Web

Extract Data to CSV but only need first 4 characters - Powershell
It's called Calculated Properties, and you use it like so. Now, simply pipe that into your Export-Csv command and you're done.
Read more >
Extract column information using the Extract function in Power BI
In this article, you will see how to use the Extract function in Power BI to extract information from columns in a Power...
Read more >
Extract data from Google Sheets cells: text, numbers, URLs ...
Take out different types of data from Google Sheets cells: text from strings or by position, first/last N chars, numbers, links & URLs...
Read more >
EXTRACT Expression (U-SQL) - Microsoft Learn
See usage in next section, below. Extracts first and last names as separate columns using the custom extractor defined above. c# code is...
Read more >
What is Data Extraction? Data Extraction Tools & Techniques
The first time you replicate any source, you must do a full extraction. Some data sources have no way to identify data that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found