With DTM you don’t need Plugins! – Part 2

Let’s continue on the journey and replace one more plugins with DTM goodness.

I even get to introduce an almost hidden feature!

getVisitNum

I was slightly disappointed last time because I couldn’t find an easy way of replacing getVisitNum. This plugin keeps track of how often someone comes to the site. Very useful for segmentation purposes.

The plugin really does two things: maintain the number of visits in a cookie (which means increasing the number at the start of a visit), and providing the current number so we can track it into a “variable” of our choice.

I knew that reading the visit number from a cookie was easy: just make a Data Element based on the cookie.

But would I have to add some custom logic to manage the visit number? Where exactly?

Turns out the answer is no! I don’t have to! DTM provides everything I need, although it is hidden away a little bit.

When you make a rule, you can add a condition based on the number of visits. Oh. So DTM actually does keep track of visits for me? Cool!

Can I read that value somewhere? I couldn’t find it.

Then my colleague Anna pointed me the right way: the visit number is only handled by DTM if I actually have a rule with a condition based on “Sessions” (aka Visits) in my setup. Otherwise it doesn’t care.

But if I do have a rule with such a condition, it will write a cookie (“_sdsat_session_count”)! Heureka!

So, let’s set up a rule with a condition, like so:

[Screenshot]

DTM Rule with Session-baed Condition

Now if we push that live or use the “DTM Switch plugin” to check the staging version, we should see a new cookie on our site.

[Screenshot]

DTM Session Count Cookie

Success!

All we need now is a Data Element that reads that cookie:

[Screenshot]

Data Element for Visit Number

Use that Data Element with the Analytics variable that you currently use with the getVisitNum plugin:

[Screenshot]

Assigning Data Element to prop33

And Bob’s your uncle!

Bonus

For added bliss, you could add custom Javascript that reads the existing cookie and bootstraps the new one, so the visit number wouldn’t start at 1 for everyone.

In my s_code.js file, I was assigning the prop like so:

[Screenshot]

Original Call to getVisitNum in s_code.js

No parameter on the getVisitNum plugin means that the plugin will store the visit number in a cookie called “s_vnum”.

So all we need to do is read that value from the “s_vnum” cookie and write it into the “_sdsat_session_count” cookie before DTM uses that cookie for the first time to populate our variable.

My guess would be that placing such code into a sequential Javascript block at page top should work.

Don’t forget to delete the “s_vnum” cookie! You want to transfer the visit number once only.

About

German expat living in Switzerland (formerly UK and France). Consultant and member of the Multi-Solutions Group at Adobe, working with the Digital Marketing Suite. Father of 4 girls.

Tagged with: , , , ,
Posted in DTM, Integration, Javascript, Plugins
10 comments on “With DTM you don’t need Plugins! – Part 2
  1. Cool! Looking forward to the next in the series.

    Like

  2. Hi Jan! Love these posts. Any chance you have a getPageName example for DTM?

    Like

  3. Pedro Monjo says:

    How about setting the page load rule as a top of the page rule? Since DTM does not guarantee order of execution, if you want to use the value at the bottom of the page, you need to make sure the “_sdsat_session_count” is already set.

    Like

  4. Pedro Monjo says:

    One other comment. DTM sets the visit cookie to expire at the end of the session, where getVisitNum expires this cookie after 30 minutes of the last page viewed. This will add some discrepancy between the two codes.

    Like

  5. Very useful post(s). Can only agree with the objective of having a “clean” DTM implementation without the necessity of legacy code or plugins. Next up: getTimeParting/getVisitNum : )

    Like

  6. […] tip: each bit of code that you migrate from doPlugins and into DTM (or whatever your TMS is) will make your setup easier, at least easier for your friendly […]

    Like

  7. Erich says:

    Thanks for that getVisitNum workaround – for some reason every time I tried to add that plugin, it literally broke everything.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: