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.