Jump to content

how to set custom attribute in "ins" tag, and then have Revive notice, respect it


Recommended Posts

I am trying to coordinate between a GDPR cookie-setting script and Revive.

The cookie-setting script starts out as "false" (so no cookies are supposed to be set) and asks the user to pick the user's "level" of cookies ("necessary", "preferences", "statistics", and "marketing"). The script then sets a cookie as either a "0" (meaning "opts out of everything non-necessary") or else as a more standard type cookie (containing something along the lines of "necessary:true,preferences:[value],statistics:[value],marketing:[value]", where [value] is "true" or "false"). For the purposes of discussion, let's call the cookie "CB".

I have figured out how to have a Javascript check CB, and return either "true" for marketing, or else "false", writing this value (as a string) into a global variable "cb2ox" (for "converting CB's "marketing" value to an OpenX tag value"). I have figured out how to have another Javascript add "data-revive-cb2ox=[value of cb2ox]" to the "ins" tag in the HTML of a given webpage. (That is, if you view the DOM for the page, the new name-value pair is displayed within the "ins" tag.)

I've done this scripting set-up on a page that I'm using for testing.

I have set a Delivery Rule (that is, "Only display this banner when:") as:

"(Site-PageURL DoesNotContain [testing page's URL]) OR (Site-Variable cb2ox Contains true)"

If I'm understanding the Rule correctly, this means that ads will be displayed in the customary way on all pages other than [testing page's URL]. However, when the URL is [testing page's URL], the other rule should be checked; that is, the value of "data-revive-cb2ox" should be checked and, if NOT "true", then no ads should display.

However, ads are still displaying. So clearly I'm doing something wrong. There is no documentation for "Site - Variable", so the error may lie there. Or maybe I've got the Delivery Rule set up wrong. Either way, I'd appreciate advice, instruction, links,... commiseration, sympathy,... whatever....

Thank you!

Eliz.

Link to comment
Share on other sites

I may have found a fix, and it involves editing the "async.js" file. I am NOT a coder, so USE AT YOUR OWN RISK!

In the "development" folder at the github page for Revive, the "www/delivery_dev/async.js" file contains the following:

74                /**
75                 * The start event handler. Delivery can be prevented by setting e.detail.start = false.
76                 *
77                 * @param {CustomEvent} e
78                 */
79                start: function (e)
80                {
81                    if (e.detail && e.detail.hasOwnProperty('start') && !e.detail.start) {
82                        return;
83                    }
84
85                rv.removeEventListener('start', rv.start);
86
87                rv.dispatchEvent('refresh');
88                },

I took the comment to heart, and decided to copy my Javascript (which was functioning correctly in reading the GDPR cookie value) into the "async.js" file.

Note: In the actual "async.js" file, everything is in one line, rather than nicely broken up so as to be easily read. For testing, I first inserted my coding without stripping all of the empty spaces, line returns, etc.

So my new "start: function (e)" looks like this:

                    start:function(g){
                    // Begin my custom coding for reading the cookie value
                    var CB_value, CB_consent, cb2ox;
                    if (document.cookie.split(';').filter(function(item){return item.indexOf('CookieConsent=') >= 0}).length){
                        function getCBval(cname) {
                            var name = cname + "=";
                            var decodedCookie = decodeURIComponent(document.cookie);
                            var ca = decodedCookie.split(';');
                            for(var i = 0; i <ca.length; i++) {
                                var c = ca;
                                while (c.charAt(0) == ' ') {
                                    c = c.substring(1);
                                }
                                if (c.indexOf(name) == 0) {
                                return c.substring(name.length, c.length);
                                }
                            }
                        }
                        var CBval = getCBval("CookieConsent");
                        if (CBval == '0'){
                            CB_value = 0;
                            CB_consent = false;
                        }
                        else{
                            CB_split = CBval.split(",");
                            CB_array = new Array();
                            for(i=0;i<=5;i++){
                                CB_array = CB_split;
                            }
                            CB_value = CB_array[4];
                            if (CB_value == "marketing:true"){
                                CB_consent = true;
                            }
                            else{     
                                CB_consent = false;
                            }
                        }
                    }
                    else{
                    CB_consent = false;
                    }
                    cb2ox = CB_consent.toString();
                    // End of my custom coding for reading the cookie value
                    
                    // Added "or cb2ox = 'false'" to "if" statement
                    // "if" was "(g.detail&&g.detail.hasOwnProperty("start")&&!g.detail.start)"
                    // I added an extra set of parentheses around the "if" condition
                    // Then I added "||(cb2ox=="false")" inside the "if" condition, after the original condition

                    if((g.detail&&g.detail.hasOwnProperty("start")&&!g.detail.start)||(cb2ox=="false")){
                        return
                    }
                    f.removeEventListener("start",f.start);
                    f.dispatchEvent("refresh")
                },

In the above, I've included comments delineating my cookie coding, and also the addition in the "if" statement.

I have tested the above script in each of Firefox and Internet Explorer, and it appears to work. My cookie script determines if the current website visitor has selected "true" or "false" for accepting "marketing" cookies (this information being available in the "CookieConsent" cookie). If the user has elected NOT to accept marketing cookies (so ads should not display, and the "cb2ox" variable reads "false") or if the user is seeing the GDPR screen for the first time (so GDPR regs require that no cookies be set - yet), then nothing is displayed for any of my Revive "zones".

Phew!

Eliz.

Edited by stapel_eliz
Fixing link; removing unintended italicisation of text.
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...