daveferrara1
daveferrara1

Reputation: 97

Adobe DTM (adobe tag manager) set s.campaign with direct call rule

I need to set s.campaign with a value that is returned by some ajax. I figured I could just make a direct call to get that done. Nothing seems to be reported.

After ajax I call:

_satellite.track('ruleString');

I can see in the debugger my rule is fired. In the Adobe analytics admin, has been set for values to expire after MIN.

I have tried four ways of getting the campaign value set from here.

1 - Set it to a dataElement like : (in the analytics preset)

Campaign Value  ->  %mySpecialValue%

This element runs custom JS and logs the value so I know it runs, but adobe never sees a value.

2 - I set it with the following: (in custom code box)

var delm = _satellite.getVar('special_id');
_satellite.setVar("newVal",delm);
return true;

and then set campaing to %%newVal%%

  1. - I set it with the following: (in custom code box)

    var delm = _satellite.getVar('special_id'); s.linkTrackVars='campaign'; s.campaign = delm; s.tl();

  2. - I set it with the following: (in custom code box)

    var delm = _satellite.getVar('special_id'); s.linkTrackVars='eVar0'; s.campaign = delm; s.tl();

None of them seem to get data passed to adobe analytics. It's like my campaign var doesn't accept data. It should also be noted that if I just set in DTM the value of campaign to just "text" it never seems to get passed in either.

Is there a better way to set campaign with custom code.

Upvotes: 0

Views: 485

Answers (2)

daveferrara1
daveferrara1

Reputation: 97

As it turns out a consutant that set up dtm initially for us dropped in some custom code in our app measurement file. It must have been from another client Basically s.campaign was being set in there only when "cmpid" was passed as a query param.

Basically (1) above is all thats needed in the direct call to set it from a data element so long as you call _satellite.track('stringVal'); when your ajax is done

If the data element value is coming from work done via Ajax, then don't call that data element with any other rules prior.

Upvotes: 0

Jakub Otrząsek
Jakub Otrząsek

Reputation: 66

Please remember that AJAX is asynchronous:

$.ajax({
  url: "test.html",
});
_satellite.track('ruleString');

is wrong, but:

$.ajax({
  url: "test.html",
  context: document.body
}).done(function() {
  _satellite.track('ruleString');
});

will work.

Also please add in direct call rule console.log with data element value in javascript section, to check that value is present when rule is fired.

Upvotes: 0

Related Questions