开发者

Javascript question: How to update Google Analytics code in LightBox Slideshow 1.1

I am using Lightbox Slideshow 1.1 (www.justinbarkhuff.com/lab/lightbox_slideshow) on my site which uses javascript to display photos in a modal window and it has a Google Analytics option built-in to its javascript file, but it uses the old urchintracker code. I'm very unfamiliar with modifying javascript. I was wondering if anyone could help me transform this code from the old urchintracker to the new Asynch开发者_运维知识库ronous code. More info on migrating to that new code can be found here - http://code.google.com/apis/analytics/docs/tracking/asyncMigrationExamples.html

The code in the lightbox.js file in question is:

if(this.options.googleAnalytics){
    urchinTracker(this.imageArray[this.activeImage].link);
}

With "(this.imageArray[this.activeImage].link)" being the variable which passes the path and filename of the image currently being viewed (i.e. "p/image1.jpg") to Google Analytics. This works great and my Google Analytics is receiving data fine, but I need to convert to the latest Asynchronous code.

I want to convert to an Event tracker in the new code, so instead of the script just sending urchinTracker('p/image1.jpg'); I would need it to be instead:

_gaq.push(['_trackEvent', 'Photos', 'View', 'currentimage.jpg']);

(Where "currentimage.jpg" is the value passed by "(this.imageArray[this.activeImage].link);" in the lightbox.js file.

("_gaq.push" is the new "urchintracker")

To view the lightbox.js file, go to: http://www.justinbarkhuff.com/lab/lightbox_slideshow/lightbox.js and search for "urchintracker".

If anyone who knows Javascript could help me transform this above code so I can use the latest code for Google Analytics, I'd really appreciate it. Or if you could point me in the right direction. Thanks in advance.

I wonder.. could it be as simple as this?

if(this.options.googleAnalytics){
    _gaq.push(['_trackEvent', 'Photos', 'View', this.imageArray[this.activeImage].link]);
}

What about the ' symbols around this.imageArray[this.activeImage].link? Will the script automatically pass them on without me adding them to the code?

Thanks in advance for any and all help!


Yes. Your code is perfectly well adopted. Try it out; assuming it was working before, it should work now.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