airbrite/celery-overlay — pull request #1 by sdebaun (2014-03-26 20:21:01+00:00)
Title: Added callbacks for analytics integration

I actually haven't figured out how to test whether or not the referrer gets through until data starts showing up in production. I can see the events firing with a debugger; I'll let you know after a couple of days in production. I don't know why it wouldn't include referrer, because the original cause should be fixed.

The problem is: when you call ga() events in the context of the iframe, it treats the enclosing page as the referrer. If you make ga() calls there, thats what it will get.
My solution was: have the celery code in the iframe hook into callbacks in the parent window. Basically at each step, Celery checks to see if a callback e.g. named "onCeleryOrderPlaced" exists. If it does, it fires the callback.
So in the parent window, the onCeleryOrderPlaced function makes the ga() call. It's using the ga() function that was created in the context of the parent window.

Celery users will be able to write whatever callback handlers they want. You could provide a set of vanilla ga callbacks, or they could write their own for any analytics or tracking system.