Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

What's the best way to capture content changing under an ajax/angular framework?

Level 4
Level 4

Hi guys,

I'm working across a site under an angular/ajax framework, and I'm wondering what the best practice is for dealing with this kind of site. In the past under straight s_code I've asked the dev team to populate contextData/custom variables and execute an s.t() with clearVars if needed each time the content loads, triggering a virtual page load. I'd then in my s_code have a bunch of rules and switch statements to set the appropriate props/eVars/events.

Now using DTM, I can see how I could ask for a new js 'analytics' object that captures data like and analytics.tool within data elements, however I'm unsure of how to trigger this capture on a location change within the ajax site.

I've looked at the 'element exists' or 'enters viewport' options, such as #location and id="pagename", but I believe I'd then need to set this across each page, and it's a pretty large site 🙂

So, what is the best way of using DTM's functionality to efficiently tag up an ajax/angular based site?

Cheers, Jez

4 Replies

You would either use the 'element exists' or 'enters viewport' like to mentioned, or take advantage of our Direct Call Rules.


Level 4
Level 4

Thanks Rudi - I'm liking the direct call rules, and have already used then for some video milestone measurement, is there any down side to using them, or any limits on the number of direct call rules?


Hey Jerome,

I posted this in another question about using DTM in angular (, but here is what I said:

I don't have any documentation or best practices, but we have done a little bit of tracking with angular and this has come in handy for "page views":
In other words, if you want to hook into a view change event with angular, you could do something like this:
$('appElement').scope().$root.$on('$locationChangeSuccess', function () { console.log(window.location.href); // can use this for page name //s.t(); or; or fire a "direct rule" in DTM });
There are other things you can do from there of course like listening/watching:$rootScope.Scope#$watch
And you can use DTM's selectors to do other event based rules as well.
That is the little advice I can give.  🙂
Level 4
Level 4

Thanks bbytheway, that's really helpful - do you know if s.t() and _satellite.pageBottom() are interchangeable?