Duplicate value is passing when thank you page get reload

Jayakrishnaa
New Member
Jayakrishnaa

Team,

We have a registration page and tracking all those fields as expected. Also, we are tracking the registration successfull at the end of the submit button clicked. so that we can count the no of people who get registered successfully. We are passing events and evars accordingly. But, when we reload the thank you page from the successfull submission then again same events and evars are tracking. However, this wasn't the expected behaviour for the data. Is there any other way that we can stop this duplicate data passing in to our report. We just want to stop the events and evars when user reload the page. Please find my code below.

------------------------------

$(window).load(function() {
setTimeout(function(){
if(window.location.pathname=="request-a-rep-confirm.html" || window.location.pathname=="/hcp/request-a-rep-confirm.html"){

var s = window.s;
s = s_gi(s_account);
var tempPlugins = s.doPlugins;
s.doPlugins = function() {};
s.linkTrackVars = 'events,eVar71';
s.linkTrackEvents = 'event11,event29';
s.eVar71 = 'REQUEST A REP|Form|Successful Submission';
s.events='event11,event29';
s.tl(this, 'o', 'REQUEST A REP|Form|Successful Submission');
s.doPlugins = tempPlugins;
s.linkTrackVars = 'None';
s.linkTrackEvents = 'None';
}
},500);
});

---------------------------------------

2 REPLIES 2
Highlighted

Duplicate value is passing when thank you page get reload

mvenkatesan
Occasional Contributor
mvenkatesan Occasional Contributor

Hello @Jayakrishnaa

Its a javascript code and every time when you refresh the page it will run by default and I believe thats its nature.

In order to make the snippet run only once what you need to do is put a flag and check for the flag each time when the code starts to run it.

You can do this with 2 type of approaches

  1. cookie method: classic way
  2. session storage which all the modern browsers support


I tried updating your code witht the session storage method, but dint get a chance to test it. 

Hope this helps!

$(window).load(function () {
    setTimeout(function () {
        if (window.location.pathname == "request-a-rep-confirm.html" || window.location.pathname == "/hcp/request-a-rep-confirm.html") {
            if (sessionStorage.getItem("regstatus") === null) { //check for the sessionStorage flag
                var s = window.s;
                s = s_gi(s_account);
                var tempPlugins = s.doPlugins;
                s.doPlugins = function () { };
                s.linkTrackVars = 'events,eVar71';
                s.linkTrackEvents = 'event11,event29';
                s.eVar71 = 'REQUEST A REP|Form|Successful Submission';
                s.events = 'event11,event29';
                s.tl(this, 'o', 'REQUEST A REP|Form|Successful Submission');
                s.doPlugins = tempPlugins;
                s.linkTrackVars = 'None';
                s.linkTrackEvents = 'None';
                sessionStorage.setItem("regstatus", "success"); // setting the sessionstorage flag
            }
        }
    }, 500);
});


Thanks!

Duplicate value is passing when thank you page get reload

VIP
VIP VIP

@Jayakrishnaa great question and @mvenkatesan - great answer, love the usage of local storage!

 

Since we're specifically using Adobe Analytics in this scenario, another approach is also possible, Event Serialization. Read about it here: https://community.tealiumiq.com/t5/Tags/SiteCatalyst-Firing-multiple-events-and-Event-Serialization/... (there's more links to read on that page).  Also see the Adobe docs about this technique.