Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notification Tracking #27

Merged
merged 18 commits into from
Feb 25, 2021

Conversation

ravjain-adb
Copy link
Contributor

Description

  • Adding location displayed api.
  • Moving Target request builder to another class
  • Moving common code to a separate function
  • Adding a demo test app

Pending

  • Location clicked API
  • Testing

Related Issue

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@ravjain-adb ravjain-adb force-pushed the notification-tracking-1-with-app branch from e43ef70 to 1369d49 Compare February 18, 2021 06:09
@ravjain-adb ravjain-adb changed the title Notification Tracking - Location displayed API Notification Tracking Feb 18, 2021
@ravjain-adb ravjain-adb linked an issue Feb 18, 2021 that may be closed by this pull request
4 tasks
@ravjain-adb ravjain-adb force-pushed the notification-tracking-1-with-app branch from 1369d49 to f5a57cd Compare February 19, 2021 01:01
@ravjain-adb ravjain-adb force-pushed the notification-tracking-1-with-app branch from b09b34b to cf882b3 Compare February 20, 2021 23:40
@ravjain-adb ravjain-adb changed the base branch from Prefetch to dev February 20, 2021 23:40
Podfile Outdated
@@ -12,6 +12,14 @@ target 'AEPTarget' do
pod 'AEPIdentity'
end

target 'AEPTargetDemoApp' do
pod 'AEPCore'
pod 'AEPRulesEngine'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AEPCore has a dependency on AEPRulesEngine so this will be pulled in. We can omit it here unless we are targeting some specific version.

@@ -0,0 +1,64 @@
/*
Copyright 2020 Adobe. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright 2021, check this for all other files you added


/// Returns true if the event is location display request event
var isLocationDisplayedEvent: Bool {
return data?[TargetConstants.EventDataKeys.IS_LOCATION_DISPLAYED] != nil ? true : false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: You can rewrite this as return data?[TargetConstants.EventDataKeys.IS_LOCATION_DISPLAYED] ?? false


MobileCore.setLogLevel(.trace)
MobileCore.registerExtensions([Lifecycle.self, Identity.self, Target.self, Signal.self])
MobileCore.configureWith(appId: "launch-ENc28aaf2fb6934cff830c8d3ddc5465b1-development")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please specify the name of the launch property/ Org as well here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Let's integrate Assurance as well (in a future PR).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Later: You might want to implement Lifecycle in the app as we will need to check we are sending all lifecycle data to Target correctly.

private(set) var thirdPartyId: String?
private(set) var thirdPartyId: String? {
didSet {
dataStore.set(key: TargetConstants.DataStoreKeys.THIRD_PARTY_ID, value: tntId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value should be thirdPartyId and not tntId here, let's fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is deleted as we dont store 3rd party in db

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed as we discussed and here is the separate task logged for it - #21

// if not, Log and bail out

guard let mboxJson: [String: Any?] = targetState.prefetchedMboxJsonDicts[mBoxName] ?? targetState.loadedMboxJsonDicts[mBoxName] else {
Log.warning(label: Target.LOG_TAG, "\(TargetError.ERROR_CLICK_NOTIFICATION_SEND_FAILED) \(TargetError.ERROR_NO_CACHED_MBOX_FOUND) \(mBoxName) For more details refer to https://aep-sdks.gitbook.io/docs/using-mobile-extensions/adobe-target/target-api-reference#send-an-mbox-click-notification")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove doc reference from errors. It adds to clutter plus the doc location is subject to change.


// Get the configuration shared state
guard let configuration = getSharedState(extensionName: TargetConstants.Configuration.EXTENSION_NAME, event: event)?.value else {
Log.error(label: Target.LOG_TAG, "Location displayed unsuccessful, configuration is null")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix log message. It says "Location displayed..."


// bail out if the target configuration is not available or if the privacy is opted-out
if let error = prepareForTargetRequest(configData: configuration) {
Log.error(label: Target.LOG_TAG, TargetError.ERROR_DISPLAY_NOTIFICATION_SEND_FAILED + error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix error - ERROR_DISPLAY_NOTIFICATION_SEND_FAILED. It should be for click notification

Log.trace(label: Target.LOG_TAG, "Handling Locations Displayed - event \(event.name) type: \(event.type) source: \(event.source) ")

// Get the configuration shared state
guard let configuration = getSharedState(extensionName: TargetConstants.Configuration.EXTENSION_NAME, event: event)?.value else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a TODO for getting the latest configuration wherever needed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we might not need this 👆 because Configuration will resolve with forward/ backward resolve in case of pending. Nil will be returned only when there is no shared state.

let lifecycleSharedState = getSharedState(extensionName: TargetConstants.Lifecycle.EXTENSION_NAME, event: event)?.value
let identitySharedState = getSharedState(extensionName: TargetConstants.Identity.EXTENSION_NAME, event: event)?.value

for mBoxName: String in mBoxNames {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: type is inferred, not needed.

Copy link
Contributor

@swarna04 swarna04 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to address the comments in the same PR or next as convenient.

@@ -0,0 +1,25 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this as we are integrating AEPCore via CocoaPods. It's needed when using SPM to resolve package dependencies.

prefetch()
}.padding(10)

Button("Location displayed") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: "Locations displayed"


MobileCore.setLogLevel(.trace)
MobileCore.registerExtensions([Lifecycle.self, Identity.self, Target.self, Signal.self])
MobileCore.configureWith(appId: "launch-ENc28aaf2fb6934cff830c8d3ddc5465b1-development")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Later: You might want to implement Lifecycle in the app as we will need to check we are sending all lifecycle data to Target correctly.

@@ -1,5 +1,5 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename DeliveryResponse -> TargetDeliveryResponse

@@ -0,0 +1,216 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename DeliveryRequestBuilder -> TargetDeliveryRequestBuilder

var tokens: [String] = []
if let optionsArray = cachedMboxJson?[TargetConstants.TargetJson.OPTIONS] as? [[String: Any?]?] {
for option in optionsArray {
guard let optionEventToken: String = option?[TargetConstants.TargetJson.Metric.EVENT_TOKEN] as? String else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

guard let optionEventToken = ...

return notification
}

static func getClickedNotification(cachedMboxJson: [String: Any?], parameters: TargetParameters?, timestamp: Int64, lifecycleContextData: [String: String]?) -> Notification? {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: rename parameters->targetParameters

let id = UUID().uuidString

// Set parameters: getMboxParameters
let mBoxparameters: [String: String] = getMboxParameters(mboxParameters: parameters?.parameters, lifecycleContextData: lifecycleContextData)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let mboxparameters = ...


let mboxName = cachedMboxJson[TargetConstants.TargetJson.Mbox.NAME] as? String ?? ""

let mBox = Mbox(name: mboxName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mBox->mbox

let mBox = Mbox(name: mboxName)

guard let metrics = cachedMboxJson[TargetConstants.TargetJson.METRICS] as? [Any?] else {
return Notification(id: id, timestamp: timestamp, type: TargetConstants.TargetJson.MetricType.CLICK, mbox: mBox, parameters: mBoxparameters, profileParameters: parameters?.profileParameters, order: parameters?.order?.toInternalOrder(), product: parameters?.product?.toInternalProduct())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you confirm we send click notifications even without tokens?

@ravjain-adb ravjain-adb merged commit 52d263a into adobe:dev Feb 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[prefetch] missing the mapping for lifecycle data Create a test app (Swift) Epic: Notification tracking
3 participants