将数据层中的数组数据填充到GTM中

时间:2017-04-09 22:34:58

标签: drupal google-analytics google-tag-manager

我有一个数据层,它从Drupal

给我这样的信息
entityTaxonomy.byline

我可以轻松使用GTM的数据层变量来引入entityBundle。如何将其设置为引入署名信息?我试过了Name1, Name2,但这给了我一个数组。我可以设置entityTaxonomy.byline.4来获取Name1,但这很愚蠢,因为编辑会定期添加内容。

我计划最终将署名添加到Google Analytics中的自定义维度2中。

我希望将自定义维度2的数据设为var circles = []; var squares = []; var sizeProportion = 0.2; //additional shapes var r = 0; var velocity = 1; var fillColor = color(0, 0, 0); var hit = false; var startTime; var waitTime = 3000; var drawCircles; var drawSquares; function preload() { sound = loadSound('assets/findingnemoegg.mp3'); } function setup() { createCanvas(windowWidth, windowHeight); amplitude = new p5.Amplitude(); sound.loop(); sound.play(); startTime = millis(); } function draw() { background(255); // other shapes + information r = r + velocity; if ((r > 256) || (r < 0)) { velocity = velocity * -1; } noStroke(); fill(144, 12, 63, r); ellipse(100, 100, 80, 80); // drawing circles circles.push(new Circle1(touchX, touchY)); for (var i = 0; i < circles.length; i++) { circles[i].display(); if (circles[i].strokeOpacity <= 0) { // Remove if faded out. circles.splice(i, 1); // remove } } //collisions if (pointTouchcircle2(touchX, 100, 100)) { // <- collision detection //call upon Circle2 function and have the main module draw that } else { //stay the same. } } //starting circles function Circle1(x, y) { this.x = x; this.y = y; this.size = 0; this.age = 0; this.fillOpacity = 20 this.strokeOpacity = 30 this.display = function() { var level = amplitude.getLevel(); this.age++; if (this.age > 500) { this.fillOpacity -= 1; this.strokeOpacity -= 1; } var newSize = map(level, 0, 1, 20, 900); this.size = this.size + (sizeProportion * (newSize - this.size)); strokeWeight(10); stroke(152, 251, 152, this.strokeOpacity); fill(23, 236, 236, this.fillOpacity); ellipse(this.x, this.y, this.size); } } //maroon circles function Circle2(x, y) { this.x = x; this.y = y; this.size = 0; this.age = 0; this.fillOpacity = 20 this.strokeOpacity = 30 this.display = function() { var level = amplitude.getLevel(); this.age++; if (this.age > 500) { this.fillOpacity -= 1; this.strokeOpacity -= 1; } var newSize = map(level, 0, 1, 20, 900); this.size = this.size + (sizeProportion * (newSize - this.size)); strokeWeight(10); stroke(173, 212, 92, this.strokeOpacity); fill(144, 12, 63, this.fillOpacity); ellipse(this.x, this.y, this.size); } } //collision functions function pointTouchcircle2(touch, x, y) { if (hit = collidePointCircle(touchX,touchY,100,100,50)) { return true } else { return false } } 。有时这只是一个价值。有时最多可以达到20个值。

在GTM中我需要做些什么才能让它注册该信息?

1 个答案:

答案 0 :(得分:0)

entityTaxonomy.byline实际上为您提供了一个对象。您需要进行一些处理才能获得可以加入字符串的数组。一种可能的方法是

temp = [];
Object.keys(test.entityTaxonomy.byline).map(function(key, index) {
    temp.push(test.entityTaxonomy.byline[key]);
});
bylines = temp.join(",")

(我确信可以做得更简洁)。在GTM中,您需要创建一个包含带有bylines的对象的变量,然后您可以在自定义的javascript变量中进行处理(根据定义,它是一个带有返回值的匿名函数)

function() {
    var byLineObject = {{bylines}} // created as datalayer var beforehand
    temp = [];
    Object.keys(byLineObject).map(function(key, index) {
        temp.push(byLineObject[key]);
    });
    return temp.join(",")
}
相关问题