adobe / reactor-extension-core

This is the Core extension for Adobe Experience Platform Tags. It provides default event, condition, action, and data element types to all Tags properties.
https://experienceleague.adobe.com/docs/experience-platform/tags/extensions/adobe/core/overview.html
Apache License 2.0
21 stars 13 forks source link

Update Core Data Elements to support event #71

Closed alcazes closed 2 years ago

alcazes commented 2 years ago

At the moment it is possible to call a data element using

_satellite.getVar('dataElementId', event);

This is particularly useful with DCR as you can pass metadata and they are passed down to data element where data element support event.

For example custom code support this:

"test": {
    "modulePath": "core/src/lib/dataElements/customCode.js",
    "settings": {
        "source": function(event) {
            console.log(event)
        }
    }
},

So when called directly like _satellite.getVar('test', 'xyz'), xyz will be passed to the custom script and output in console xyz.

For some data element no event is passed so it is impossible to pass %event% as value in data element configuration

"testquery": {
    "modulePath": "core/src/lib/dataElements/queryStringParameter.js",
    "settings": {
        "name": "test",
        "caseInsensitive": true
    }
},

I believe this is due to the fact event is not passed in queryStringParameter:

"extensions": {
    "core": {
        "displayName": "Core",
        "hostedLibFilesBaseUrl": "https://assets.adobedtm.com/extensions/EPd22815afd48447aa955be6a3a012e3b5/",
        "modules": {
            "core/src/lib/dataElements/queryStringParameter.js": {
                "name": "query-string-parameter",
                "displayName": "Query String Parameter",
                "script": function(module, exports, require, turbine) {
                    /***************************************************************************************
                     * Copyright 2019 Adobe. All rights reserved.
                     * This file is licensed to you under the Apache License, Version 2.0 (the "License");
                     * you may not use this file except in compliance with the License. You may obtain a copy
                     * of the License at http://www.apache.org/licenses/LICENSE-2.0
                     *
                     * Unless required by applicable law or agreed to in writing, software distributed under
                     * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
                     * OF ANY KIND, either express or implied. See the License for the specific language
                     * governing permissions and limitations under the License.
                     ****************************************************************************************/

                    'use strict';

                    var window = require('@adobe/reactor-window');
                    var queryString = require('@adobe/reactor-query-string');

                    /**
                     * The query string parameter data element.
                     * @param {Object} settings The data element settings object.
                     * @param {string} settings.name The query string parameter name.
                     * @param {string} [settings.caseInsensitive] Whether casing should be ignored.
                     * @returns {string}
                     */
                    module.exports = function(settings) {
                        var queryParams = queryString.parse(window.location.search);

                        if (settings.caseInsensitive) {
                            var lowerCaseName = settings.name.toLowerCase();
                            var keys = Object.keys(queryParams);
                            for (var i = 0; i < keys.length; i++) {
                                var key = keys[i];
                                if (key.toLowerCase() === lowerCaseName) {
                                    return queryParams[key];
                                }
                            }
                        } else {
                            return queryParams[settings.name];
                        }
                    };

                }

            },

I think if the following module.exports = function(settings) { is updated to module.exports = function(settings, event) { it would work.

This would mean that I could create a queryParam data element and call it as follow:

_satellite.getVar('queryParam', 'param1');
_satellite.getVar('queryParam', 'param2');

no need to create multiple data elements for query params, once can be used to retrieve param value as needed.

jeffreywalter commented 2 years ago

So, it sounds like you want a dynamic custom query parameter data element that would only be functional in custom code, as you would need to pass the parameter key in the function. Correct? We haven't heard this before, as it would be a fairly niche use case that would only be usable in custom code and not via settings.

jhicken commented 2 years ago

@alcazes Do you have any extra thoughts from @jeffreywalter 's comment?

jeffreywalter commented 2 years ago

@alcazes Hey, we are going to close this issue, please re-open with comments if you would like to discuss this use case.

alcazes commented 2 years ago

@jhicken @jeffreywalter

Sorry been busy lately.

Basically I do not need any additional condition, data element or actions to be developed as per say. I just need that existing actions, data element and conditions pass the event object as part of the module.exports = function(settings, event) {

So instead of using module.exports = function(settings) { you would add the event argument to the function like so module.exports = function(settings, event) {

Use case would be when rule is called using DCR with specific payload.

All my private extension pass the event argument which means that if my DCR is called with a payload, I can then configure my data elements to leverage the event details.

This is specifically used on my side as part of the auto-tagging framework that I designed which pass a queued snapshot of the data layer when queued hit is processed. By doing so every condition, data elements and actions that pass the event argument, allows my data elements to return correct data from data layer snapshot.

Also it is used as part of the private extension that I developed to handle ePrivacy and cookie scenarios. If page is loaded without cookie group preference opted in, the rule is queued with a payload that takes a snapshot of the current data element values. When cookie selection is changed and group is opted in then the rule is triggered using a DCR with payload queued at the time. When rule is executed using DCR, all data elements check if event.detail exist and is specific dataElement name exist in payload, if it does it returns it value, if not it continues with normal logic.

So in interface I able to leverage %event.detail.property% and in custom code I am able to leverage event.detail.property