Skip to content

Commit

Permalink
Merge pull request #101 from adjust/criteo_update
Browse files Browse the repository at this point in the history
Criteo update
  • Loading branch information
nonelse committed Apr 29, 2015
2 parents 930311f + b3d7281 commit 61773e7
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 35 deletions.
29 changes: 15 additions & 14 deletions doc/criteo_plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@ to `Copy items if needed` and select the radio button to `Create groups`.

Now you can integrate each of the different Criteo events, like in the following examples:

### View Search

```objc
#import "ADJCriteo.h"

ADJEvent *event = [ADJEvent eventWithEventToken:@"{viewSearchEventToken}"];

[ADJCriteo injectViewSearchIntoEvent:event checkInDate:@"2015-01-01" checkOutDate:@"2015-01-07"];

[Adjust trackEvent:event];
```
### View Listing

```objc
Expand Down Expand Up @@ -78,7 +66,8 @@ ADJCriteoProduct *product2 = [ADJCriteoProduct productWithId:@"productId2" price
ADJCriteoProduct *product3 = [ADJCriteoProduct productWithId:@"productId3" price:50 quantity:2];
NSArray *products = @[product1, product2, product3];
[ADJCriteo injectTransactionConfirmedIntoEvent:event products:products customerId:@"customerId1"];
[ADJCriteo injectTransactionConfirmedIntoEvent:event products:products
transactionId:@"transactionId1" customerId:@"customerId1"];
[Adjust trackEvent:event];
```
Expand Down Expand Up @@ -153,5 +142,17 @@ The hashed email can be removed by setting the `injectHashedEmailIntoCriteoEvent
```objc
#import "ADJCriteo.h"
AdjustCriteo.injectHashedEmailIntoCriteoEvents("8455938a1db5c475a87d76edacb6284e");
[ADJCriteo injectHashedEmailIntoCriteoEvents:@"8455938a1db5c475a87d76edacb6284e"];
```

### Search dates

It's possible to attach a check-in and check-out date to every Criteo event with the `injectViewSearchDatesIntoCriteoEvent` method. The dates will be sent with every Criteo event for the duration of the application lifecycle, so it must be set again when the app is re-lauched.

The search dates can be removed by setting the `injectViewSearchDatesIntoCriteoEvents` dates with `nil`.

```objc
#import "ADJCriteo.h"

