From 78ca4984f1081c70ce8ca34ee04ef730ef16a886 Mon Sep 17 00:00:00 2001 From: Damodaram <> Date: Tue, 16 Jun 2020 09:51:59 +0530 Subject: [PATCH] parsing analytics data --- .../Atomic/Molecules/Items/CarouselItemModel.swift | 5 +++++ MVMCoreUI/Atomic/Organisms/Carousel.swift | 12 ++++++++++++ .../ModelProtocols/CarouselItemModelProtocol.swift | 7 +++++++ 3 files changed, 24 insertions(+) diff --git a/MVMCoreUI/Atomic/Molecules/Items/CarouselItemModel.swift b/MVMCoreUI/Atomic/Molecules/Items/CarouselItemModel.swift index 15a83552..9165cec7 100644 --- a/MVMCoreUI/Atomic/Molecules/Items/CarouselItemModel.swift +++ b/MVMCoreUI/Atomic/Molecules/Items/CarouselItemModel.swift @@ -10,6 +10,8 @@ import Foundation @objcMembers public class CarouselItemModel: MoleculeCollectionItemModel, CarouselItemModelProtocol { + public var analyticsData: [String : String]? + //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- @@ -28,6 +30,7 @@ import Foundation private enum CodingKeys: String, CodingKey { case peakingUI case peakingArrowColor + case analyticsData } //-------------------------------------------------- @@ -38,6 +41,7 @@ import Foundation let typeContainer = try decoder.container(keyedBy: CodingKeys.self) peakingUI = try typeContainer.decodeIfPresent(Bool.self, forKey: .peakingUI) peakingArrowColor = try typeContainer.decodeIfPresent(Color.self, forKey: .peakingArrowColor) + analyticsData = try typeContainer.decodeIfPresent([String:String].self, forKey: .analyticsData) try super.init(from: decoder) } @@ -46,5 +50,6 @@ import Foundation var container = encoder.container(keyedBy: CodingKeys.self) try container.encodeIfPresent(peakingUI, forKey: .peakingUI) try container.encodeIfPresent(peakingArrowColor, forKey: .peakingArrowColor) + try container.encodeIfPresent(analyticsData, forKey: .analyticsData) } } diff --git a/MVMCoreUI/Atomic/Organisms/Carousel.swift b/MVMCoreUI/Atomic/Organisms/Carousel.swift index abc0e74b..baa62c88 100644 --- a/MVMCoreUI/Atomic/Organisms/Carousel.swift +++ b/MVMCoreUI/Atomic/Organisms/Carousel.swift @@ -163,6 +163,9 @@ open class Carousel: View { pageIndex = carouselModel.index pagingView?.currentIndex = carouselModel.index collectionView.reloadData() + + // track analyticsData + trackSwipeActionAnalyticsforIndex(pageIndex) } //-------------------------------------------------- @@ -297,6 +300,13 @@ open class Carousel: View { cell.accessibilityElementsHidden = true } } + func trackSwipeActionAnalyticsforIndex(_ index : Int){ + guard let itemModel = molecules?[index], + let analyticsData = itemModel.analyticsData, + let viewcontrollerObject = delegateObject?.moleculeDelegate as? MVMCoreViewControllerProtocol else { return } + MVMCoreUILoggingHandler.shared()?.defaultLogAction(forController:viewcontrollerObject, actionInformation: analyticsData, additionalData: analyticsData) + + } } extension Carousel: UICollectionViewDelegateFlowLayout { @@ -454,5 +464,7 @@ extension Carousel: UIScrollViewDelegate { // Cycle to other end if on buffer cell. pagingView?.currentIndex = pageIndex showPeaking(true) + // track analyticsData + trackSwipeActionAnalyticsforIndex(pageIndex) } } diff --git a/MVMCoreUI/Atomic/Protocols/ModelProtocols/CarouselItemModelProtocol.swift b/MVMCoreUI/Atomic/Protocols/ModelProtocols/CarouselItemModelProtocol.swift index 198cf80d..2d8444b5 100644 --- a/MVMCoreUI/Atomic/Protocols/ModelProtocols/CarouselItemModelProtocol.swift +++ b/MVMCoreUI/Atomic/Protocols/ModelProtocols/CarouselItemModelProtocol.swift @@ -10,4 +10,11 @@ import Foundation public protocol CarouselItemModelProtocol: ContainerModelProtocol { + var analyticsData: [String:String]? { get } +} +public extension CarouselItemModelProtocol { + + var analyticsData: [String:String]? { + get { return nil} + } }