<commit_before>//
//  CARAccengageTagHandler.swift
//  Cargo
//
//  Created by <NAME> on 05/10/16.
//  Copyright © 2016 55 All rights reserved.
//

import Foundation
import AccengageKit


/// The class which handles interactions with the Accengage SDK.
class CARAccengageTagHandler: CARTagHandler {
    
/* *********************************** Variables Declaration ************************************ */

    /** Constants used to define callbacks in the register and in the execute method */
    let ACC_INIT = "ACC_init";
    let ACC_TAG_EVENT = "ACC_tagEvent";
    let ACC_TAG_PURCHASE = "ACC_tagPurchase";
    let ACC_ADD_TO_CART = "ACC_tagAddToCart";
    let ACC_TAG_LEAD = "ACC_tagLead";
    let ACC_UPDATE_DEVICE_INFO = "ACC_updateDeviceInfo";

    let PARTNER_ID = "partnerId";
    let PRIVATE_KEY = "privateKey";


/* ********************************** Handler core methods ************************************** */

    /// Called to instantiate the handler with its key and name properties.
    /// Register the callbacks to the container. After a dataLayer.push(),
    /// these will trigger the execute method of this handler.
    init() {
        super.init(key: "ACC", name: "Accengage");

        cargo.registerTagHandler(self, key: ACC_INIT);
        cargo.registerTagHandler(self, key: ACC_TAG_EVENT);
        cargo.registerTagHandler(self, key: ACC_TAG_PURCHASE);
        cargo.registerTagHandler(self, key: ACC_ADD_TO_CART);
        cargo.registerTagHandler(self, key: ACC_TAG_LEAD);
        cargo.registerTagHandler(self, key: ACC_UPDATE_DEVICE_INFO);
    }

    /// Callback from GTM container designed to execute a specific method
    /// from its tag and the parameters received.
    ///
    /// - Parameters:
    ///   - tagName: the tag name of the aimed method
    ///   - parameters: Dictionary of parameters
    override func execute(_ tagName: String, parameters: [AnyHashable: Any]) {
        super.execute(tagName, parameters: parameters);

        if (tagName == ACC_INIT) {
            self.initialize(parameters);
            return ;
        }
        // check whether the SDK has been initialized before calling any method
        else if (self.initialized) {
            switch (tagName) {
                case ACC_TAG_EVENT:
                    self.tagEvent(parameters);
                    break ;
                case ACC_TAG_PURCHASE:
                    self.tagPurchaseEvent(parameters);
                    break ;
                case ACC_ADD_TO_CART:
                    self.tagCartEvent(parameters);
                    break ;
                case ACC_TAG_LEAD:
                    self.tagLead(parameters);
                    break ;
                case ACC_UPDATE_DEVICE_INFO:
                    self.updateDeviceInfo(parameters);
                    break ;
                default:
                    logger.logUnknownFunctionTag(tagName);
            }
        }
        else {
            logger.logUninitializedFramework();
        }
    }

    
/* ************************************ SDK initialization ************************************** */

