Michael Johns
Michael Johns

Reputation: 441

Obtain Adobe Marketing Cloud ID when Cookies not set previously using DTM?

I'm trying to figure out how to capture the Adobe Marketing Cloud ID (MID) when a page first loads using a Data Element (or by whatever alternative method will work). My Data Element logic works fine, if the Marketing Cloud cookie already exists. If there is no Marketing Cloud Cookie already existing, my data element reads the Marketing Cloud ID cookie as it is being written but the MID is not populated in the cookie at the time the Data Element reads it.

Is there any way I can access the value and report it in an eVar on the initial page load? I actually take the MID and combine it with an additional value to create the eVar value. As stated my code works unless the Marketing Cloud ID doesn't exist and has to be created during the page load.

Upvotes: 0

Views: 1408

Answers (1)

CrayonViolent
CrayonViolent

Reputation: 32517

You can use Visitor.getInstance() to get the Visitor instance, and then and then Visitor.getMarketingCloudVisitorID() to get the MC ID (what you see in the mid= param)

example:

var visitor = Visitor.getInstance("[mcorgid]@AdobeOrg")
s.eVar1 = visitor.getMarketingCloudVisitorID(); // set v2 with mid= value

If you implemented the MC ID service as a DTM tool, you can alternatively use _satellite.getVisitorId() instead of Visitor.getInstance(), e.g.:

s.eVar1 = _satellite.getVisitorId().getMarketingCloudVisitorID();

So for your Data Element, instead of doing a Cookie type (I assume that's what you did), you will need to use Custom Script type and return the value, e.g.

try {
  return _satellite.getVisitorId().getMarketingCloudVisitorID();
} catch(e) {console.log(e);}

(Update) Alternatives

From your comment below (my bold for emphasis):

Just to be clear, this only happens to me on the first page when the Marketing Cloud cookies don't exist. I do see the MID in the server call.

Since you have confirmed that AA is getting an mid= value in its request, instead of trying to push the actual value of it to your eVar, you can pop it indirectly in other ways.

Dynamic Variables

dynamic variable syntax to reference the mid= param:

s.eVar1 = "D=mid";

Note: D= is the default dynamic variable prefix syntax. Check your AA tool config/other custom code to ensure it is not being set to something else.

Processing Rules

If you have access to create processing rules, you can setup a processing rule to set your eVar to mid= value there.

Upvotes: 1

Related Questions