Instantly share code, notes, and snippets.

Embed
What would you like to do?
No boundaries: Snippet from Tealium utag script (https://gist.github.com/englehardt/3b86d6a4a97e2c9c86b23e57ad65adca)
try {
    utag.data.facebook_handler = {};
    utag.data.facebook_handler.id_grabber = function() {
        utag.data.facebook_handler.call_counter = utag.data.facebook_handler.call_counter + 1 || 1;
        if (utag.data.facebook_handler.call_counter < 11) {
            setTimeout(function() {
                if (window.FB && typeof window.FB.getAuthResponse === "function") {
                    utag.data.facebook_handler.authResponse = FB.getAuthResponse();
                    if (utag.data.facebook_handler.authResponse && utag.data.facebook_handler.authResponse.userID) {
                        utag.data.facebook_handler.call_counter = 100;
                        utag.data.facebook_id = utag.data.facebook_handler.authResponse.userID;
                        utag.track('audiencestream', {
                            facebook_id: utag.data.facebook_id,
                            as_event_name: 'grab Facebook ID'
                        });
                    }
                }
                if (utag.data.facebook_handler.call_counter < 11) {
                    utag.data.facebook_handler.id_grabber();
                }
            }, 1000);
        }
    }
    utag.data.facebook_handler.id_grabber();
} catch (e) {
    utag.DB(e)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment