Dtm Cheat Sheet

ADVERTISEMENT

Variables are used to dynamically insert text into
Below are some of the most commonly used methods
DTM has useful functions built into the platform
site tags (like an eVar or event). Variables are
in JavaScript. Note that many DTM implementations
that help QA tags. The code below can be used in
wrapped in %...% syntax.
don’t even use JS, but just in case…
functions or typed directly into your console.
enable staging library in production
JavaScript Regular Expressions
localStorage.setItem('sdsat_stagingLibrary',true);
declare regex variable
var RegEx =
/pattern/mod
enable debug mode (useful to QA rules)
use selected element
%this.[attribute]%
modifier
function
_satellite.setDebug(true);
use child element
%target.[attribute]%
/g
global matching
Dynamically insert the title and inner HTML for:
/i
case insensitive
hide browsing activity from DTM
<a title="link" href="/"><p>Hello!</p></a>
/s
single line mode
localStorage.setItem('hide_activity',true);
/m
multi line mode
title
%this.title%
cross-browser compatible console.log()
link
Output
JavaScript Selectors
_satellite.notify('text to display',[1-5]);
inner HTML
%target.innerHTML%
get element by id
getElementById('id')
Note: Messages from _satellite.notify() are only
Hello!
Output
get elements by class
getElementsByClassName('')
viewable in Debug mode. Additionally, the 1-5
get elements by tag
getElementsByTagName('a')
integer sets the importance level of the message.
Other example uses:
href
%this.href%
get the date of the last publish
class
%this.className%
JavaScript Logic Tests
_satellite.publishDate;
alt
%this.alt%
src
%this.src%
if statement
switch statement
get the date of the last library build
inner text
%this.@text%
if(i<0){some
action}
switch(i){
_satellite.buildDate;
n
inner text w/trim
%this.@cleanText%
else
if(i<1){some
action}
case
:
custom attribute
%this.getAttribute(
name
)%
else{some
action}
some action;
break;
for…next loop
Other useful variables:
default:
URL pathname
%URI%
for(i=0;i<10;i++){some
some action;
Regular Expressions (RegEx) is a method of
URL hostname
%hostname%
action}
}
matching that can be used within DTM (and
URL protocol
%protocol%
JavaScript and others) to select groups of text.
Bonus!
cross-browser trim
_satellite.cleanText('text');
Core Patterns
pattern
function
Data Elements are an alternative way of setting a
.
match any character
variable. These are most useful when you use
Below are some common jQuery methods. If
*
0 or more of previous expression
value(s) across multiple rules.
available, consider using Sizzle as a selector.
+
1 or more of previous expression
using data elements in a rule
?
0 or 1 of previous expression
%Element Name%
prefixes
targeting
suffixes
^
start of string
$(this)
.parents()
.text()
$
end of string
set a data element
$('#id')
.children()
.html()
|
“OR” match on both sides
_satellite.setVar("Element Name",value);
$('.class')
.siblings()
.val()
{…}
explicit quantifier notation
$('div')
.find()
.attr()
[…]
explicit character set match
get a data element
$('div.class')
[^…]
NOT one of the characters in set
_satellite.getVar("Element Name");
(…)
logical grouping of expression parts
selectors
function
\
precedes characters above; makes
Note: Each time you call a data element, DTM
img
div
$("div img")
select all
within
special character literal
tries to reset the value. If you need to store a
$("div>img")
only direct
img
children
value more permanently, use cookies (below).
Examples
title
$("a[title='equals']")
anchor
equals string
$("a[title!='noequal']")
title
doesn’t equal string
pattern
function
$("a:first")
select 1
st
anchor element
[abc]
matches a or b or c
ul
li
$("ul:last li:last")
select last
of last
[a-z]
match any letter from a-z (lowercase)
Cookies store values over a certain period of time.
$("ul li:first-child")
first
li
of every
ul
[A-Z]
match letter from A-Z (uppercase)
They are similar to Data Elements, but instead
id
$("[id*='contains']")
contains string
[0-9]
matches any number from 0-9
allow you to set a cookie memory in days (integer).
class
$("[class$='ends']")
ends with string
{3}
matches 3 of preceding expression
$("[id^='begins']")
id
begins with string
set a cookie
{3.9}
matches 3-9 of preceding expression
$(":checked")
selects all checked boxes
_satellite.setCookie("Cookie Name",value,days);
{3,}
matches 3 or more
$(":selected")
selects active inputs
read a cookie
Bonus!
@jimalytics
_satellite.readCookie("Cookie Name");
efficient $(this).text();
_satellite.text('text');

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go