Skip to content

Commit

Permalink
[MT-1224] - Map handling (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
jameskeith authored Apr 4, 2023
1 parent 5f390c1 commit aeb352a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Tealium/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tealium-cordova-plugin",
"version": "2.3.0",
"version": "2.3.1",
"description": "Tealium Customer Data Hub",
"cordova": {
"id": "tealium-cordova-plugin",
Expand Down
2 changes: 1 addition & 1 deletion Tealium/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="tealium-cordova-plugin" version="2.3.0"
id="tealium-cordova-plugin" version="2.3.1"
name="tealium-cordova-plugin">

<name>TealiumCordova</name>
Expand Down
26 changes: 25 additions & 1 deletion Tealium/www/tealium.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,22 @@ const Dispatch = {
}
};

const mapToObject = function (entries){
if (!entries || !entries[Symbol.iterator]) {
return {};
}

let obj = {};
for (let [key, value] of entries) {
if (value && value instanceof Map) {
obj[key] = mapToObject(value);
} else {
obj[key] = value;
}
}
return obj;
};

const Commands = {
INITIALIZE: "initialize",
TRACK: "track",
Expand Down Expand Up @@ -142,7 +158,7 @@ let TealiumPlugin = {
initialize(config, callback) {
let self = this;
cordova.exec(function(e) {
self.addData({'plugin_name': 'Tealium-Cordova', 'plugin_version': '2.3.0'}, Expiry.forever);
self.addData({'plugin_name': 'Tealium-Cordova', 'plugin_version': '2.3.1'}, Expiry.forever);
if (config.remoteCommands) {
config.remoteCommands.forEach((remoteCommand) => {
self.addRemoteCommand(remoteCommand.id, remoteCommand.callback, remoteCommand.path, remoteCommand.url)
Expand All @@ -156,6 +172,10 @@ let TealiumPlugin = {
},

track(dispatch) {
if (dispatch.dataLayer && dispatch.dataLayer instanceof Map) {
// Ionic supports sending `Map<String, Any>`
dispatch.dataLayer = mapToObject(dispatch.dataLayer)
}
cordova.exec(null, null, PLUGIN_NAME, Commands.TRACK, [dispatch])
},

Expand All @@ -164,6 +184,10 @@ let TealiumPlugin = {
},

addData(data, expiry) {
if (data && data instanceof Map) {
// Ionic supports sending `Map<String, Any>`
data = mapToObject(data)
}
cordova.exec(null, null, PLUGIN_NAME, Commands.ADD_DATA, [data, expiry])
},

Expand Down

0 comments on commit aeb352a

Please sign in to comment.