baker icon indicating copy to clipboard operation
baker copied to clipboard

Google Analytics integration

Open jacopoch opened this issue 14 years ago • 57 comments

Hi, I think this has been addressed by someone already, but how exactly you implement Google Analytics in Baker?

Cheers,

Jacopo

jacopoch avatar Mar 01 '12 23:03 jacopoch

I explain better: I would just like to know when the application gets launched, if it makes this any easier :) I know how to do it in a normal iOS app, but as I am no xCode developer I fail in integrating it into my baker based magazine..

jacopoch avatar Mar 03 '12 09:03 jacopoch

Have you looked at the appdelegate? Also - you might think about putting in the localytics library - it's a little richer than google analytics. You can create your own triggers and events.

ghost avatar Mar 04 '12 02:03 ghost

Ok, but what about tracking the single pages with localytics? I've checked it out vs google analytics, and I'll go for it, it has more features, thanks for the tip ;)

On Mar 4, 2012, at 4:49 AM, [email protected] wrote:

Have you looked at the appdelegate? Also - you might think about putting in the localytics library - it's a little richer than google analytics. You can create your own triggers and events.


Reply to this email directly or view it on GitHub: https://github.com/Simbul/baker/issues/332#issuecomment-4307089

jacopoch avatar Mar 04 '12 08:03 jacopoch

If I were to guess, the authors of this library are getting defining moments every time they read this stuff!

If I were in charge of the API, I would consider the following:

BakerFramework is a wonderful bridge between web pages and iOS. I like it a great deal.

The snapshot, updating features, getting script-filled html pages to work in iOS in an epub-like format is an awesome feat - so the bridge works great!

I think you can get the actual html page somewhere in the curr page code (somewhere around the snapshot stuff.)

Going forward, it would be helpful to expose those variables a bit in documentation. It appears that people are getting really sophisticated!

ghost avatar Mar 04 '12 13:03 ghost

I think that since the framework is so flexible is quite obvious people want to do more and more with it.

We are almost ready to press the first issue of a monthly magazine of about 100 pages with Baker for example :)

jacopoch avatar Mar 04 '12 13:03 jacopoch

I know it might sound rough, and maybe it doesn't work, but it might be possible to just add the Google Analytics code in every page of the book... And maybe trigger a custom javascript event to track the single page.

Did anyone test it yet? :D It might be an awesome think if it works... :)

folletto avatar Mar 05 '12 20:03 folletto

It doesn't work unfortunately, it is not allowed to execute JavaScript like that from the app directly. But I'll give a try with localytics tonight, I can live with just the open the application tracking for the moment: I really need to press the issue before 15th of march :)

jacopoch avatar Mar 06 '12 06:03 jacopoch

Jeep, no analytics love yet.

If somebody has integrated already please share the valuable piece of information so that we can document it :)

jacopoch avatar Mar 09 '12 06:03 jacopoch

I struggled with actually stating this in a reply but here goes:

The challenge with OpenSource growth is in its developers inability to document their own code.

Lots of developers want to reuse, extend, modify OpenSource. Whether or not projects are extended by its audience is predicated by two things: Whether they can confidently modify existing code - within a construct and have the "audacity" to share it and whether or not they have the skills.

The skills part is frequently driven by their ability to understand what is in front of them. Sure, they might understand what is being done line by line; or they can scan well-commented code and go to the right place. Whether they do the latter is driven by their ability to devote and willingness to invest the time.

The last sentence is me. Nonetheless, I'm looking for the right place to give you a good example. I've used Localytics and it works wonderfully.

ghost avatar Mar 09 '12 13:03 ghost

"The challenge with OpenSource growth is in its developers inability to document their own code."

As you might guess, I disagree, but you say it better later:

"Whether they do the latter is driven by their ability to devote and willingness to invest the time."

It's not willingness, otherwise this project wouldn't be here at all. It's a matter of time. Our time is limited, as it is with any opensource project, where "time" is the primary and absolute constraint. So, it's very often a choice between writing code (and fixing, adding features or improving) and documentation, community, pr and so on.

I personally think that we did a quite amazing work in Baker, given the time we had.

We can improve? Of course. But since our donations flow doesn't allow us to dedicate more time, the only extra time here could come from the community.

This means... that's up to you.

If you want, you can easily create a page on the wiki above with all the details you think are necessary, polish and expand it. Opensource isn't just about "the developers", but it's about the community. If the community isn't willing to support the whole project - and that doesn't mean just money - with documentation, contributions, feedback, and so on, the developers are in a really tight spot and they have to make difficult choices and compromises.

So, to rephrase myself:

I personally think that we did a quite amazing work in Baker, given the time we had and that's at least 50% thanks to the community here. :)

folletto avatar Mar 09 '12 13:03 folletto

I think if you add the load library stuff in the app delegate as in the Localytics docs and then look at the RootViewController - around Line 542 #pragma mark "Loading"

Down at line 568, it's loading a page (in a rect view).

