Skip to main content

Multiple Domains

  • September 5, 2024
  • 4 replies
  • 302 views

Forum|alt.badge.img+2

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,

Was this topic helpful?

4 replies

Chauntel Greaves
Segmenter
Forum|alt.badge.img+3

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 


Forum|alt.badge.img+2

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


Chris Carrel
Forum|alt.badge.img+4

@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("a[href*='/" + 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);
});

 


Forum|alt.badge.img+2
Chris Carrel wrote:

@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("a[href*='/" + 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