Skip to main content

Hi,
I have 15 different content websites on different domains. If I visit first domain example abc.com, I get A123 as anonymous_id but when I visit 2nd domain def.com, I get D987 as anonymous_id. What I want to achieve is for Segment to know, it was me on both domains.
I can use query string for 2 domains but for 15, it gets complicated. Is there a better solution?

 

Thanks,

Hi @Khalid Mahmood - Unfortunately there’s not a better way for segment to know that these domains are interconnected together.  Also for security purposes we don’t necessarily want to pass ids from one website to another. Alternatively, using a subdomain could work for tracking across different sites for example: gap.com is connected to oldnavy.gap.com, bananarepublic.gap.com etc… as long as the domain remains the same, you should be able to use one javascript code that carries throughout. Here’s some helpful documentation around this: https://segment.com/docs/connections/sources/catalog/libraries/website/javascript/#cross-subdomain-analytics 


Hi @Chauntel Greaves 
Thanks for coming back. Yeah, I know the subdomain solution but was more interested in cross domain. I can use a solution that creates first party user id in browser of a user but that will be lots of development work. Thought to check if someone from community has faced a similar issue.

 

Thanks


@Khalid Mahmood I haven’t tested this, but theoretically you could add a function similar to this on your site and it would automatically add the visitors Segment anonymous_id to all the links to your other domains.

 

jQuery.fn.same_user = function(domain, ajsId) {
$(this).find("adhref*='/" + domain + "']").each(function() {
// var url = $(this).attr('href');
const url = new URL($(this).attr('href'));
url.searchParams.set("ajs_aid", ajsId);
$(this).attr( 'href', url.toString() );
});
}

// Example Call
analytics.ready( function() {
const anId = analytics.user().anonymousId();
jQuery('body').same_user('www.example.com', anId);
jQuery('body').same_user('www.mydomain.com', anId);
});

 


@Khalid Mahmood I haven’t tested this, but theoretically you could add a function similar to this on your site and it would automatically add the visitors Segment anonymous_id to all the links to your other domains.

 

jQuery.fn.same_user = function(domain, ajsId) {
$(this).find("adhref*='/" + domain + "']").each(function() {
// var url = $(this).attr('href');
const url = new URL($(this).attr('href'));
url.searchParams.set("ajs_aid", ajsId);
$(this).attr( 'href', url.toString() );
});
}

// Example Call
analytics.ready( function() {
const anId = analytics.user().anonymousId();
jQuery('body').same_user('www.example.com', anId);
jQuery('body').same_user('www.mydomain.com', anId);
});

 

@Chris Carrel Thanks for sharing an idea. I will try this out and see if it works. Apologies for the late reply as I was away.


Reply