Skip to content

Commit

Permalink
Flat & percent based goal support for conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Jan 14, 2020
1 parent 7e98cec commit b0ab10f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
20 changes: 17 additions & 3 deletions examples/examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ let apiKey = process.env.TONICPOW_API_KEY || ''
console.log('updated title: '+campaign.title)

//
// Example: Create a goal
// Example: Create a goal (flat rate)
//
let goal = {
campaign_id: campaign.id,
Expand All @@ -193,6 +193,20 @@ let apiKey = process.env.TONICPOW_API_KEY || ''
goal = await TonicPow.updateGoal(goal)
console.log('updated title: '+goal.title)

//
// Example: Create a goal (percent based)
//
let goalPercent = {
campaign_id: campaign.id,
description: 'Get 10% of all action!',
name: 'all-action',
payout_rate: 0.10, // 10% of "purchaseAmount"
payout_type: 'percent',
title: '10% Commissions'
}
goalPercent = await TonicPow.createGoal(goalPercent)
console.log('goal created', goalPercent)

//
// Example: Create a link
//
Expand Down Expand Up @@ -248,9 +262,9 @@ let apiKey = process.env.TONICPOW_API_KEY || ''
//console.log('conversion successful', conversion)

//
// Example: Convert a goal (by user)
// Example: Convert a goal (by user) (delayed)
//
let conversion = await TonicPow.createConversionByUserID(1, 1, 'my custom attributes', 10)
let conversion = await TonicPow.createConversionByUserID(1, 1, 'my custom attributes', 0, 10)
console.log('conversion successful', conversion)

//
Expand Down
24 changes: 12 additions & 12 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,24 +645,24 @@ async function getConversion (t, conversionId) {
// createConversionByGoalID will fire a conversion for a given goal id, if successful it will make a new Conversion
//
// For more information: https://docs.tonicpow.com/#caeffdd5-eaad-4fc8-ac01-8288b50e8e27
async function createConversionByGoalID (t, goalId, tncpwSession, additionalData = '', delayInMinutes = 0) {
let data = { goal_id: goalId, tncpw_session: tncpwSession, additional_data: additionalData, delay_in_minutes: delayInMinutes }
async function createConversionByGoalID (t, goalId, tncpwSession, optionalData = '', optionalPurchaseAmount = 0.00, delayInMinutes = 0) {
let data = { goal_id: goalId, tncpw_session: tncpwSession, additional_data: optionalData, delay_in_minutes: delayInMinutes, amount: optionalPurchaseAmount }
return tonicAxios.post(t.config.apiUrl + version + '/conversions', data, getOptions())
}

// createConversionByGoalName will fire a conversion for a given goal name, if successful it will make a new Conversion
//
// For more information: https://docs.tonicpow.com/#d19c9850-3832-45b2-b880-3ef2f3b7dc37
async function createConversionByGoalName (t, goalName, tncpwSession, additionalData = '', delayInMinutes = 0) {
let data = { name: goalName, tncpw_session: tncpwSession, additional_data: additionalData, delay_in_minutes: delayInMinutes }
async function createConversionByGoalName (t, goalName, tncpwSession, optionalData = '', optionalPurchaseAmount = 0.00, delayInMinutes = 0) {
let data = { name: goalName, tncpw_session: tncpwSession, additional_data: optionalData, delay_in_minutes: delayInMinutes, amount: optionalPurchaseAmount }
return tonicAxios.post(t.config.apiUrl + version + '/conversions', data, getOptions())
}

// createConversionByUserID will fire a conversion for a given goal and user id, if successful it will make a new Conversion
//
// For more information: https://docs.tonicpow.com/#d724f762-329e-473d-bdc4-aebc19dd9ea8
async function createConversionByUserID (t, goalId, userId, additionalData = '', delayInMinutes = 0) {
let data = { goal_id: goalId, user_id: userId, additional_data: additionalData, delay_in_minutes: delayInMinutes }
async function createConversionByUserID (t, goalId, userId, optionalData = '', optionalPurchaseAmount = 0.00, delayInMinutes = 0) {
let data = { goal_id: goalId, user_id: userId, additional_data: optionalData, delay_in_minutes: delayInMinutes, amount: optionalPurchaseAmount }
return tonicAxios.post(t.config.apiUrl + version + '/conversions', data, getOptions())
}

Expand Down Expand Up @@ -1100,33 +1100,33 @@ module.exports = {
}
})
},
createConversionByGoalID: async function (goalId, tncpwSession, additionalData = '', delayInMinutes = 0) {
createConversionByGoalID: async function (goalId, tncpwSession, optionalData = '', optionalPurchaseAmount = 0.00, delayInMinutes = 0) {
return new Promise(async (resolve, reject) => {
try {
initCheck(this.loaded)
let response = await createConversionByGoalID(this, goalId, tncpwSession, additionalData, delayInMinutes)
let response = await createConversionByGoalID(this, goalId, tncpwSession, optionalData, optionalPurchaseAmount, delayInMinutes)
resolve(response.data)
} catch (e) {
reject(checkError(e))
}
})
},
createConversionByGoalName: async function (goalName, tncpwSession, additionalData = '', delayInMinutes = 0) {
createConversionByGoalName: async function (goalName, tncpwSession, optionalData = '', optionalPurchaseAmount = 0.00, delayInMinutes = 0) {
return new Promise(async (resolve, reject) => {
try {
initCheck(this.loaded)
let response = await createConversionByGoalName(this, goalName, tncpwSession, additionalData, delayInMinutes)
let response = await createConversionByGoalName(this, goalName, tncpwSession, optionalData, optionalPurchaseAmount, delayInMinutes)
resolve(response.data)
} catch (e) {
reject(checkError(e))
}
})
},
createConversionByUserID: async function (goalId, userId, additionalData = '', delayInMinutes = 0) {
createConversionByUserID: async function (goalId, userId, optionalData = '', optionalPurchaseAmount = 0.00, delayInMinutes = 0) {
return new Promise(async (resolve, reject) => {
try {
initCheck(this.loaded)
let response = await createConversionByUserID(this, goalId, userId, additionalData, delayInMinutes)
let response = await createConversionByUserID(this, goalId, userId, optionalData, optionalPurchaseAmount, delayInMinutes)
resolve(response.data)
} catch (e) {
reject(checkError(e))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tonicpow-js",
"version": "0.1.36",
"version": "0.1.37",
"description": "TonicPow API Library in JS - https://docs.tonicpow.com",
"main": "lib/api.js",
"repository": {
Expand Down

0 comments on commit b0ab10f

Please sign in to comment.