Skip to main content
Contributor I
May 18, 2023
Solved

How to track same user on subdomain?

  • May 18, 2023
  • 6 replies
  • 569 views

Hi,

I have two domains for example:  abc.com and abc.shop.com.
I want to track same user for both domains. I mean if user A push event on domain abc.com and same user push event from other domain abc.shop.com, then how klaviyo cookie automatically track the same user for second domain? It will not create other profile for other domain only one profile can track both domain.

I read below link but new klaviyo object is not giving the exchange_id. 


 

    This topic has been closed for replies.
    Best answer by Brian Turcotte

    Hi @web!

    I see that you also asked this question in another Community thread in the Developer Group, so for the sake of organization and visibility, I’m going to link to that here:

     

    Best,

    Brian

    6 replies

    Taylor Tarpley
    Community Manager
    Community Manager
    May 18, 2023

    Hi @web

     

    Welcome to the Community, happy to help! 

     

    Great work so far! While it was previously allowed to track users across different domains by using _ke parameter , this was changed last year to increase security protection. Now we have switched to using an exchange id, or _kx  parameter. So you will need to go about tracking the user in a different way, which is append the exchange id value to each link on one subdomain that then directs to the other, instead of the previous used code below. But Dov shared two great ways to still find the user to have seamless tracking across both domains!

    _learnq.identify().$email

     

    Do you mean that you tried both methods, mentioned in the post you linked above, to find the exchange ID and weren’t successful?

    • Decoding the klaviyo cookie and retrieving it
    • Expose in our frontend library called _learnq.push(["_getIdentifiers"])  which should return a key value pair in an object with $exchange_id so long as the user is cookied.

     

    If you followed the second option, did you ensure to the script ends in the _kx parameter instead of the _ke parameter? If should look like the code below:

    + '_kx=' + exchange_id)
    }
    });
    }
    }
    }, 1200);
    </script>

     

    Thanks for participating in the Community!

    -Taylor 

    webAuthor
    Contributor I
    May 19, 2023

    Hi @Taylor Tarpley

    I am using new object klaviyo instead of legacy _learnq object. 

    I used new object “klaviyo.push(["_getIdentifiers"])” for getting $exchange_id , but it is giving the error i.e. “Unable to process event: _getIdentifiers”.

    How we get $exchange_id  with new object klaviyo?
    Is there any other way to track the same user for subdomain?

    David To
    Klaviyo Employee
    Klaviyo Employee
    May 19, 2023

    Hey @web,

    Can you confirm if the user was identified/cookied on the first domain before attempting to retrieve the $exchange_id?

    I’m not a developer, but that error you’re getting of “Unable to process event: _getIdentifiers” seems to indicate that it was unable to process/retrieve the identifier originally. 

    David

    webAuthor
    Contributor I
    May 22, 2023

    Hi @David To,

    yes, I am identified/cookied the user on the first domain before attempting to retrieve the  $exchange_id.


    Also i have one more question, If we cookied the user on one system, then how we get that user on the other system for second domain?
     

    webAuthor
    Contributor I
    May 22, 2023

    Hi @David To,

    Below code is not working in react. What is the ‘a’ element? 
      $(document).find('a').each(function(){
     

    if setting the exchange_id overwrites the values from a _kx parameter? 
     

     

    Brian Turcotte
    Klaviyo Alum
    May 31, 2023

    Hi @web!

    I see that you also asked this question in another Community thread in the Developer Group, so for the sake of organization and visibility, I’m going to link to that here:

     

    Best,

    Brian