    /// The method you need to call first. Allow you to initialize Accengage SDK
    /// Register the private key and the partner ID to the Accengage SDK.
    ///
    /// - Parameters:
    ///   - privateKey: private key Accengage gives when you register your app
    ///   - partnerId: partner ID Accengage gives when you register your app
    private func initialize(_ parameters: [AnyHashable: Any]) {
        if let partnerId = parameters[PARTNER_ID], let privateKey = parameters[PRIVATE_KEY] {
            BMA4STracker.track(withPartnerId: partnerId as! String,
                               privateKey: privateKey as! String,
                               options: cargo.launchOptions);
            // the SDK is now initialized
            self.initialized = true;
            logger.logParamSetWithSuccess(PARTNER_ID, value: partnerId);
            logger.logParamSetWithSuccess(PRIVATE_KEY, value: privateKey);
            logger.logParamSetWithSuccess("launchOptions", value: cargo.launchOptions);
        }
        else {<commit_msg>warning correction<commit_after>//
//  CARAccengageTagHandler.swift
//  Cargo
//
//  Created by <NAME> on 05/10/16.
//  Copyright © 2016 55 All rights reserved.
//

import Foundation
import AccengageKit


/// The class which handles interactions with the Accengage SDK.
class CARAccengageTagHandler: CARTagHandler {
    
/* *********************************** Variables Declaration ************************************ */

    /** Constants used to define callbacks in the register and in the execute method */
    let ACC_INIT = "ACC_init";
    let ACC_TAG_EVENT = "ACC_tagEvent";
    let ACC_TAG_PURCHASE = "ACC_tagPurchase";
    let ACC_ADD_TO_CART = "ACC_tagAddToCart";
    let ACC_TAG_LEAD = "ACC_tagLead";
    let ACC_UPDATE_DEVICE_INFO = "ACC_updateDeviceInfo";

    let PARTNER_ID = "partnerId";
    let PRIVATE_KEY = "privateKey";


/* ********************************** Handler core methods ************************************** */

    /// Called to instantiate the handler with its key and name properties.
    /// Register the callbacks to the container. After a dataLayer.push(),
    /// these will trigger the execute method of this handler.
    init() {
        super.init(key: "ACC", name: "Accengage");

        cargo.registerTagHandler(self, key: ACC_INIT);
        cargo.registerTagHandler(self, key: ACC_TAG_EVENT);
        cargo.registerTagHandler(self, key: ACC_TAG_PURCHASE);
        cargo.registerTagHandler(self, key: ACC_ADD_TO_CART);
        cargo.registerTagHandler(self, key: ACC_TAG_LEAD);
        cargo.registerTagHandler(self, key: ACC_UPDATE_DEVICE_INFO);
    }

    /// Callback from GTM container designed to execute a specific method
    /// from its tag and the parameters received.
    ///
    /// - Parameters:
    ///   - tagName: the tag name of the aimed method
    ///   - parameters: Dictionary of parameters
    override func execute(_ tagName: String, parameters: [AnyHashable: Any]) {
        super.execute(tagName, parameters: parameters);

        if (tagName == ACC_INIT) {
            self.initialize(parameters);
            return ;
        }
        // check whether the SDK has been initialized before calling any method
        else if (self.initialized) {
            switch (tagName) {
                case ACC_TAG_EVENT:
                    self.tagEvent(parameters);
                    break ;
                case ACC_TAG_PURCHASE:
                    self.tagPurchaseEvent(parameters);
                    break ;
                case ACC_ADD_TO_CART:
                    self.tagCartEvent(parameters);
                    break ;
                case ACC_TAG_LEAD:
                    self.tagLead(parameters);
                    break ;
                case ACC_UPDATE_DEVICE_INFO:
                    self.updateDeviceInfo(parameters);
                    break ;
                default:
                    logger.logUnknownFunctionTag(tagName);
            }
        }
        else {
            logger.logUninitializedFramework();
        }
    }

    
/* ************************************ SDK initialization ************************************** */

    /// The method you need to call first. Allow you to initialize Accengage SDK
    /// Register the private key and the partner ID to the Accengage SDK.
    ///
    /// - Parameters:
    ///   - privateKey: private key Accengage gives when you register your app
    ///   - partnerId: partner ID Accengage gives when you register your app
    private func initialize(_ parameters: [AnyHashable: Any]) {
        if let partnerId = parameters[PARTNER_ID], let privateKey = parameters[PRIVATE_KEY] {
            BMA4STracker.track(withPartnerId: partnerId as! String,
                               privateKey: privateKey as! String,
                               options: cargo.launchOptions);
            // the SDK is now initialized
            self.initialized = true;
            logger.logParamSetWithSuccess(PARTNER_ID, value: partnerId);
            logger.logParamSetWithSuccess(PRIVATE_KEY, value: privateKey);
            logger.logParamSetWithSuccess("launchOptions", value: cargo.launchOptions as Any);
        }
        else {
{'fraction_non_alphanumeric': 0.13187605092481383, 'fraction_numerical': 0.0031227480182560653, 'mean_word_length': 2.200230591852421, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6340890', 'n_tokens_mistral': 2232, 'n_tokens_neox': 2091, 'n_words': 601}