window.styla = window.styla || {};
window.styla.hooks = window.styla.hooks || [];

// track interactions with styla content
window.styla.hooks.push([
    'analytics',
    function(context, data){
        var label = '';
        var action = '';
        if (window.event && window.event.srcElement && window.event.srcElement.text) {
            label += window.event.srcElement.text;
        }
        if ( data.targetUrl ) {
            label += data.targetUrl;
        }
        if ( data.type ) {
            action = data.type;
        }
        action = action || 'no_action';
        label = label || 'no_text';
        alert("EVENT_TEST", action, context, data);
        if (window.dataLayer) {
        	 // Google Tag Manager
           //window.dataLayer.push({'event':action, "eventCategory":"styla_interaction", "eventLabel":label});
           // Gtag
           // window.gtag('event', action, {
           //     'event_category': 'styla_interaction',
           //     'event_label': label,
           //     'module_id': context && context.module && context.module.id,
           //     'module_name': context && context.module && context.module.name,
           //     'module_type': context && context.module && context.module.type,
           // });
           // GA
           // window.ga();
        }
    }
]);

// track virtual pageviews for opening magazine stories
var isFirstPageviewIgnored = false;
window.styla.hooks.push([
    'view_page',
    function(context, data){
        if (!isFirstPageviewIgnored) {
            isFirstPageviewIgnored = true;
            return;
        }
        alert("PAGE_VIEW_TEST",context,data);
        if (window.dataLayer) {
        		// Google Tag Manager Integration
        		//window.dataLayer.push({
        		//             'event': 'Pageview',
        		//             'pagePath': window.location.pathname,
        		//             'pageTitle': 'Contact us' //some arbitrary name for the page/state
        		//             });
            // GTAG Integration
            // gtag('config', 'GA_MEASUREMENT_ID', {'page_path': window.location.pathname});
            // GA Integration
            //ga('send', 'pageview');
        }
    }
]);