AppsFlyer
AppsFlyer is a mobile marketing analytics and attribution platform that helps app developers to track and optimize their user acquisition funnel. AppsFlyer provides a comprehensive mobile marketing analytics and attribution platform that helps app developers to track and optimize their user acquisition funnel.
Web
In order to integrate it to your web portal, you need to follow the steps below.
- Create a Web App Bundle in AppsFlyer backoffice, and generate a webAppId key.
- Add the following code to your portal in CMS -> Tag manager -> Tags -> Add Tag -> Custom JS (use "On App Init" and "Exclude from Native" conditions), replacing
<insert key here>
with the key you generated in the previous step.
- Save, mark tag as active and ready for publishing.
- Publish the change to CDN.
(function () {
!function (t, e, n, s, a, c, i, o, p) {
t.AppsFlyerSdkObject = a, t.AF = t.AF || function () {
(t.AF.q = t.AF.q || []).push([Date.now()].concat(Array.prototype.slice.call(arguments)));
},
t.AF.id = t.AF.id
|| i, t.AF.plugins = {}, o = e.createElement(n), p = e.getElementsByTagName(n)[0], o.async = 1,
o.src = 'https://websdk.appsflyer.com?' + (c.length > 0 ? 'st=' + c.split(',').sort().join(',') + '&' : '')
+ (i.length > 0 ? 'af_id=' + i : ''),
p.parentNode.insertBefore(o, p);
}(window, document, 'script', 0, 'AF', 'pba', { pba: { webAppId: '<insert key here>' } });
if (Playtech.API.user.isLoggedIn()) {
AF('pba', 'setCustomerUserId', Playtech.fetchUserDetails().userId);
}
Playtech.on('LOGGED_IN', function () {
AF('pba', 'setCustomerUserId', Playtech.fetchUserDetails().userId);
});
Playtech.on('LOGGED_OUT', function () {
AF('pba', 'setCustomerUserId', 'undefined');
});
Playtech.on('LOGGED_IN', function () {
AF('pba', 'event', {
eventType: 'EVENT',
eventName: 'af_login',
eventValue: {
category: 'login',
label: 'login success',
customerID: Playtech.fetchUserDetails().userId
}
});
});
Playtech.on('LOGGED_IN_FAIL', function () {
AF('pba', 'event', {
eventType: 'EVENT',
eventName: 'af_login_fail',
eventValue: {
'category': 'login',
'label': 'login fail'
}
});
});
Playtech.on('REGISTRATION_COMPLETED', function ([{ userId }]) {
AF('pba', 'setCustomerUserId', userId);
setTimeout(function () {
AF('pba', 'event', {
eventType: 'EVENT',
eventName: 'af_register',
eventValue: {
category: 'registration',
label: 'registration completed',
customerID: userId
}
});
}, 2000);
});
Playtech.on('REGISTRATION_FAIL', function () {
AF('pba', 'event', {
eventType: 'EVENT',
eventName: 'af_register_fail',
eventValue: {
'category': 'registration',
'label': 'registration fail'
}
});
});
Playtech.on('DEPOSIT_COMPLETED', async function() {
const response = await Playtech.API.payments.getPaymentStatistics();
if (response.deposits.totalDepositCount === '1') {
AF('pba', 'event', {
eventType: 'EVENT',
eventName: 'af_first_deposit',
eventValue: {
category: 'deposit',
label: 'deposit first',
customerID: Playtech.fetchUserDetails().userId
}
});
} else {
AF('pba', 'event', {
eventType: 'EVENT',
eventName: 'af_deposit',
eventValue: {
category: 'deposit',
label: 'deposit completed',
customerID: Playtech.fetchUserDetails().userId
}
});
}
});
Playtech.on('DEPOSIT_FAIL', function () {
AF('pba', 'event', {
eventType: 'EVENT',
eventName: 'af_deposit_fail',
eventValue: {
category: 'deposit',
label: 'deposit fail',
customerID: Playtech.fetchUserDetails().userId
}
});
});
})();
Native
In case, Native AppsFlyer SDK is used, you can follow the steps below.
- Add the following code to your portal in CMS -> Tag manager -> Tags -> Add Tag -> Custom JS (use "On App Init" and "Only from Native" conditions)
- Save, mark tag as active and ready for publishing.
- Publish the change to CDN.
(function () {
Playtech.on('DEPOSIT_FAIL', () => {
Playtech.API.htcmd.portalEvent({ event: 'depositFail' });
});
Playtech.on('DEPOSIT_COMPLETED', async (response) => {
response = response[0];
const { currency } = Playtech.fetchUserDetails();
const stats = await Playtech.API.payments.getPaymentStatistics();
const isFirstDeposit = stats.deposits.totalDepositCount === '1';
const amount = response.amount ? response.amount : response.transactionData
? response.transactionData.amount && response.transactionData.amount.amount
: response.payments && response.payments.transaction && response.payments.transaction[0].amount;
Playtech.API.htcmd.portalEvent({
event: isFirstDeposit ? 'depositFirst' : 'depositCompleted',
amount,
currency
});
});
Playtech.on('REGISTRATION_COMPLETED', ([{ userId, username }]) => {
Playtech.API.htcmd.sendMessage('accountCreated', { userId, username });
});
})();
Alternatively, if direct event tracking is needed, you can use the following code.
(function () {
Playtech.on('LOGGED_IN', function () {
Playtech.API.htcmd.portalEvent({
event: 'af_login',
category: 'login',
label: 'login success',
customerID: Playtech.fetchUserDetails().userId
});
});
Playtech.on('LOGGED_IN_FAIL', function () {
Playtech.API.htcmd.portalEvent({
event: 'af_login_fail',
'category': 'login',
'label': 'login fail'
});
});
Playtech.on('REGISTRATION_COMPLETED', function ([{ userId }]) {
Playtech.API.htcmd.portalEvent({
event: 'af_register',
category: 'registration',
label: 'registration completed',
customerID: userId
});
});
Playtech.on('REGISTRATION_FAIL', function () {
Playtech.API.htcmd.portalEvent({
event: 'af_register_fail',
'category': 'registration',
'label': 'registration fail'
});
});
Playtech.on('DEPOSIT_COMPLETED', async function () {
const response = await Playtech.API.payments.getPaymentStatistics();
if (response.deposits.totalDepositCount === '1') {
Playtech.API.htcmd.portalEvent({
event: 'af_first_deposit',
category: 'deposit',
label: 'deposit first',
customerID: Playtech.fetchUserDetails().userId
});
} else {
Playtech.API.htcmd.portalEvent({
event: 'af_deposit',
category: 'deposit',
label: 'deposit completed',
customerID: Playtech.fetchUserDetails().userId
});
}
});
Playtech.on('DEPOSIT_FAIL', function () {
Playtech.API.htcmd.portalEvent({
event: 'af_deposit_fail',
category: 'deposit',
label: 'deposit fail',
customerID: Playtech.fetchUserDetails().userId
});
});
Playtech.on(Playtech.Events.SAFECHARGE_ANALYTICS, function ([event]) {
const { action } = event;
let eventName = null;
switch (action) {
case 'attempted deposit':
case 'failed deposit':
eventName = 'af_deposit_fail';
break;
case 'attempted first deposit':
case 'failed first deposit':
eventName = 'af_first_deposit_fail';
break;
case 'made first deposit':
eventName = 'af_first_deposit';
break;
case 'made deposit':
eventName = 'af_deposit';
break;
default:
return;
}
const {
deposit_amount,
currency,
label
} = event;
Playtech.API.htcmd.portalEvent({
event: eventName,
category: 'deposit',
label: label,
deposit_amount,
currency,
customerID: Playtech.fetchUserDetails().userId
});
});
Playtech.on(Playtech.Events.SAFECHARGE_ANALYTICS, function ([event]) {
const { action } = event;
let eventName = null;
switch (action) {
case 'withdrawal_request_created':
eventName = 'af_withdraw';
break;
default:
return;
}
const {
amount,
currency,
label
} = event;
Playtech.API.htcmd.portalEvent({
event: eventName,
category: 'withdraw',
label: label,
amount,
currency,
customerID: Playtech.fetchUserDetails().userId
});
});
})();