Skip to content

Commit

Permalink
Merge pull request #1 from vharsh/dnsOrverride
Browse files Browse the repository at this point in the history
Explictly use Google-DNS as nameserver
  • Loading branch information
kmova authored Nov 14, 2018
2 parents 14b04e0 + 74d88c1 commit 6944921
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ package ga

import (
"bytes"
"context"
"fmt"
"net"
"net/http"
"net/url"
"regexp"
Expand All @@ -16,9 +18,22 @@ func NewClient(trackingID string) (*Client, error) {
if !trackingIDMatcher.MatchString(trackingID) {
return nil, fmt.Errorf("Invalid Tracking ID: %s", trackingID)
}
dialer := &net.Dialer{
Resolver: &net.Resolver{
PreferGo: true,
Dial: func(ctx context.Context, network, address string) (net.Conn, error){
dialer := net.Dialer{}
return dialer.DialContext(ctx, network, "8.8.8.8:53")
},
},
}
return &Client{
UseTLS: true,
HttpClient: http.DefaultClient,
HttpClient: &http.Client{
Transport: &http.Transport{
DialContext: dialer.DialContext,
},
},
protocolVersion: "1",
protocolVersionSet: true,
trackingID: trackingID,
Expand Down Expand Up @@ -49,17 +64,17 @@ func (c *Client) Send(h hitType) error {
return err
}

url := ""
gaUrl := ""
if cpy.UseTLS {
url = "https://www.google-analytics.com/collect"
gaUrl = "https://www.google-analytics.com/collect"
} else {
url = "http://ssl.google-analytics.com/collect"
gaUrl = "http://ssl.google-analytics.com/collect"
}

str := v.Encode()
buf := bytes.NewBufferString(str)

resp, err := c.HttpClient.Post(url, "application/x-www-form-urlencoded", buf)
resp, err := c.HttpClient.Post(gaUrl, "application/x-www-form-urlencoded", buf)
if err != nil {
return err
}
Expand Down

0 comments on commit 6944921

Please sign in to comment.