-
Notifications
You must be signed in to change notification settings - Fork 12
/
Main.as
317 lines (273 loc) · 15.3 KB
/
Main.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
package {
import com.adjust.sdk.Adjust;
import com.adjust.sdk.AdjustConfig;
import com.adjust.sdk.AdjustEvent;
import com.adjust.sdk.AdjustEventSuccess;
import com.adjust.sdk.AdjustEventFailure;
import com.adjust.sdk.AdjustSessionSuccess;
import com.adjust.sdk.AdjustSessionFailure;
import com.adjust.sdk.AdjustAttribution;
import com.adjust.sdk.AdjustEnvironment;
import com.adjust.sdk.AdjustLogLevel;
import flash.display.SimpleButton;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.system.Capabilities;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFieldAutoSize;
import flash.utils.Dictionary;
public class Main extends Sprite {
private static var IsEnabledTextField:TextField;
private static var DeviceIdTextField:TextField;
public function Main() {
buildButton(-4, "Track Simple Event", TrackEventClick);
buildButton(-3, "Track Revenue Event", TrackRevenueClick);
buildButton(-2, "Track Callback Event", TrackCallbackClick);
buildButton(-1, "Track Partner Event", TrackPartnerClick);
buildButton(1, "Enable Offline Mode", EnableOfflineModeClick);
buildButton(2, "Disable Offline Mode", DisableOfflineModeClick);
buildButton(3, "Enable SDK", SetEnableClick);
buildButton(4, "Disable SDK", SetDisableClick);
IsEnabledTextField = buildButton(5, "Is SDK Enabled?", IsEnabledClick);
DeviceIdTextField = buildButton(6, "Get IDs", GetIDs);
// -------- Adjust Configuration -------- //
var adjustConfig:AdjustConfig = new AdjustConfig("2fm9gkqubvpc", AdjustEnvironment.SANDBOX);
adjustConfig.setLogLevel(AdjustLogLevel.VERBOSE);
adjustConfig.setAttributionCallback(function (attribution:AdjustAttribution): void {
var message:String = "Tracker token = " + attribution.getTrackerToken() + "\n" +
"Tracker name = " + attribution.getTrackerName() + "\n" +
"Campaign = " + attribution.getCampaign() + "\n" +
"Network = " + attribution.getNetwork() + "\n" +
"Creative = " + attribution.getCreative() + "\n" +
"Adgroup = " + attribution.getAdgroup() + "\n" +
"Click label = " + attribution.getClickLabel() + "\n" +
"Cost type = " + attribution.getCostType() + "\n" +
"Cost amount = " + (isNaN(attribution.getCostAmount()) ? "NaN" : attribution.getCostAmount().toString()) + "\n" +
"Cost currency = " + attribution.getCostCurrency() + "\n" +
"FB install referrer = " + attribution.getFbInstallReferrer();
showCustomAlert(message, "Attribution Callback");
});
adjustConfig.setEventSuccessCallback(function (eventSuccess:AdjustEventSuccess):void {
var message:String = "Event tracking succeeded\n" +
"Message = " + eventSuccess.getMessage() + "\n" +
"Timestamp = " + eventSuccess.getTimestamp() + "\n" +
"Adid = " + eventSuccess.getAdid() + "\n" +
"Event Token = " + eventSuccess.getEventToken() + "\n" +
"Callback Id = " + eventSuccess.getCallbackId() + "\n" +
"Json Response = " + eventSuccess.getJsonResponse();
showCustomAlert(message, "Event Success Callback");
});
adjustConfig.setEventFailureCallback(function (eventFailure:AdjustEventFailure):void {
var message:String = "Event tracking failed\n" +
"Message = " + eventFailure.getMessage() + "\n" +
"Timestamp = " + eventFailure.getTimestamp() + "\n" +
"Adid = " + eventFailure.getAdid() + "\n" +
"Event Token = " + eventFailure.getEventToken() + "\n" +
"Callback Id = " + eventFailure.getCallbackId() + "\n" +
"Will Retry = " + eventFailure.getWillRetry().toString() + "\n" +
"Json Response = " + eventFailure.getJsonResponse();
showCustomAlert(message, "Event Failure Callback");
});
adjustConfig.setSessionSuccessCallback(function (sessionSuccess:AdjustSessionSuccess): void {
var message:String = "Session tracking succeeded\n" +
"Message = " + sessionSuccess.getMessage() + "\n" +
"Timestamp = " + sessionSuccess.getTimestamp() + "\n" +
"Adid = " + sessionSuccess.getAdid() + "\n" +
"Json Response = " + sessionSuccess.getJsonResponse();
showCustomAlert(message, "Session Success Callback");
});
adjustConfig.setSessionFailureCallback(function (sessionFailure:AdjustSessionFailure):void {
var message:String = "Session tracking failed\n" +
"Message = " + sessionFailure.getMessage() + "\n" +
"Timestamp = " + sessionFailure.getTimestamp() + "\n" +
"Adid = " + sessionFailure.getAdid() + "\n" +
"Will Retry = " + sessionFailure.getWillRetry().toString() + "\n" +
"Json Response = " + sessionFailure.getJsonResponse();
showCustomAlert(message, "Session Failure Callback");
});
adjustConfig.setDeferredDeeplinkCallback(function (deeplink:String):void {
var message:String = "Received deferred deep link\n" +
"Deep link = " + deeplink;
showCustomAlert(message, "Deferred Deeplink Callback");
});
adjustConfig.setSkanUpdatedCallback(function (skanUpdatedData:Dictionary):void {
var message:String = "SKAN values updated\n" +
"Conversion value = " + skanUpdatedData["conversionValue"].toString() + "\n" +
"Coarse value = " + skanUpdatedData["coarseValue"] + "\n" +
"Lock window = " + skanUpdatedData["lockWindow"].toString() + "\n" +
"Error = " + skanUpdatedData["error"];
showCustomAlert(message, "SKAN Updated Callback");
});
Adjust.addGlobalCallbackParameter("scpk1", "scpv1");
Adjust.addGlobalCallbackParameter("scpk2", "scpv2");
Adjust.addGlobalPartnerParameter("sppk1", "sppv1");
Adjust.addGlobalPartnerParameter("sppk2", "sppv2");
Adjust.removeGlobalCallbackParameter("scpk1");
Adjust.removeGlobalPartnerParameter("sppk2");
Adjust.initSdk(adjustConfig);
// -------- Adjust Configuration -------- //
}
private static function TrackEventClick(Event:MouseEvent):void {
trace ("Track simple event button tapped!");
var adjustEvent:AdjustEvent = new AdjustEvent("g3mfiw");
Adjust.trackEvent(adjustEvent);
}
private static function TrackRevenueClick(Event:MouseEvent):void {
trace ("Track revenue event button tapped!");
var adjustEvent:AdjustEvent = new AdjustEvent("a4fd35");
adjustEvent.setRevenue(0.01, "EUR");
Adjust.trackEvent(adjustEvent);
}
private static function TrackCallbackClick(Event:MouseEvent):void {
trace ("Track callback event button tapped!");
var adjustEvent:AdjustEvent = new AdjustEvent("34vgg9");
adjustEvent.addCallbackParameter("foo", "bar");
adjustEvent.addCallbackParameter("a", "b");
adjustEvent.addCallbackParameter("foo", "c");
Adjust.trackEvent(adjustEvent);
}
private static function TrackPartnerClick(Event:MouseEvent):void {
trace ("Track partner event button tapped!");
var adjustEvent:AdjustEvent = new AdjustEvent("w788qs");
adjustEvent.addPartnerParameter("foo", "bar");
adjustEvent.addPartnerParameter("x", "y");
adjustEvent.addPartnerParameter("foo", "z");
Adjust.trackEvent(adjustEvent);
}
private static function EnableOfflineModeClick(Event:MouseEvent):void {
Adjust.switchToOfflineMode();
}
private static function DisableOfflineModeClick(Event:MouseEvent):void {
Adjust.switchBackToOnlineMode();
}
private static function SetEnableClick(Event:MouseEvent):void {
Adjust.enable();
}
private static function SetDisableClick(Event:MouseEvent):void {
Adjust.disable();
}
private static function IsEnabledClick(Event:MouseEvent):void {
Adjust.isEnabled(function (isEnabled:Boolean): void {
if (isEnabled) {
IsEnabledTextField.text = "Is enabled? TRUE";
} else {
IsEnabledTextField.text = "Is enabled? FALSE";
}
});
}
private static function GetIDs(Event:MouseEvent):void {
trace ("Get IDs button tapped");
Adjust.getAttribution(function (attribution:AdjustAttribution): void {
trace("Tracker token = " + attribution.getTrackerToken());
trace("Tracker name = " + attribution.getTrackerName());
trace("Campaign = " + attribution.getCampaign());
trace("Network = " + attribution.getNetwork());
trace("Creative = " + attribution.getCreative());
trace("Adgroup = " + attribution.getAdgroup());
trace("Click label = " + attribution.getClickLabel());
trace("Cost type = " + attribution.getCostType());
trace("Cost amount = " + isNaN(attribution.getCostAmount()) ? "NaN" : attribution.getCostAmount().toString());
trace("Cost currency = " + attribution.getCostCurrency());
trace("FB install referrer = " + attribution.getFbInstallReferrer());
});
Adjust.getAdid(function (adid:String): void {
trace("Adid = " + adid);
});
Adjust.getLastDeeplink(function (lastDeeplink:String): void {
trace("Last deeplink = " + lastDeeplink);
});
Adjust.getIdfa(function (idfa:String): void {
trace("IDFA = " + idfa);
});
Adjust.getIdfv(function (idfv:String): void {
trace("IDFV = " + idfv);
});
Adjust.getAppTrackingAuthorizationStatus(function (status:int): void {
trace("Authorization status = " + status.toString());
});
Adjust.requestAppTrackingAuthorization(function (status:int): void {
trace("Authorization status = " + status.toString());
});
Adjust.updateSkanConversionValue(6, "low", false, function (error:String): void {
trace("Error = " + error);
});
Adjust.getGoogleAdId(function (googleAdId:String): void {
trace("Google Ad ID = " + googleAdId);
});
Adjust.getAmazonAdId(function (amazonAdId:String): void {
trace("Amazon Ad ID = " + amazonAdId);
});
}
private function buildButton(number:int, text:String, clickFunction:Function):TextField {
var buttonHeight:int = 40;
var yPosition:int = 20 + stage.stageHeight * 0.25 +
(number < 0 ? number * buttonHeight : (number - 1) * buttonHeight) + ((number != 1 && number != -1) ?
(number > 0 ? 20 * Math.abs(number) : -20 * Math.abs(number)) : number * 10);
var textField:TextField = new TextField();
textField.text = text;
textField.autoSize = TextFieldAutoSize.CENTER;
textField.mouseEnabled = false;
textField.x = (stage.stageWidth - textField.width) * 0.5;
textField.y = yPosition + 10;
var buttonSprite:Sprite = new Sprite();
buttonSprite.graphics.beginFill(0x82F0FF);
buttonSprite.graphics.drawRect((stage.stageWidth - 400) * 0.5, yPosition, 400, buttonHeight);
buttonSprite.graphics.endFill();
buttonSprite.addChild(textField);
var simpleButton:SimpleButton = new SimpleButton();
simpleButton.downState = buttonSprite;
simpleButton.upState = buttonSprite;
simpleButton.overState = buttonSprite;
simpleButton.hitTestState = buttonSprite;
simpleButton.addEventListener(MouseEvent.CLICK, clickFunction);
addChild(simpleButton);
return textField;
}
private function showCustomAlert(message:String, title:String = "Alert"):void {
var alert:Sprite = new Sprite();
alert.graphics.beginFill(0xCCCCCC, 1);
alert.graphics.drawRect(0, 0, 300, 200);
alert.graphics.endFill();
alert.x = stage.stageWidth / 2 - 150;
alert.y = stage.stageHeight / 2 - 100;
var titleField:TextField = new TextField();
titleField.defaultTextFormat = new TextFormat("Arial", 16, 0x000000, true);
titleField.text = title;
titleField.width = 280;
titleField.height = 30;
titleField.x = 10;
titleField.y = 10;
titleField.selectable = false;
alert.addChild(titleField);
var messageField:TextField = new TextField();
messageField.defaultTextFormat = new TextFormat("Arial", 14, 0x000000);
messageField.text = message;
messageField.width = 280;
messageField.height = 100;
messageField.wordWrap = true;
messageField.x = 10;
messageField.y = 50;
messageField.selectable = false;
alert.addChild(messageField);
var closeButton:Sprite = new Sprite();
closeButton.graphics.beginFill(0x000000, 1);
closeButton.graphics.drawRect(0, 0, 80, 30);
closeButton.graphics.endFill();
closeButton.x = 110;
closeButton.y = 150;
var closeText:TextField = new TextField();
closeText.defaultTextFormat = new TextFormat("Arial", 14, 0xFFFFFF, true);
closeText.text = "Close";
closeText.width = 80;
closeText.height = 30;
closeText.mouseEnabled = false;
closeButton.addChild(closeText);
closeButton.addEventListener(MouseEvent.CLICK, function(event:MouseEvent):void {
stage.removeChild(alert);
});
alert.addChild(closeButton);
stage.addChild(alert);
}
}
}