My company uses a tag management platform that attempts to perform user stitching in its click tracking tables. I've found that it's not even close to being watertight, and I'm exploring ways to perform that stitching on my own. What I have to work with is a series of IDs (why so many? Beats me) that pair to each other somewhat haphazardly. For one user, the data would look something like this:
| ID_1 | ID_2 | ID_3 |
|---|---|---|
| A | C | |
| A | D | |
| A | E | |
| A | F | |
| B | C | |
| B | D | |
| B | E | |
| B | F |
My goal is to create a new column that has stores one constant ID. I don't care which one, A/B/C/D/E/F, as long as it's constant and exhaustive across all records for a given user. Something like:
| ID_1 | ID_2 | ID_3 | ID_final |
|---|---|---|---|
| A | C | A | |
| A | D | A | |
| A | E | A | |
| A | F | A | |
| B | C | A | |
| B | D | A | |
| B | E | A | |
| B | F | A |
I would love a SQL-based way of doing this, but I'd be open to an R- or Python-based solution as well. For R/Python, we'd probably spin up a dockerized job that performs the stitching and writes a lookup table to our warehouse. Thank you!!
A few edits based on initial feedback:
- Added second table with visualization of the end result I'm trying to achieve.
- FYI, Google Tag Manager is not the actual tag management platform. It doesn't actually matter what the actual tag manager is, this is more of a data wrangling task than a tag management task. I only mentioned tag management to provide context for where this question came up.