[ADJCriteo injectViewSearchDatesIntoCriteoEvents:@"2015-01-01" checkOutDate:@"2015-01-07"];
```
8 changes: 4 additions & 4 deletions plugin/ADJCriteo.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@

@interface ADJCriteo : NSObject

+ (void)injectViewSearchIntoEvent:(ADJEvent *)event
checkInDate:(NSString *)din
checkOutDate:(NSString *)dout;

+ (void)injectViewListingIntoEvent:(ADJEvent *)event
productIds:(NSArray *)productIds
customerId:(NSString *)customerId;
Expand All @@ -45,6 +41,7 @@

+ (void)injectTransactionConfirmedIntoEvent:(ADJEvent *)event
products:(NSArray *)products
transactionId:(NSString *)transactionId
customerId:(NSString *)customerId;

+ (void)injectUserLevelIntoEvent:(ADJEvent *)event
Expand All @@ -69,4 +66,7 @@
customerId:(NSString *)customerId;

+ (void)injectHashedEmailIntoCriteoEvents:(NSString *)hashEmail;

+ (void)injectViewSearchDatesIntoCriteoEvents:(NSString *)checkInDate
checkOutDate:(NSString *)checkOutDate;
@end
58 changes: 41 additions & 17 deletions plugin/ADJCriteo.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,21 @@ + (ADJCriteoProduct *) productWithId:(NSString *)productId
@implementation ADJCriteo

static NSString * hashEmailInternal;
static NSString * checkInDateInternal;
static NSString * checkOutDateInternal;

+ (id<ADJLogger>) logger {
return ADJAdjustFactory.logger;
}

+ (void)injectHashEmail:(ADJEvent *)event {
if (hashEmailInternal == nil) {
return;
}
[event addPartnerParameter:@"criteo_email_hash" value:hashEmailInternal];
}

+ (void)injectViewSearchIntoEvent:(ADJEvent *)event
checkInDate:(NSString *)din
checkOutDate:(NSString *)dout
{
[event addPartnerParameter:@"din" value:din];
[event addPartnerParameter:@"dout" value:dout];

[ADJCriteo injectHashEmail:event];
[ADJCriteo injectOptionalParams:event];
}

+ (void)injectViewListingIntoEvent:(ADJEvent *)event
Expand All @@ -71,7 +66,7 @@ + (void)injectViewListingIntoEvent:(ADJEvent *)event
NSString * jsonProductsIds = [ADJCriteo createCriteoVLFromProducts:productIds];
[event addPartnerParameter:@"criteo_p" value:jsonProductsIds];

[ADJCriteo injectHashEmail:event];
[ADJCriteo injectOptionalParams:event];
}

+ (void)injectViewProductIntoEvent:(ADJEvent *)event
Expand All @@ -81,7 +76,7 @@ + (void)injectViewProductIntoEvent:(ADJEvent *)event
[event addPartnerParameter:@"customer_id" value:customerId];
[event addPartnerParameter:@"criteo_p" value:productId];

[ADJCriteo injectHashEmail:event];
[ADJCriteo injectOptionalParams:event];
}

+ (void)injectCartIntoEvent:(ADJEvent *)event
Expand All @@ -93,19 +88,21 @@ + (void)injectCartIntoEvent:(ADJEvent *)event
NSString * jsonProducts = [ADJCriteo createCriteoVBFromProducts:products];
[event addPartnerParameter:@"criteo_p" value:jsonProducts];

[ADJCriteo injectHashEmail:event];
[ADJCriteo injectOptionalParams:event];
}

+ (void)injectTransactionConfirmedIntoEvent:(ADJEvent *)event
products:(NSArray *)products
transactionId:(NSString *)transactionId
customerId:(NSString *)customerId
{
[event addPartnerParameter:@"customer_id" value:customerId];
[event addPartnerParameter:@"transaction_id" value:transactionId];

NSString * jsonProducts = [ADJCriteo createCriteoVBFromProducts:products];
[event addPartnerParameter:@"criteo_p" value:jsonProducts];

[ADJCriteo injectHashEmail:event];
[ADJCriteo injectOptionalParams:event];
}

+ (void)injectUserLevelIntoEvent:(ADJEvent *)event
Expand All @@ -117,7 +114,7 @@ + (void)injectUserLevelIntoEvent:(ADJEvent *)event
NSString * uiLevelString = [NSString stringWithFormat:@"%lu",(unsigned long)uiLevel];
[event addPartnerParameter:@"ui_level" value:uiLevelString];

[ADJCriteo injectHashEmail:event];
[ADJCriteo injectOptionalParams:event];
}

+ (void)injectUserStatusIntoEvent:(ADJEvent *)event
Expand All @@ -127,7 +124,7 @@ + (void)injectUserStatusIntoEvent:(ADJEvent *)event
[event addPartnerParameter:@"customer_id" value:customerId];
[event addPartnerParameter:@"ui_status" value:uiStatus];

[ADJCriteo injectHashEmail:event];
[ADJCriteo injectOptionalParams:event];
}

+ (void)injectAchievementUnlockedIntoEvent:(ADJEvent *)event
Expand All @@ -137,7 +134,7 @@ + (void)injectAchievementUnlockedIntoEvent:(ADJEvent *)event
[event addPartnerParameter:@"customer_id" value:customerId];
[event addPartnerParameter:@"ui_achievmnt" value:uiAchievement];

[ADJCriteo injectHashEmail:event];
[ADJCriteo injectOptionalParams:event];
}

+ (void)injectCustomEventIntoEvent:(ADJEvent *)event
Expand All @@ -147,7 +144,7 @@ + (void)injectCustomEventIntoEvent:(ADJEvent *)event
[event addPartnerParameter:@"customer_id" value:customerId];
[event addPartnerParameter:@"ui_data" value:uiData];

[ADJCriteo injectHashEmail:event];
[ADJCriteo injectOptionalParams:event];
}

+ (void)injectCustomEvent2IntoEvent:(ADJEvent *)event
Expand All @@ -161,14 +158,41 @@ + (void)injectCustomEvent2IntoEvent:(ADJEvent *)event
NSString * uiData3String = [NSString stringWithFormat:@"%lu",(unsigned long)uiData3];
[event addPartnerParameter:@"ui_data3" value:uiData3String];

[ADJCriteo injectHashEmail:event];
[ADJCriteo injectOptionalParams:event];
}

+ (void)injectHashedEmailIntoCriteoEvents:(NSString *)hashEmail
{
hashEmailInternal = hashEmail;
}

+ (void)injectViewSearchDatesIntoCriteoEvents:(NSString *)checkInDate
checkOutDate:(NSString *)checkOutDate
{
checkInDateInternal = checkInDate;
checkOutDateInternal = checkOutDate;
}

+ (void)injectOptionalParams:(ADJEvent *)event {
[ADJCriteo injectHashEmail:event];
[ADJCriteo injectSearchDates:event];
}

+ (void)injectHashEmail:(ADJEvent *)event {
if (hashEmailInternal == nil) {
return;
}
[event addPartnerParameter:@"criteo_email_hash" value:hashEmailInternal];
}

+ (void)injectSearchDates:(ADJEvent *)event {
if (checkInDateInternal == nil || checkOutDateInternal == nil) {
return;
}
[event addPartnerParameter:@"din" value:checkInDateInternal];
[event addPartnerParameter:@"dout" value:checkOutDateInternal];
}

+ (NSString*) createCriteoVBFromProducts:(NSArray*) products
{
if (products == nil) {
Expand Down

0 comments on commit 61773e7

Please sign in to comment.