I have issue in firebase firestore snapshot with limit and pagination - firebase

I am working with Firestore right now and have a little bit of a problem with pagination.
Basically, I have a collection (assume 10 items) where each item has some data and a timestamp.
and First 10 items get with snapshot orderBy(createdAt ,desc) after that I take one variable as a last record and i used it in another query as a startAfter clouse but when I add new record then first item is removed
if we have one array in that we have 1 to 50 items then on the first time i get 10 item with snapshot like 1 to 10 and If I add new item then 1 is remove and new item is pushed in array and if I clicked on load more button then in the list i saw 1 is removed
how can I solve this problem?
EX.
In firebase collection Array = [2,3,4,1,8,7,6,9,5,10,13,12,14,11,16,17,18,20,15,19]
first snapshot with order by createdAt desc and limit 5 I get and I also use docChange() method in snapshot
16
17
18
19
20
after i clciked on Load More this is get() method same as above limit ,orderBy and startAfter then I get
11
12
13
.
.
.
20
if i add 21 then I get
11
12
13
14
15
17
18
19
20
21
after reload I get it back in perfact order
My Tasks are:
1.Delete items from array with real time upsdate
2.Edit Items with real time upsdate
3.At the first time I only want to use Snapshot with limit 10
4.After than other record get with simple firestore get() query

Related

Firestore (Flutter) .orderBy Function sorting alphanumerically, sort numerically instead

I have a number set for document ids and are sorting based on them: here is a snippet of my code
StreamBuilder(
stream: Firestore.instance
.collection('parties')
.document(partyCode)
.collection('guestPicks')
.orderBy(FieldPath.documentId)
.snapshots(),
...
)
when i use this method, it sorts the documents like the following:
1
10
11
12
2
3
4
5
6
7
8
9
Can I change this to sort numerically so it's 12345...10 11 12?
I have other systems depending on this database architecture so changing it has to be a last-ditch option
Firestore document IDs are always strings. They can't be treated as numbers. As such, they will always sort lexicographically (by string value) as you are currently seeing.
If you want a numeric sort, you will need to add a number type field in your documents, and sort on that field instead of the document ID.

How to calculate duplicate events ? Google analytics

collected data :
I have a custom dimension called advertisingId with hit-scope , which is sent along with the event actions, here is an example of the collected data:
# action | advertisinId
1 install 30
2 install 10
3 install 30
4 install 10
5 install 40
6 install 50
requested metrics :
in google analytics i would like to build two metrics:
returning event : event who has advertisingId which is already associated to previous event.
unique event : an event who has advertisingId which is not associated to any previous event.
processes data example :
so according to the above collected data , here is the how the processes data should be:
# action | advertisinId | returningEvent
1 install 30 no. there is no previous event who has the same advertisingId
2 install 10 no. there is no previous event who has the same advertisinId
3 install 30 yes. because event #1 has the same advertisingId
4 install 10 yes. because event #2 has the same advertisingId
5 install 40 no. unique advertisingId
6 install 50 no. unique advertisinId
Final Report :
accordig to the processes data i need to build the following report:
action | unique event | returningEvent
install 4 2
How could i build that, what custom metrics i should build and configure ?
Thanks
Assuming your 'Action' field here is actually 'Event Action', you should already be able to extract this data from Google Analytics. I can't think of a way to get it as a calculated metric, but you can certainly get the volumes yourself.
Create a Flat Table Custom Report with Metric 'Total Events', and Dimensions 'Event Action' and 'advertisingID'.
Unique Events (as you defined above) is equal to the number of rows in the report.
Returning Events (as you defined above) is equal to the sum of 'Total Events' in the report, minus the Unique Events figure defined above.

Format of How Amazon Wishlist pages are showed

This is a conceptual question rather than a technical one and might seem silly but anyway here goes.
I'm trying to parse a public amazon wishlist given in this link using jsoup. I am able to do that currently.
As you can see in the above link, there are total 9 pages of in that wishlist in the format
1 2 3 4 5 6 7 .. 9
If there were n pages in a public wishlist then will the format be
1 2 3 4 5 6 7.. n
I need to know how all the pages in an Amazon Wishlist are represented so that I can code accordingly.
Links to various public Amazon Wishlists containing 2,5, 10, 20 pages are welcome to help understand how the pages are shown.
There are few options to know how many pages are in the list:
All the links to the other pages are at the same format: http://www.amazon.com/gp/registry/wishlist/3C96S5RO2A5A9/ref=cm_wl_sortbar_v_page_X/182-3573734-9320732?ie=UTF8&page=X (the page number is X and it appears twice in the URL), so you can loop on X from 2 and on. You should get 200 OK response for all the pages, until you hit a non existing one.
Download the first page and do:
Elements e = document.select("#wishlistPagination > span:nth-child(1) > div:nth-child(1)");
String s = e.text();
The string s contains now - ?Previous 1 2 3 4 5 6 7 … 9 Next? so find the number after the ellipsis or before "Next" and you're done.
EDIT
In a second thought - if the list contains 7 pages or less, there won't be "next" in the string, so the first method (fetching all the URLs and changing the page number X) is more robust.

ga:visits showing zero when ga:pageviews, ga:visitors show values?

I have a top profileid and a filtered profileid.
the filtered profileid uses a path starting with /xxx/yyy/
now in site I have 2 view pages -
1) top profile + my filter of /xxx/yyy/
2) sub profile
both pages show the same number and values for pages
but when I do a view of "ga:pageviews, ga:visitors, ga:visits"
I get different values only for visits (sometimes 0 on #1)
examples of output
1)
70 5 1
40 8 0 <--how can I get a zero?
2)
70 5 6
40 8 8
so hitting the top profile and adding my filter to the call gives me invalid visits.
using the same code for profile #2 I get correct numbers.
looking inside google admin, profile 2 only has the 1 filter and it matches the same as what I am doing in code. also the pages match up so this does not make sense to me.
how is it possible to get numbers but have no visits?
is there a way to get an individual listing of the data that it is using to output to my filtered request?
http://www.analyticsedge.com/2014/09/misunderstood-metrics-sessions-pages/
I think I figured this out. doing the filter inside google as a separate profile will retag the first page to a session count, whereas if I query the top profile and filter on my end I will get very low session starts because most people hit the home page or login page which counts as their session start.
it seems I cannot use the metric sessions or visits along with my filtering to a sub section.

Firefox Extension executeAsync Returns only 15 rows at a time

I am developing a firefox extension which reads and writes to a sqlite database. I ran an async query to fetch 20 rows from a database, and the callback function which handles the receipt of data gets called twice. The first time it return 15 rows and second time it return the last 5. Is this a standard value? If so, can this value be changed?
Yes, executeAsync will return a result after at most 15 rows and 75ms execution time. No, this cannot be changed - the thresholds are hardcoded.

Resources