feat(tealium): update wrapper (#3883)

Co-authored-by: Karen Tamayo <karentamayo@Karens-MBP.webpass.net>
This commit is contained in:
Karen Tamayo 2021-12-21 09:58:13 -08:00 committed by GitHub
parent 50069b6fe8
commit 771552cd42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,229 +1,366 @@
import { Cordova, AwesomeCordovaNativePlugin, Plugin } from '@awesome-cordova-plugins/core';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Plugin, Cordova, CordovaProperty, CordovaInstance, InstanceProperty, AwesomeCordovaNativePlugin } from '@awesome-cordova-plugins/core';
import { Observable } from 'rxjs';
export interface TealConfig { export enum Collectors {
/** AppData = 'AppData',
* Your Tealium account name Connectivity = 'Connectivity',
*/ DeviceData = 'DeviceData',
account: string; Lifecycle = 'Lifecycle',
/** }
* Your Tealium profile name
*/ export enum Dispatchers {
profile: string; Collect = 'Collect',
/** TagManagement = 'TagManagement',
* Your Tealium environment name (dev, qa, prod) RemoteCommands = 'RemoteCommands',
*/ }
environment: string;
/** export enum Expiry {
* Arbitrary instance name string. Must be consistent for all calls to Tealium API. forever = 'forever',
*/ untilRestart = 'untilRestart',
instance: string; session = 'session',
/** }
* Enables ("true") or disables ("false") lifecycle reporting. Default true if omitted.
*/ export enum ConsentPolicy {
isLifecycleEnabled?: string; ccpa = 'ccpa',
/** gdpr = 'gdpr',
* Not usually required. Sets a custom URL override for dispatches to UDH. }
*/
collectDispatchURL?: string; export interface TealiumDispatch {
/** dataLayer: Map<string, any>;
* Your Tealium UDH profile. Only active if you do not have collectDispatchURL set. type: string;
*/ toJson(): string;
collectDispatchProfile?: string; }
/**
* Enables ("true") or disables ("false") Crash Reporter module for Android. Default false if omitted. export class TealiumView implements TealiumDispatch {
*/ public type: string = 'view';
isCrashReporterEnabled?: string; constructor(public viewName: string, public dataLayer: Map<string, any>) {}
toJson() {
let dictionary: any = {};
dictionary['type'] = this.type;
dictionary['dataLayer'] = {};
this.dataLayer.forEach((k, v) => {
dictionary['dataLayer'][k] = v;
});
dictionary['type'] = this.type;
dictionary['viewName'] = this.viewName;
return JSON.stringify(dictionary);
}
}
export class TealiumEvent implements TealiumDispatch {
public type: string = 'event';
constructor(public eventName: string, public dataLayer: Map<string, any>) {}
toJson() {
let dictionary: any = {};
dictionary['type'] = this.type;
dictionary['dataLayer'] = {};
this.dataLayer.forEach((k, v) => {
dictionary['dataLayer'][k] = v;
});
dictionary['type'] = this.type;
dictionary['eventName'] = this.eventName;
return JSON.stringify(dictionary);
}
}
export class ConsentExpiry {
constructor(public time: number, public unit: TimeUnit) {}
}
export enum TimeUnit {
minutes = 'minutes',
hours = 'hours',
days = 'days',
months = 'months',
}
export enum ConsentStatus {
consented = 'consented',
notConsented = 'notConsented',
unknown = 'unknown',
}
export enum LogLevel {
dev = 'dev',
qa = 'qa',
prod = 'prod',
silent = 'silent',
}
export enum TealiumEnvironment {
dev = 'dev',
qa = 'qa',
prod = 'prod',
}
export enum ConsentCategories {
analytics = 'analytics',
affiliates = 'affiliates',
displayAds = 'display_ads',
email = 'email',
personalization = 'personalization',
search = 'search',
social = 'social',
bigData = 'big_data',
mobile = 'mobile',
engagement = 'engagement',
monitoring = 'monitoring',
crm = 'crm',
cdp = 'cdp',
cookieMatch = 'cookiematch',
misc = 'misc',
}
export interface TealiumConfig {
account: string;
profile: string;
environment: TealiumEnvironment;
dataSource?: string;
collectors: Collectors[];
dispatchers: Dispatchers[];
customVisitorId?: string;
memoryReportingEnabled?: boolean;
overrideCollectURL?: string;
overrideCollectBatchURL?: string;
overrideCollectDomain?: string;
overrideLibrarySettingsURL?: string;
overrideTagManagementURL?: string;
deepLinkTrackingEnabled?: boolean;
qrTraceEnabled?: boolean;
loglevel?: LogLevel;
consentLoggingEnabled?: boolean;
consentPolicy?: ConsentPolicy;
consentExpiry?: ConsentExpiry;
lifecycleAutotrackingEnabled?: boolean;
useRemoteLibrarySettings?: boolean;
visitorServiceEnabled?: boolean;
visitorServiceRefreshInterval?: string;
} }
/** /**
* @paid
* @name Tealium * @name Tealium
* @description * @description
* This plugin provides a TypeScript wrapper around the [Tealium](https://www.tealium.com) Cordova plugin for Ionic Native. * This plugin does provides a wrapper around the Tealium Cordova Plugin for Ionic Native.
*
* For full documentation, see [https://docs.tealium.com/platforms/cordova/](https://docs.tealium.com/platforms/cordova/)
* *
* For full documentation, see [https://community.tealiumiq.com/t5/Mobile-Libraries/Tealium-for-Cordova/ta-p/17618](https://community.tealiumiq.com/t5/Mobile-Libraries/Tealium-for-Cordova/ta-p/17618)
* @usage * @usage
* ``` * ```typescript
* import { Tealium, TealConfig } from '@awesome-cordova-plugins/tealium/ngx'; * import { Tealium } from '@awesome-cordova-plugins/tealium/ngx';
* *
* *
* constructor(private tealium: Tealium) { } * constructor(private tealium: Tealium) { }
* *
* ... * ...
* *
* let tealConfig: TealConfig = { * let config: TealiumConfig = {
* account: "<your-account>", * account: <your_tealium_account>,
* profile: "<your-profile>", * profile: <your_tealium_profile>,
* environment: "<your-environment>", // usually "dev", "qa" or "prod" * environment: TealiumEnvironment.dev,
* isLifecycleEnabled: "true", // pass "false" to disable lifecycle tracking * dispatchers: [Dispatchers.Collect, Dispatchers.RemoteCommands, Dispatchers.TagManagement],
* isCrashReporterEnabled: "false", // pass "true" to enable crash reporter (Android only) * collectors: [Collectors.AppData, Collectors.DeviceData, Collectors.Lifecycle, Collectors.Connectivity],
* instance: "<your-instance-name" // an arbitrary instance name. use the same instance name for all subsequent API calls * consentLoggingEnabled: true,
* } * consentPolicy: ConsentPolicy.gdpr,
* * visitorServiceEnabled: true,
* this.tealium.init(tealConfig).then(()=>{ * // visitorServiceRefreshInterval: '1',
* this.tealium.trackView({"screen_name": "homescreen"}); * consentExpiry: new ConsentExpiry(3, TimeUnit.minutes),
* }); * };
*
* Tealium.initialize(config);
* *
* ``` * ```
* @interfaces
* TealConfig
*/ */
@Plugin({ @Plugin({
pluginName: 'Tealium', pluginName: 'Tealium',
plugin: 'tealium-cordova-plugin', // npm package name, example: cordova-plugin-camera plugin: 'tealium-cordova-plugin', // npm package name
pluginRef: 'window.tealium', // the variable reference to call the plugin, example: navigator.geolocation pluginRef: 'tealium', // the variable reference to call the plugin
repo: 'https://github.com/Tealium/cordova-plugin', // the github repository URL for the plugin repo: 'https://github.com/Tealium/cordova-plugin', // the github repository URL for the plugin
platforms: ['Android', 'iOS'], // Array of platforms supported, example: ['Android', 'iOS']
install: '', // OPTIONAL install command, in case the plugin requires variables install: '', // OPTIONAL install command, in case the plugin requires variables
installVariables: [], // OPTIONAL the plugin requires variables
platforms: ['Android', 'iOS'] // Array of platforms supported
}) })
@Injectable() @Injectable()
export class Tealium extends AwesomeCordovaNativePlugin { export class Tealium extends AwesomeCordovaNativePlugin {
/** /**
* This function initializes the Tealium Cordova plugin. * This function initializes the Tealium Cordova Plugin
* This should usually be done inside the "deviceReady" handler. * @param config {TealiumConfig}
* * @param callback
* @param config {TealConfig} * @return {Promise<any>} Returns a promise that resolves when something happens
* @returns {Promise<any>} Returns a promise that resolves when something happens
*/ */
@Cordova() @Cordova()
init(config: TealConfig): Promise<any> { initialize(config: TealiumConfig, callback?: Function): Promise<any> {
return; // We add return; here to avoid any IDE / Compiler errors return; // We add return; here to avoid any IDE / Compiler errors
} }
/** /**
* This function tracks a view event in the Tealium Cordova plugin * This function tracks an event
* * @param dispatch {TealiumDispatch} Dispatch containing event data
* @param dataObject {any} The JSON data object containing your key-value pairs * @return {Promise<any>} Returns a promise that resolves when something happens
* @param instanceName {string} Your arbitrary Tealium instance name provided at init time
* @returns {Promise<any>} Returns a promise that resolves when something happens
*/ */
@Cordova() @Cordova()
trackView(dataObject: any, instanceName: string): Promise<any> { track(dispatch: TealiumDispatch): Promise<any> {
return; return;
} }
/** /**
* This function tracks a link event in the Tealium Cordova plugin * This function terminatest the Tealium instance
* * @return {Promise<any>} Returns a promise that resolves when something happens
* @param dataObject {any} The JSON data object containing your key-value pairs
* @param instanceName {string} Your arbitrary Tealium instance name provided at init time
* @returns {Promise<any>} Returns a promise that resolves when something happens
*/ */
@Cordova() @Cordova()
trackEvent(dataObject: any, instanceName: string): Promise<any> { terminateInstance(): Promise<any> {
return; return;
} }
/** /**
* This function tracks a custom event in the Tealium Cordova plugin * Adds data to data layer
* * @param data A map containing the key-value pairs to be added to data layer
* @param eventType {string} The event type, link or view * @param expiry When the data should expire. Choose `Expiry.session` if unsure.
* @param dataObject {any} The JSON data object containing your key-value pairs * @return {Promise<any>} Returns a promise that resolves when something happens
* @param instanceName {string} Your arbitrary Tealium instance name provided at init time
* @returns {Promise<any>} Returns a promise that resolves when something happens
*/ */
@Cordova() @Cordova()
track(eventType: string, dataObject: any, instanceName: string): Promise<any> { addData(data: Map<string, any>, expiry: string): Promise<any> {
return; return;
} }
/** /**
* This function adds data to the Tealium persistent data store *
* * @param key The key of the data to retrieve from the data layer
* @param keyName {string} The key name that this data will be stored under for later retrieval * @param callback
* @param value {any} The value to be stored as persistent data * @return {Promise<any>} Returns a promise that resolves when something happens
* @param instanceName {string} Your arbitrary Tealium instance name provided at init time
* @returns {Promise<any>} Returns a promise that resolves when something happens
*/ */
@Cordova() @Cordova()
addPersistent(keyName: string, value: string | string[] | any, instanceName: string): Promise<any> { getData(key: string, callback?: Function): Promise<any> {
return; return;
} }
/** /**
* This function adds data to the Tealium volatile data store * Removes data from the data layer
* * @param keys The keys of the data to be removed
* @param keyName {string} The key name that this data will be stored under for later retrieval * @return {Promise<any>} Returns a promise that resolves when something happens
* @param value {any} The value to be stored as volatile data
* @param instanceName {string} Your arbitrary Tealium instance name provided at init time
* @returns {Promise<any>} Returns a promise that resolves when something happens
*/ */
@Cordova() @Cordova()
addVolatile(keyName: string, value: string | string[], instanceName: string): Promise<any> { removeData(keys: string[]): Promise<any> {
return; return;
} }
/** /**
* This function removes data from the Tealium volatile data store * Retrieves the user's consent status
* * @param callback
* @param keyName {string} The key name that this data will removed from the Tealium data store * @return {Promise<any>} Returns a promise that resolves when something happens
* @param instanceName {string} Your arbitrary Tealium instance name provided at init time
* @returns {Promise<any>} Returns a promise that resolves when something happens
*/ */
@Cordova() @Cordova()
removeVolatile(keyName: string, instanceName: string): Promise<any> { getConsentStatus(callback?: Function): Promise<any> {
return; return;
} }
/** /**
* This function removes data from the Tealium persistent data store * Sets the user's consent status
* * @param consentStatus
* @param keyName {string} The key name that this data will removed from the Tealium data store * @return {Promise<any>} Returns a promise that resolves when something happens
* @param instanceName {string} Your arbitrary Tealium instance name provided at init time
* @returns {Promise<any>} Returns a promise that resolves when something happens
*/ */
@Cordova() @Cordova()
removePersistent(keyName: string, instanceName: string): Promise<any> { setConsentStatus(consentStatus: ConsentStatus): Promise<any> {
return; return;
} }
/** /**
* This function retrieves a value from the Tealium Persistent data store * Retrieves the user's consent categories
* * @param callback
* @param keyName {string} The key name that this data will retrieved from the Tealium data store * @return {Promise<any>} Returns a promise that resolves when something happens
* @param instanceName {string} Your arbitrary Tealium instance name provided at init time
* @param callback {any} A callback function that will be called when the data has been retrieved
* @returns {Promise<any>} Returns a promise that resolves when something happens
*/ */
@Cordova() @Cordova()
getPersistent(keyName: string, instanceName: string, callback: any): Promise<any> { getConsentCategories(callback?: Function): Promise<any> {
return;
}
/**
* This function retrieves a value from the Tealium Volatile data store
*
* @param keyName {string} The key name that this data will retrieved from the Tealium data store
* @param instanceName {string} Your arbitrary Tealium instance name provided at init time
* @param callback {any} A callback function that will be called when the data has been retrieved
* @returns {Promise<any>} Returns a promise that resolves when something happens
*/
@Cordova()
getVolatile(keyName: string, instanceName: string, callback: any): Promise<any> {
return; return;
} }
/** /**
* This function adds a remote command for later execution * Sets the user's consent categories
* * @param categories
* @param commandName {string} The command name for this Remote Command * @return {Promise<any>} Returns a promise that resolves when something happens
* @param instanceName {string} Your arbitrary Tealium instance name provided at init time
* @param callback {any} A callback function that will be called when the data has been retrieved
* @returns {Promise<any>} Returns a promise that resolves when something happens
*/ */
@Cordova() @Cordova()
addRemoteCommand(commandName: string, instanceName: string, callback: any): Promise<any> { setConsentCategories(categories: ConsentCategories[]): Promise<any> {
return; return;
} }
/** /**
* This function retrieves the Tealium Visitor ID * Joins a trace session weith the specified Trace ID
* * @param id Trace ID
* @returns {Promise<any>} Returns a promise that resolves when something happens * @return {Promise<any>} Returns a promise that resolves when something happens
*/ */
@Cordova() @Cordova()
getVisitorId(): Promise<any> { joinTrace(id: string): Promise<any> {
return;
}
/**
* Leaves a trace session
* @return {Promise<any>} Returns a promise that resolves when something happens
*/
@Cordova()
leaveTrace(): Promise<any> {
return;
}
/**
* Retrieves the Tealium Visitor ID
* @param callback
* @return {Promise<any>} Returns a promise that resolves when something happens
*/
@Cordova()
getVisitorId(callback?: Function): Promise<any> {
return;
}
/**
* Sets a listener to be called when the AudienceStream visitor profile is updated
* @param callback
* @return {Promise<any>} Returns a promise that resolves when something happens
*/
@Cordova()
setVisitorServiceListener(callback?: Function): Promise<any> {
return;
}
/**
* Sets a listener to be called when the consent has expired
* @param callback
* @return {Promise<any>} Returns a promise that resolves when something happens
*/
@Cordova()
setConsentExpiryListener(callback?: Function): Promise<any> {
return;
}
/**
* Adds a remote command for later execution
* @param id The ID used to invoke the remote command
* @param callback
* @return {Promise<any>} Returns a promise that resolves when something happens
*/
@Cordova()
addRemoteCommand(id: string, callback?: Function): Promise<any> {
return;
}
/**
* Removes a previously-added remote command
* @param id The ID of remote command to be removed
* @return {Promise<any>} Returns a promise that resolves when something happens
*/
@Cordova()
removeRemoteCommand(id: string): Promise<any> {
return;
}
/**
* Removes all listeners
* @return {Promise<any>} Returns a promise that resolves when something happens
*/
@Cordova()
removeListeners(): Promise<any> {
return; return;
} }
} }