/** * Records an event in Criteo * * @param {String} eventName - The name of the 'event' property such as 'viewItem' or 'viewBasket' * @param {Object} eventProps - Additional details about the event such as `{ item: '1' }` * * @returns {void} */ function recordInCriteo( eventName, eventProps ) { if ( ! isAdTrackingAllowed() || ! isCriteoEnabled ) { return; } if ( ! hasStartedFetchingScripts ) { return loadTrackingScripts( recordInCriteo.bind( null, eventName, eventProps ) ); } const events = []; events.push( { event: 'setAccount', account: TRACKING_IDS.criteo } ); events.push( { event: 'setSiteType', type: criteoSiteType() } ); if ( user.get() ) { events.push( { event: 'setEmail', email: [ hashPii( user.get().email ) ] } ); } const conversionEvent = clone( eventProps ); conversionEvent.event = eventName; events.push( conversionEvent ); // The deep clone is necessary because the Criteo script modifies the objects in the // array which causes the console to display different data than is originally added debug( 'Track `' + eventName + '` event in Criteo', cloneDeep( events ) ); window.criteo_q.push( ...events ); }
initialize: function() { const parameters = {}; if ( ! analytics.ga.initialized ) { if ( _user && _user.get() ) { parameters.userId = hashPii( _user.get().ID ); } window.ga( 'create', config( 'google_analytics_key' ), 'auto', parameters ); window.ga( 'set', 'anonymizeIp', true ); analytics.ga.initialized = true; } },
/** * Defines the global variables required by Nanigans * (app tracking ID, user's hashed e-mail) */ function setupNanigansGlobal() { isNanigansConfigured = true; const currentUser = user.get(); const normalizedEmail = currentUser && currentUser.email ? currentUser.email.toLowerCase().replace( /\s/g, '' ) : ''; window.NaN_api = [ [ TRACKING_IDS.nanigansAppId, normalizedEmail ? hashPii( normalizedEmail ) : '' ], ]; debug( 'Nanigans setup: ', window.NaN_api, ', for e-mail: ' + normalizedEmail ); }
/** * Returns an object with DCM Floodlight user params * * @returns {Object} With the WordPress.com user id and/or the logged out Tracks id */ function floodlightUserParams() { const params = {}; const currentUser = user.get(); if ( currentUser ) { params.u4 = hashPii( currentUser.ID ); } const anonymousUserId = tracksAnonymousUserId(); if ( anonymousUserId ) { params.u5 = anonymousUserId; } return params; }
/** * Recorders an individual product purchase conversion * * @param {Object} product - the product * @param {Number} orderId - the order id * @returns {void} */ function recordProduct( product, orderId ) { if ( ! isAdTrackingAllowed() ) { return; } if ( ! hasStartedFetchingScripts ) { return loadTrackingScripts( recordProduct.bind( null, product, orderId ) ); } const isJetpackPlan = productsValues.isJetpackPlan( product ); if ( isJetpackPlan ) { debug( 'Recording Jetpack purchase', product ); } else { debug( 'Recording purchase', product ); } const currentUser = user.get(); const userId = currentUser ? hashPii( currentUser.ID ) : 0; try { // Google Analytics const item = { currency: product.currency, id: orderId, name: product.product_slug, price: product.cost, sku: product.product_slug, quantity: 1, }; debug( 'recordProduct: ga ecommerce add item', item ); window.ga( 'ecommerce:addItem', item ); // Google AdWords if ( isAdwordsEnabled ) { if ( window.google_trackConversion ) { window.google_trackConversion( { google_conversion_id: isJetpackPlan ? ADWORDS_CONVERSION_ID_JETPACK : ADWORDS_CONVERSION_ID, google_conversion_label: isJetpackPlan ? TRACKING_IDS.googleConversionLabelJetpack : TRACKING_IDS.googleConversionLabel, google_conversion_value: product.cost, google_conversion_currency: product.currency, google_custom_params: { product_slug: product.product_slug, user_id: userId, order_id: orderId, }, google_remarketing_only: false, } ); } } // Facebook (disabled for now as we are not sure this works as intended). // The entire order is already reported to Facebook, so not absolutely necessary. /* if ( isFacebookEnabled ) { window.fbq( 'trackSingle', isJetpackPlan ? TRACKING_IDS.facebookJetpackInit : TRACKING_IDS.facebookInit, 'Purchase', { currency: product.currency, product_slug: product.product_slug, value: product.cost, user_id: userId, order_id: orderId, } ); } */ // Twitter if ( isTwitterEnabled ) { window.twq( 'track', 'Purchase', { value: product.cost.toString(), currency: product.currency, content_name: product.product_name, content_type: 'product', content_ids: [ product.product_slug ], num_items: product.volume, order_id: orderId, } ); } // Yandex Goal if ( isYandexEnabled ) { window.yaCounter45268389.reachGoal( 'ProductPurchase', { order_id: orderId, product_slug: product.product_slug, order_price: product.cost, currency: product.currency, } ); } if ( isSupportedCurrency( product.currency ) ) { const costUSD = costToUSD( product.cost, product.currency ); // Bing if ( isBingEnabled ) { const bingParams = { ec: 'purchase', gv: costUSD, }; if ( isJetpackPlan ) { // `el` must be included only for jetpack plans bingParams.el = 'jetpack'; } window.uetq.push( bingParams ); } // Quantcast if ( isQuantcastEnabled ) { // Note that all properties have to be strings or they won't get tracked window._qevents.push( { qacct: TRACKING_IDS.quantcast, labels: '_fp.event.Purchase Confirmation,_fp.pcat.' + product.product_slug, orderid: orderId.toString(), revenue: costUSD.toString(), event: 'refresh', } ); } // Yahoo if ( isYahooEnabled ) { // Like the Quantcast tracking above, the price has to be passed as a string // See: https://developer.yahoo.com/gemini/guide/dottags/installing-tags/ /*global YAHOO*/ YAHOO.ywa.I13N.fireBeacon( [ { projectId: TRACKING_IDS.yahooProjectId, properties: { pixelId: TRACKING_IDS.yahooPixelId, qstrings: { et: 'custom', ec: 'wordpress.com', ea: 'purchase', el: product.product_slug, gv: costUSD.toString(), }, }, }, ] ); } } } catch ( err ) { debug( 'Unable to save purchase tracking data', err ); } }