Solved

Cross domain tracking with GTM and React

  • 31 May 2023
  • 6 replies
  • 314 views

Badge +2

I am using GTM to instrument Amplitude and have an issue I think many of you have bumped into. I am trying to track a user across different domains by passing the deviceid in the url.

 

However, I can't access the deviceid in the right amplitude instance from code in order to pass it in the url. Here's a reference to a description of the problem in an Amplitude Community forum: https://community.amplitude.com/data-instrumentation-57/cross-domain-tracking-typescript-1461?postid=8608#post8608

 

I'd be grateful for any help as this is going to be crucial for our implementation to work. Thanks! (ping @Esther Trapadoux)

icon

Best answer by Linus Lennstrand 1 June 2023, 15:54

View original

6 replies

Userlevel 5
Badge +8

@Linus Lennstrand thanks for this! Have you tried this option yet? Let me know if this works for you (or not), and we’ll keep digging into it.

Badge +2

@Linus Lennstrand thanks for this! Have you tried this option yet? Let me know if this works for you (or not), and we’ll keep digging into it.

Yes, we have absolutely tried that. The problem is exactly that we haven’t been able access the device id from the amplitude instance that has been initialised from GTM when trying to get it from code on the page.

 

When running amplitude.getDeviceId() (amplitude.options.deviceId is not available in Analytics Browser SDK) it returns undefined.

Badge +2

I have also tried the solution provided by @Alyssa Yu in 

however, it’s not working either. 

Badge +10

I’m sure there must be a way using the SDK, but if not you could perhaps read it directly from the amplitude browser cookie?

Badge +10

the name of the amplitude cookie is found in the instance using amplitude.getInstance()._cookieName 

Badge +2

Problem solved (solution described here)!

Reply