# Launch
# Custom Events
The implementation of Launch code fires custom JavaScript events when a key event is detected.
The third party trackers should listen to the custom JavaScript event and trigger code based on that.
The following custom events have been implemented and they are attached to the document element. Note: events are different for production and test environments.
Events can contain data in them. The instructions below show the events as well as data.
# ATDecibelTokens
Custom event for Decibel from Adobe Target script
Data: token - Adobe Target response tokens
# childSearch
Will fire when the sponsorship search is executed.
The following properties will be added in addition to default ones, documented in pageView event:
childListingsViewed: ${numberOfChildrenInTheListSeen}
childProfilesViewed: ${numberOfChildProfilesSeen}
childSearchDetails: ${underscoreDelimitedListOfSearchCriteria}
# formSubmit
Will fire on the generic forms such as surveys, on peer-to-peer pages where the form does not add a product into a cart or attempts a checkout.
The following properties will be added in addition to default ones, documented in pageView event:
detail: {
formId: ${formId},
formName: ${formName},
}
# interaction
Will fire on any click interactions. The following properties will be added in addition to default ones, documented in pageView event:
detail: {
interactionElement: ${clickedElement},
interactionDestination: ${linkOrFormDestination},
interactionRegion: ${elementRegion},
interactionType: ${elementType},
}
# leadgenPX
Will fire only in AEM when the sign up form is submitted. The detail will contain the following properties:
detail: {
name: ${formName},
surveyId: ${idOfTargetSurvey},
}
# pageView
Page view event will contain default data, it will be included in all other events, as well:
Product data will be added on product list & product display pages.
detail: {
environment: ${environment},
pageUrl: ${currentPageUrl},
pageName: ${currentPageName},
pageType: ${currentPageType},
products: ${arrayOfProductsViewed},
userConsId: ${loggedInUserConsId},
userDonorId: ${loggedInUserDonorId},
userIsDonor: ${loggedInUserDonorStatus},
userIsFaf: ${loggedInUserPeer-to-peerStatus},
userIsPartner: ${loggedInUserPartnerForChildrenStatus},
userIsSponsor: ${loggedInUserSponsorshipStatus},
useMcId: ${adobeMarketingCloudId},
}
On pages where a product is shown, the product data will also be included in the same standard format as it is documented in transactionAddToCart event.
# productView
This event will fire on product pages, the product data will also be included in the same standard format as it is documented in transactionAddToCart event. The standard page data documented in pageView will also be included.
# signUp
This event will fire when the user submits a sign up form & that submission goes to the Cheetahmail, which is not always the case in AEM forms. See leadgenPX event details to capture all form submissions. The following properties will be added, in addition to default ones, documented in pageView event:
detail: {
formId: ${formId},
formName: ${formName},
}
# transactionAddToCart
The following properties will be added in addition to default ones, documented in pageView event, child properties will only be included on sponsorship products:
detail: {
products: [
{
productCategory: ${productCategory},
productId: ${productId},
productPrice: ${productPriceIfAvailable},
productQuantity: ${productQuantity},
childAge: ${childAge},
childCountry: ${childCountry},
childDaysWaiting: ${childDaysWaiting},
childGender: ${childGender},
childId: ${childId},
}
]
}
# transactionCheckout
The following properties will be added in addition to default ones for pageView event and product details documented in transactionAddToCart.
Note that transaction category properties will be included if the subtotal for that category is greater than 0.
detail: {
transactionTotal: ${transactionGrantTotalAmount},
transactionPaymentMethod: ${transactionPaymentMethod},
transactionCatalogTotal: ${catalogProductsSubtotal},
transactionDonationFrequency: ${donationProductsFrequency},
transactionDonationTotal: ${donationProductsSubtotal},
transactionEventTotal: ${eventTicketsSubtotal},
transactionSponsorshipFrequency: ${sponsorshipProductsFrequency},
transactionSponsorshipTotal: ${sponsorshipProductsSubtotal},
transactionPeerToPeerTotal: ${peerToPeerRegistrationFeeSubtotals},
}
# transactionComplete
The following properties will be added in addition to default ones for pageView event, and product details documented in transactionAddToCart, and transaction details documented in transactionCheckout.
Note that transaction category properties will be included if the subtotal for that category is greater than 0.
detail: {
transactionId: ${transactionId},
}
# transactionRemoveFromCart
The details provided for this event is a the same ones as the ones sent with pageView & transactionAddToCart events,
# Available Data
The third party tracker may need to get meaningful data from analytics. All relevant data should be included in the event. If key data points are missing, please let the development team know to make the necessary additions.
This section documents generic functions that are created in code to get basic data.
s.getTransactionTotals()- this function present in Launch code and accessible only in Launch; it will return an object with the grand total for the transaction and include subtotals per category and renewal frequencies for donations and sponsorships.
# Triggering Trackers Only in Production
- Create your rule
- Add a new condition of the
CoreExtension andValue ComparisonCondition Type - Give it a meaningful name
Execute only in productionorExecute only in development - In the field Left Operand select
content:isProductionDomainor enter%content:isProductionDomain% - In the Operator fiels select Is True or Is False depending on the need
- Save the condition
- Save the rule
# Triggering Trackers Only on Transaction Success Pages
A custom data element has been defined in Launch to enable for easy identification of the transaction success pages. The name of the data element is content:isTransactionSuccessPage.
# Adding Condition of Transaction Success Pages in Code
var isTransactionSuccessPage = _satellite.getVar('content:isTransactionSuccessPage');
if (isTransactionSuccessPage) {
console.debug('We are on a transaction success page.');
} else {
console.debug('There will be any transaction events on this page.');
}
# Adding Condition of Transaction Success Pages in a Rule
- Create your rule
- Add a new condition of the
CoreExtension andValue ComparisonCondition Type - Give it a meaningful name
Is Trasnaction Success PageorIs Not a Trasnaction Success Page - In the field Left Operand select
content:isTransactionSuccessPageor enter%content:isTransactionSuccessPage% - In the Operator fiels select Is True or Is False depending on the need
- Save the condition
- Save the rule
# Add Different Parameters Based on the Event Name
In some rare cases the third party tag may need to track slightly different parameters based on the event type. For example, Wiland wants us to not track page view on transaction success pages only the transaction completed events. In such cases, the rule can be configured to fire on both events pageView & transactionCompleted. With JavaScript in the rule we can test which rule has been fired, as they both fire on transaction success pages, and make a decision accordingly. The name of the event can be accessed under event.nativeEvent.type as Adobe code moves all standard event properties into nativeEvent section.
Example:
var isTrackTransaction = false;
var isTrackPageView = true;
var isTransactionSuccessPage = _satellite.getVar('content:isTransactionSuccessPage');
if (isTransactionSuccessPage && event.nativeEvent.type === 'transactionComplete') {
isTrackTransaction = true;
isTrackPageView = false;
} else if (isTransactionSuccessPage && event.nativeEvent.type === 'pageView') {
isTrackPageView = false;
}
# Examples
JavaScript code for listening to event
try {
document.addEventListener('pageView', function(event){
console.debug(event, event.detail);
});
} catch(e) {
console.error(e);
}
# Tracking Transactions in LeadRx
Create a new rule in Launch.
Configure Events section as follows. Select the Extension to be Core, Event Type to be Custom Event, Custom Event Type to be transactionComplete, specific elements to be any element. Note Selecting document seems to fail although it is accurate.
Configure Actions section as follows. Select the Extension to be Core, Action Type to be Custom Code, Language to be JavaScript. Mutiple tracking codes were provided by the LeadRX team but they all contained similar data. The code was combined into one function where the values change dynamically based on the page type details in the custom event. The code was wrapped into try/catch clause to ensure the code fails gracefully, when it does.
function trackTransactionInLeadRx(event) {
var data = event.detail;
// default object records user data
var lRxProfile = {
"userID": data.userConsId === '' ? null : data.userConsId
};
var lRxConversionId = ''
var pageType = data.pageType.toLowerCase();
// Default order id and grand total values
lRxProfile.orderID = data.transactionId;
lRxProfile.leadValue = data.transactionTotal;
if (pageType.indexOf('donation') > -1) {
if (data.transactionDonationFrequency === 'one-time') {
lRxConversionId = 13774;
} else {
lRxConversionId = 13775;
}
} else if (pageType.indexOf('sponsorship') > -1) {
lRxConversionId = 13777;
} else if (pageType.indexOf('catalog') > -1) {
lRxConversionId = 13776;
}
_lrx_sendEvent('conversion', lRxConversionId, null, JSON.stringify(lRxProfile));
}
try {
trackTransactionInLeadRx(event);
} catch(e) {
console.error(e);
}