AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

Analytics
4.3K members online now
4.3K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

Choosing experiment after cxApi is loaded

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hello everyone,

 

how do you load the data for a specific content experiment after  

<script src="//www.google-analytics.com/cx/api.js"></script>

 has been loaded?

I'm using a client-side experiment implementation. To keep track of several experiments on my site, I need to get data for the different experiments on different pages.

Unfortunately the Content Experiments JavaScript API Reference doesn't say anything about this.

I'd appreciate any help.

Re: Choosing experiment after cxApi is loaded

Participant ✭ ✭ ✭
# 2
Participant ✭ ✭ ✭
Hey Tobias, how are things?

If I understand correctly, you wish to access different pages of your experiments, is that correct?

If that's the case, all you have to do ir clear the cookies for that particular page. If you're using Chrome, you can access the Dev Console and clear data just for that specific page, when it will reset the cookie, giving you the ability to visit the page again and receive the other experiments.

Hope this helps.

Leandro Martinez | Basta1Click

Re: Choosing experiment after cxApi is loaded

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Hi leandrofm,

thanks for your answer. But if I understand you correctly, your answer is not an answer to my question. Also since cxApi is looking at the cookie to choose the variation, I don't think deleting cookies is a good idea.

 

To be specific about what I try to achieve:
Let's say I have a website with two pages build with AngularJS: domain.com/page1 and domain.com/page2 (variations are handled on the client-side, so page1 and page2 have each multiple variations)
Also I setup two experiments to run each on one page: experiment1 runs on page1 and experiment2 runs on page2

Now if I visit domain.com/page1 the cxApi script is loaded with the experiment1_id of experiment1.
If I then navigate to /page2 I need to reload the cxApi script with the experiment2_id of experiment2.

So how do I change the experiement_id in the cxApi object?
Or how do I reload the script with the new experiment2_id, without having a conflict with the already loaded script with experiment1_id?

Re: Choosing experiment after cxApi is loaded

Participant ✭ ✭ ✭
# 4
Participant ✭ ✭ ✭
Hey Tobias,

Yeah, sorry about the mistake.

I'm not very familiar with AngularJS, and I haven't tested experiments the way you're doing now, but refer to this article to see if contain what you need:
https://developers.google.com/analytics/solutions/experiments-client-side#implement-choose

It seems that you can point the Experiment ID along with the cxApi script, like this:
&lt;script src="//www.google-analytics.com/cx/api.js?experiment=YOUR_EXPERIMENT_ID">&lt;/script&gt;

Maybe this will help you.

Leandro Martinez | Basta1Click

Re: Choosing experiment after cxApi is loaded

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭

Hi leandrofm,

 

thanks for your answer again. It's probably helpful for others. I've already read through all the guides and references Google provides. But the specific case of loading the script with one experiment_id first, then (1) replacing the script's src or (2) removing the script from the DOM and adding the script again with a different experiment_id is documented nowhere.

Right now I'm testing approach (2). Removing the script from the DOM does not remove the JavaScript objects and functions. But loading the script again with a different experiment_id overrides the previously instantiated objects and functions (I hope). That's where I demand clarity (from Google) about whether this approach might lead to conflicts (distorted data, etc.). Today in the evening the test results should be available and I'll post them.

Re: Choosing experiment after cxApi is loaded

Participant ✭ ✭ ✭
# 6
Participant ✭ ✭ ✭
Hey Tobias,

Sorry this didn't help you.

Analytics API matters are handled on another community at stackoverflow. You can try there and see if anyone may help you with: http://stackoverflow.com/tags/google-analytics/info

Hope this helps.

Leandro Martinez | Basta1Click

Re: Choosing experiment after cxApi is loaded

[ Edited ]
Visitor ✭ ✭ ✭
# 7
Visitor ✭ ✭ ✭

Thanks for the hint.