currentPageNumber is an integer, you can get that - otherwise, I believe pages objectAtIndex is the actual localURL (NSURL datatype)..

Short of any documentation and loading up the Localytics library, I think that's your "insertion" point.

Hope that helps.

ghost avatar Mar 09 '12 13:03 ghost

Hi, without getting into a huge debate....

(Pardon my directness, it avoids people guessing what's on my mind...LOL)

I agree that you did INCREDIBLE WORK!!!

After being in code since 1999, I find that if I don't document everything as I go, I find that I have to retrain myself each and every time I go back into the code. The time that takes = the time it takes to document as you go.

The challenge with any new project is that you cycle through adding code and modifying what you have over and over again until it works. That really gets in the way!!!

At any rate, we have what we have and I am truly appreciative of what you have done. I hope in some small way I can continue to contribute to the community.

Best Wishes, jws

ghost avatar Mar 09 '12 14:03 ghost

That's why there is the community, we can help commenting the procedures / code and creating documentation :)

My aim was to contribute to create some sort of description here so that it's easily accessible and others willing to use it could receive help.

If we manage we'll deliver another improvement to this great open source project, if we won't, let's not start an argument on open source!

J

jacopoch avatar Mar 09 '12 14:03 jacopoch

Thanks. :)

folletto avatar Mar 09 '12 14:03 folletto

Yep. Agree!

David, what would have saved me the most time is this:

"Given a JSON file with HTML, count page numbers, pull in content into a CGRect, along the way zipping screen shots to increase page view performance.

The major portions of code you should know are: Root View Controller does the heavy lifting for pages. Properties does retrieval for pages and yada yada. Interceptor handles the popup view below."

And I'm still not sure that's right! LOL

ghost avatar Mar 09 '12 14:03 ghost

Check issue #59 and #12 (guess also how old they are from their number) and imagine the decision we took instead of doing these two things. ;)

However, I already started commenting the code every time I touch some function. It just... takes time. :)

folletto avatar Mar 09 '12 14:03 folletto

I've been using Flurry for analytics and I've just got it working with page views by placing it inside the root view controller.m code. Its still got a few problems, most noticeably that it doesn't count a page view when you open the app, only when you move through the pages after opening. Also, I can't get it to tell me which page was viewed, only that a page was viewed. I've also got it to track outbound links (our magazine is working on getting advertising and need to track clicks) Again, I can track outbound links but not which ones yet. Flurry does have a way of passing information out regarding these things, i just don't know how to implement it. (By the way, the rest of Flurry works fine, I can track users, sessions, countries, etc)

The Flurry interface is really great and I'm excited to try work on it more. If I get it to work I will try update the wiki. I know Google analytics also has an iOS SDK that works in a similar way. Maybe we can all try figuring this out as i know it will be important to magazines that wish to use advertising. I would suggest limiting ourselves right now to Flurry and Google, I know they're both popular. (By the way, to avoid confusion, Google has TWO analytics implementations, the web code and the iOS code. The web code does not work inside the app, so you can't just place it in your HTML files [yes, I tried]. The iOS code is placed inside Xcode files and works the same as Flurry. Please be exact so not to confuse people)

If anyone at Baker is interested in this and willing to work with me I would be happy to explain what i know, what the problems are and how they might be fixed. You guys know the code and I'm sure it would go quickly. Maybe we can place comments in the code that will allow people to add it on their own without actually building it into Baker.

P.S. - This is where I placed the Flurry code for web views in rootviewcontroller.m. You also need to place it in the main thread to enable Flurry.

- (BOOL)loadWebView:(UIWebView*)webView withPage:(int)page {

NSString *path = [NSString stringWithString:[pages objectAtIndex:page - 1]];

    if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
        NSLog(@"• Loading: book/%@", [[NSFileManager defaultManager] displayNameAtPath:path]);

        // Flurry Analytics page view logging
        [FlurryAnalytics logPageView];

        // Flurry Analytics event logging for pages
        [FlurryAnalytics logEvent:@"Page_Read"];

        [webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]]];
        return YES;

    }
    return NO;
}  

tstegart avatar Mar 17 '12 19:03 tstegart

@tstegart One suggestion that I might give you: if while doing this you are able to make it modular, then we have one more chance to incorporate it in our codebase. :)

Btw, thanks to your work I changed this issue from "Support" to "Feature", since what you are doing seems plausible and even if we end up not supporting a specific analytics tool, we might provide callbacks - or building a delegate. ;)

folletto avatar Mar 17 '12 21:03 folletto

What do you mean modular?

I will try and get anyone interested in this the background on both Flurry and Google so people can look at the documentation and see what the best approach is. We're launching our app this week so I won't have it for you this week, but maybe next week. I will post a also summary of the issues and an approach to solving them.

tstegart avatar Mar 18 '12 01:03 tstegart

I am going to share my knowledge about Google analytics integration in the next days, thanks in the meanwhile for your updates! I am very busy at the moment and I missed to update you, but good progress has been made to integrate fully GA :)

jacopoch avatar Mar 18 '12 09:03 jacopoch