Skip to content

Commit

Permalink
Flat and Percent based conversion support
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Jan 14, 2020
1 parent 5173ab3 commit dfc8f3e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
12 changes: 6 additions & 6 deletions conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
// 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
func (c *Client) CreateConversionByGoalID(goalID uint64, tncpwSession, additionalData string, delayInMinutes int64) (conversion *Conversion, err error) {
func (c *Client) CreateConversionByGoalID(goalID uint64, tncpwSession, additionalData string, optionalPurchaseAmount float64, delayInMinutes int64) (conversion *Conversion, err error) {

// Must have a name
if goalID == 0 {
Expand All @@ -24,7 +24,7 @@ func (c *Client) CreateConversionByGoalID(goalID uint64, tncpwSession, additiona
}

// Start the post data
data := map[string]string{fieldGoalID: fmt.Sprintf("%d", goalID), fieldVisitorSessionGUID: tncpwSession, fieldAdditionalData: additionalData, fieldDelayInMinutes: fmt.Sprintf("%d", delayInMinutes)}
data := map[string]string{fieldGoalID: fmt.Sprintf("%d", goalID), fieldVisitorSessionGUID: tncpwSession, fieldAdditionalData: additionalData, fieldDelayInMinutes: fmt.Sprintf("%d", delayInMinutes), fieldAmount: fmt.Sprintf("%f", optionalPurchaseAmount)}

// Fire the request
var response string
Expand All @@ -45,7 +45,7 @@ func (c *Client) CreateConversionByGoalID(goalID uint64, tncpwSession, additiona
// 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
func (c *Client) CreateConversionByGoalName(goalName, tncpwSession, additionalData string, delayInMinutes int64) (conversion *Conversion, err error) {
func (c *Client) CreateConversionByGoalName(goalName, tncpwSession, additionalData string, optionalPurchaseAmount float64, delayInMinutes int64) (conversion *Conversion, err error) {

// Must have a name
if len(goalName) == 0 {
Expand All @@ -60,7 +60,7 @@ func (c *Client) CreateConversionByGoalName(goalName, tncpwSession, additionalDa
}

// Start the post data
data := map[string]string{fieldName: goalName, fieldVisitorSessionGUID: tncpwSession, fieldAdditionalData: additionalData, fieldDelayInMinutes: fmt.Sprintf("%d", delayInMinutes)}
data := map[string]string{fieldName: goalName, fieldVisitorSessionGUID: tncpwSession, fieldAdditionalData: additionalData, fieldDelayInMinutes: fmt.Sprintf("%d", delayInMinutes), fieldAmount: fmt.Sprintf("%f", optionalPurchaseAmount)}

// Fire the request
var response string
Expand All @@ -81,7 +81,7 @@ func (c *Client) CreateConversionByGoalName(goalName, tncpwSession, additionalDa
// 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
func (c *Client) CreateConversionByUserID(goalID, userID uint64, additionalData string, delayInMinutes int64) (conversion *Conversion, err error) {
func (c *Client) CreateConversionByUserID(goalID, userID uint64, additionalData string, optionalPurchaseAmount float64, delayInMinutes int64) (conversion *Conversion, err error) {

// Must have a name
if goalID == 0 {
Expand All @@ -96,7 +96,7 @@ func (c *Client) CreateConversionByUserID(goalID, userID uint64, additionalData
}

// Start the post data
data := map[string]string{fieldGoalID: fmt.Sprintf("%d", goalID), fieldUserID: fmt.Sprintf("%d", userID), fieldAdditionalData: additionalData, fieldDelayInMinutes: fmt.Sprintf("%d", delayInMinutes)}
data := map[string]string{fieldGoalID: fmt.Sprintf("%d", goalID), fieldUserID: fmt.Sprintf("%d", userID), fieldAdditionalData: additionalData, fieldDelayInMinutes: fmt.Sprintf("%d", delayInMinutes), fieldAmount: fmt.Sprintf("%f", optionalPurchaseAmount)}

// Fire the request
var response string
Expand Down
1 change: 1 addition & 0 deletions definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const (
// Field key names for various model requests
fieldAdditionalData = "additional_data"
fieldAdvertiserProfileID = "advertiser_profile_id"
fieldAmount = "amount"
fieldApiKey = "api_key"
fieldCampaignID = "campaign_id"
fieldDelayInMinutes = "delay_in_minutes"
Expand Down
33 changes: 28 additions & 5 deletions examples/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func main() {
}

//
// Example: Create a Goal
// Example: Create a Goal (flat payout)
//
goal := &tonicpow.Goal{
CampaignID: campaign.ID,
Expand All @@ -245,6 +245,23 @@ func main() {
os.Exit(1)
}

//
// Example: Create a Goal (percent payout)
//
goalPercent := &tonicpow.Goal{
//CampaignID: 1,
CampaignID: campaign.ID,
Description: "Get 10% of all action!",
//Name: fmt.Sprintf("%s%d", "all-action", rand.Intn(100000)),
Name: "all-action",
PayoutRate: 0.1, // 10% as a float
PayoutType: "percent",
Title: "10% Commissions",
}
if goalPercent, err = createGoal(goalPercent, userSessionToken); err != nil {
os.Exit(1)
}

//
// Example: Create a Link (making a custom short code using the user's name)
//
Expand Down Expand Up @@ -312,7 +329,7 @@ func main() {
// Example: Fire a conversion on a goal (by user id)
//
var newConversion *tonicpow.Conversion
if newConversion, err = TonicPowAPI.CreateConversionByUserID(goal.ID, user.ID, "", 5); err != nil {
if newConversion, err = TonicPowAPI.CreateConversionByUserID(goal.ID, user.ID, "", 0.00, 5); err != nil {
os.Exit(1)
}

Expand All @@ -321,7 +338,7 @@ func main() {
//
// Example: Fire a conversion on a goal (by visitor)
//
if newConversion, err = TonicPowAPI.CreateConversionByGoalID(goal.ID, visitorSession.TncpwSession, "", 10); err != nil {
if newConversion, err = TonicPowAPI.CreateConversionByGoalID(goal.ID, visitorSession.TncpwSession, "", 0.00, 10); err != nil {
os.Exit(1)
}

Expand Down Expand Up @@ -349,11 +366,17 @@ func main() {
//
// Example: Create Conversion by User ID
//
if newConversion, err = TonicPowAPI.CreateConversionByUserID(1, 1, "", 0); err != nil {
if newConversion, err = TonicPowAPI.CreateConversionByUserID(1, 2, "", 0.00, 0); err != nil {
os.Exit(1)
}

log.Printf("new conversion: %d", newConversion.ID)
//
// Example: Create Conversion by User ID (percent based conversion - using a purchase amount, or some tx of value)
//
//if newConversion, err = TonicPowAPI.CreateConversionByUserID(goalPercent.ID, 2, "", 5.00, 0); err != nil {
// os.Exit(1)
//}
//log.Printf("new conversion: %d", newConversion.ID)

log.Println("examples complete!")
}
Expand Down

0 comments on commit dfc8f3e

Please sign in to comment.